Beispiel #1
0
    def test_import_partner_address_record(self):
        """ Import a partner address """

        partner = self.env['res.partner'].create(
            {'name': 'Customer'}
        )
        self.create_binding_no_export(
            'prestashop.res.partner', partner.id, 1,
            shop_group_id=self.shop_group.id,
            shop_id=self.shop.id,
        )
        with recorder.use_cassette('test_import_partner_address_record_1'):
            import_record(self.conn_session, 'prestashop.address',
                          self.backend_record.id, 1)

        domain = [('prestashop_id', '=', 1)]
        address_bindings = self.env['prestashop.address'].search(domain)
        address_bindings.ensure_one()

        expected = [
            ExpectedAddress(
                name='John DOE (My address)',
                parent_id=partner,
                street='16, Main street',
                street2='2nd floor',
                city='Paris',
                zip='75002',
                country_id=self.env.ref('base.fr'),
                phone='0102030405',
                mobile=False,
                type='other',
            )]

        self.assert_records(expected, address_bindings)
Beispiel #2
0
    def test_import_partner_category_record(self):
        """ Import a partner category """
        with recorder.use_cassette('test_import_partner_category_record_1'):
            import_record(self.conn_session, 'prestashop.res.partner.category',
                          self.backend_record.id, 3)

        domain = [('prestashop_id', '=', 3)]
        category_model = self.env['prestashop.res.partner.category']
        category_bindings = category_model.search(domain)
        category_bindings.ensure_one()

        expected = [
            ExpectedCategory(
                name='Customer A',
            )]

        self.assert_records(expected, category_bindings)
    def test_import_inventory_record_variant(self):
        """ Import the inventory for a variant"""
        variant_binding = self._create_product_binding(
            name='Faded Short Sleeves T-shirt',
            template_ps_id=1,
            variant_ps_id=1,
        )

        template = variant_binding.odoo_id.product_tmpl_id

        self.assertEqual(0, template.qty_available)
        with recorder.use_cassette('test_import_inventory_record_variant_1'):
            import_record(self.conn_session, '_import_stock_available',
                          self.backend_record.id, 1,
                          record={'id_product_attribute': '1',
                                  'id': '1',
                                  'id_product': '1'})
        self.assertEqual(299, template.qty_available)
    def test_import_product_record_category(self):
        """ Import a product category """
        with recorder.use_cassette('test_import_product_category_record_1'):
            import_record(self.conn_session, 'prestashop.product.category',
                          self.backend_record.id, 5)

        domain = [('prestashop_id', '=', 5),
                  ('backend_id', '=', self.backend_record.id)]
        binding = self.env['prestashop.product.category'].search(domain)
        binding.ensure_one()

        expected = [
            ExpectedProductCategory(
                name='T-shirts',
                odoo_id__display_name='Root / Home / Women / Tops / T-shirts',
            )]

        self.assert_records(expected, binding)
Beispiel #5
0
    def test_import_manufacturer_record(self):
        """ Import a manufacturer """

        with recorder.use_cassette('test_import_manufacturer_record_1'):
            import_record(self.conn_session, 'prestashop.manufacturer',
                          self.backend_record.id, 1)

        domain = [('prestashop_id', '=', 1)]
        manufacturer_bindings = \
            self.env['prestashop.manufacturer'].search(domain)
        manufacturer_bindings.ensure_one()

        expected = [
            ExpectedManufacturer(
                name='John DOE',
                category_id=self.categ.id,
            )]

        self.assert_records(expected, manufacturer_bindings)
Beispiel #6
0
    def test_import_partner_record(self):
        """ Import a partner """

        category = self.env['res.partner.category'].create(
            {'name': 'Customer'}
        )
        category_binding = self.create_binding_no_export(
            'prestashop.res.partner.category', category.id, 3
        )

        batch_job_path = ('openerp.addons.connector_prestashop.models'
                          '.res_partner.importer.import_batch')
        with recorder.use_cassette('test_import_partner_record_1'), \
                mock.patch(batch_job_path) as address_batch_mock:
            import_record(self.conn_session, 'prestashop.res.partner',
                          self.backend_record.id, 1)
            address_batch_mock.delay.assert_called_with(
                mock.ANY,
                'prestashop.address',
                self.backend_record.id,
                filters={'filter[id_customer]': '1'},
                priority=10,
            )

        domain = [('prestashop_id', '=', 1)]
        partner_bindings = self.env['prestashop.res.partner'].search(domain)
        partner_bindings.ensure_one()

        expected = [
            ExpectedPartner(
                name='John DOE',
                email='*****@*****.**',
                newsletter=True,
                company=False,
                active=True,
                shop_group_id=self.shop_group,
                shop_id=self.shop,
                default_category_id=category_binding,
                birthday='1970-01-15',
            )]

        self.assert_records(expected, partner_bindings)
    def test_import_inventory_record_template(self):
        """ Import the inventory for a template"""
        variant_binding = self._create_product_binding(
            name='Faded Short Sleeves T-shirt',
            template_ps_id=1,
            variant_ps_id=1,
        )

        template = variant_binding.odoo_id.product_tmpl_id

        self.assertEqual(0, template.qty_available)
        with recorder.use_cassette('test_import_inventory_record_template_1'):
            import_record(self.conn_session, '_import_stock_available',
                          self.backend_record.id, 1,
                          # id_product_attribute='0' means we
                          # import the template quantity
                          record={'id_product_attribute': '0',
                                  'id': '1',
                                  'id_product': '1'})
        # cumulative stock of all the variants
        self.assertEqual(1799, template.qty_available)
    def test_import_carrier_record(self):
        """ Import a carrier """
        with recorder.use_cassette('test_import_carrier_record_2'):
            import_record(self.conn_session, 'prestashop.delivery.carrier',
                          self.backend_record.id, 2)

        domain = [('prestashop_id', '=', 2),
                  ('backend_id', '=', self.backend_record.id)]
        binding = self.env['prestashop.delivery.carrier'].search(domain)
        binding.ensure_one()

        ship_product_xmlid = 'connector_ecommerce.product_product_shipping'
        ship_product = self.env.ref(ship_product_xmlid)
        expected = [
            ExpectedCarrier(
                name='My carrier',
                partner_id=self.backend_record.company_id.partner_id,
                product_id=ship_product,
                company_id=self.backend_record.company_id,
            )
        ]

        self.assert_records(expected, binding)
Beispiel #9
0
    def test_import_sale_record(self):
        """ Import a sale order """
        # setup for sale order with id 5, create the dependencies
        mode_journal = self.env['account.journal'].search([], limit=1)
        payment_method_xmlid = 'account.account_payment_method_manual_in'
        payment_method = self.env.ref(payment_method_xmlid)
        payment_mode = self.env['account.payment.mode'].create({
            'name': 'Bank wire',
            'company_id': self.backend_record.company_id.id,
            'bank_account_link': 'fixed',
            'fixed_journal_id': mode_journal.id,
            'payment_type': 'inbound',
            'payment_method_id': payment_method.id,
        })

        ship_product = self.env.ref(
            'connector_ecommerce.product_product_shipping'
        )

        carrier = self.env['delivery.carrier'].create({
            'name': 'My carrier',
            'product_id': ship_product.id,
            'partner_id': self.env.ref('base.main_company').partner_id.id,
        })
        self.create_binding_no_export(
            'prestashop.delivery.carrier', carrier.id, prestashop_id=2,
        )

        variant_tshirt_orange_s_binding = self._create_product_binding(
            name='Faded Short Sleeve T-shirts',
            template_ps_id=1,
            variant_ps_id=1,
        )
        variant_tshirt_orange_s = variant_tshirt_orange_s_binding.odoo_id
        variant_blouse_black_s_binding = self._create_product_binding(
            name='Blouse',
            template_ps_id=2,
            variant_ps_id=7,
        )
        variant_blouse_black_s = variant_blouse_black_s_binding.odoo_id
        variant_dress_orange_s_binding = self._create_product_binding(
            name='Printed Dress',
            template_ps_id=3,
            variant_ps_id=13,
        )
        variant_dress_orange_s = variant_dress_orange_s_binding.odoo_id

        partner = self.env['res.partner'].create({
            'name': 'John DOE',
        })
        partner_binding = self.create_binding_no_export(
            'prestashop.res.partner', partner.id, prestashop_id=1,
            shop_group_id=self.shop.id,
        )
        address = self.env['res.partner'].create({
            'name': 'John DOE',
            'parent_id': partner.id,
        })
        self.create_binding_no_export(
            'prestashop.address', address.id, prestashop_id=4,
            prestashop_partner_id=partner_binding.id
        )

        # import of the sale order
        with recorder.use_cassette('test_import_sale_record_5'):
            result = import_record(
                self.conn_session, 'prestashop.sale.order',
                self.backend_record.id, 5)

        error_msg = ('Import of the order 5 canceled '
                     'because it has not been paid since 30 days')
        self.assertEqual(result, error_msg)

        with recorder.use_cassette('test_import_sale_record_5'):
            with freeze_time("2016-12-08"):
                import_record(
                    self.conn_session, 'prestashop.sale.order',
                    self.backend_record.id, 5)

        domain = [('prestashop_id', '=', 5),
                  ('backend_id', '=', self.backend_record.id)]
        binding = self.env['prestashop.sale.order'].search(domain)
        binding.ensure_one()

        expected = [
            ExpectedSale(
                name='KHWLILZLL',
                partner_id=partner,
                partner_invoice_id=address,
                partner_shipping_id=address,
                total_amount=71.51,
                carrier_id=carrier,
                payment_mode_id=payment_mode,
                pricelist_id=self.backend_record.pricelist_id,
            )]

        self.assert_records(expected, binding)

        expected = [
            ExpectedSaleLine(
                name='Faded Short Sleeve T-shirts - Color : Orange, Size : S',
                product_id=variant_tshirt_orange_s,
                price_unit=16.51,
                product_uom_qty=1.0,
            ),
            ExpectedSaleLine(
                name='Blouse - Color : Black, Size : S',
                product_id=variant_blouse_black_s,
                price_unit=27.0,
                product_uom_qty=1.0,
            ),
            ExpectedSaleLine(
                name='Printed Dress - Color : Orange, Size : S',
                product_id=variant_dress_orange_s,
                price_unit=26.0,
                product_uom_qty=1.0,
            ),
            ExpectedSaleLine(
                name='My carrier',
                product_id=ship_product,
                price_unit=2.0,
                product_uom_qty=1.0,
            ),
        ]

        self.assert_records(expected, binding.order_line)
    def test_import_product_record(self):
        """ Import a product """
        # product 1 is assigned to categories 1-5 on PrestaShop
        categs = self.env['product.category']
        for idx in range(1, 6):
            cat = self.env['product.category'].create(
                {'name': 'ps_categ_%d' % idx}
            )
            self.create_binding_no_export(
                'prestashop.product.category', cat.id, idx,
            )
            categs |= cat

        with recorder.use_cassette('test_import_product_template_record_1'):
            import_record(self.conn_session, 'prestashop.product.template',
                          self.backend_record.id, 1)

        domain = [('prestashop_id', '=', 1),
                  ('backend_id', '=', self.backend_record.id)]
        binding = self.env['prestashop.product.template'].search(domain)
        binding.ensure_one()

        expected = [
            ExpectedTemplate(
                name='Faded Short Sleeves T-shirt',
                # For the categories, this is what I observed, not
                # necessarily what is wanted.
                categ_id=self.env.ref('product.product_category_all'),
                categ_ids=categs.filtered(lambda r: r.name != 'ps_categ_1'),
                list_price=16.51,
            )]

        self.assert_records(expected, binding)

        variants = binding.product_variant_ids

        PSValue = self.env['prestashop.product.combination.option.value']
        value_s = PSValue.search([('backend_id', '=', self.backend_record.id),
                                  ('name', '=', 'S')]).odoo_id
        value_m = PSValue.search([('backend_id', '=', self.backend_record.id),
                                  ('name', '=', 'M')]).odoo_id
        value_l = PSValue.search([('backend_id', '=', self.backend_record.id),
                                  ('name', '=', 'L')]).odoo_id
        value_orange = PSValue.search(
            [('backend_id', '=', self.backend_record.id),
             ('name', '=', 'Orange')]
        ).odoo_id
        value_blue = PSValue.search(
            [('backend_id', '=', self.backend_record.id),
             ('name', '=', 'Blue')]
        ).odoo_id

        expected_variants = [
            ExpectedVariant(
                default_code='1_1',
                standard_price=4.95,
                attribute_value_ids=value_s + value_orange,
            ),
            ExpectedVariant(
                default_code='1_2',
                standard_price=4.95,
                attribute_value_ids=value_s + value_blue,
            ),
            ExpectedVariant(
                default_code='1_3',
                standard_price=4.95,
                attribute_value_ids=value_m + value_orange,
            ),
            ExpectedVariant(
                default_code='1_4',
                standard_price=4.95,
                attribute_value_ids=value_m + value_blue,
            ),
            ExpectedVariant(
                default_code='1_5',
                standard_price=4.95,
                attribute_value_ids=value_l + value_orange,
            ),
            ExpectedVariant(
                default_code='1_6',
                standard_price=4.95,
                attribute_value_ids=value_l + value_blue,
            ),
        ]

        self.assert_records(expected_variants, variants)