示例#1
0
    def test_0040_import_carriers(self):
        """
        Test If all carriers are being imported from magento
        """
        magento_carrier_obj = POOL.get('magento.instance.carrier')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)

            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
            })

            carriers_before_import = magento_carrier_obj.search(
                txn.cursor, txn.user, [], context=context)
            carriers = magento_carrier_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('carriers', 'shipping_methods'),
                context=context)
            carriers_after_import = magento_carrier_obj.search(txn.cursor,
                                                               txn.user, [],
                                                               context=context)

            self.assertTrue(carriers_after_import > carriers_before_import)
            for carrier in carriers:
                self.assertEqual(carrier.instance.id,
                                 context['magento_instance'])
示例#2
0
    def test_0060_import_grouped_product(self):
        """Test the import of a grouped product using magento data
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            category_obj = POOL.get('product.category')
            product_obj = POOL.get('product.product')

            category_data = load_json('categories', '22')

            category_obj.create_using_magento_data(txn.cursor,
                                                   txn.user,
                                                   category_data,
                                                   context=context)

            product_data = load_json('products', '54')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            self.assertEqual(product.categ_id.magento_ids[0].magento_id, 22)
            self.assertEqual(product.magento_product_type, 'grouped')
    def test_0070_import_downloadable_product(self):
        """Test the import of a downloadable product using magento data
        """
        product_obj = POOL.get('product.product')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            if settings.MOCK:
                product_data = load_json('products', '170')
            else:
                with magento.Product(*settings.ARGS) as product_api:
                    product_list = product_api.list()
                    for product in product_list:
                        if product['type'] == 'downloadable':
                            product_data = product_api.info(
                                product=product['product_id'],
                            )
                            break

            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context
            )
            self.assertEqual(
                product.magento_product_type, product_data['type']
            )
            self.assertEqual(
                product.categ_id.name, 'Unclassified Magento Products'
            )
    def test_0110_export_catalog(self):
        """
        Check the export of product catalog to magento.
        This method does not check the API calls.
        """
        product_obj = POOL.get('product.product')
        category_obj = POOL.get('product.category')
        website_obj = POOL.get('magento.instance.website')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
                'magento_attribute_set': 1,
            })

            website = website_obj.browse(
                txn.cursor, txn.user, self.website_id1, txn.context
            )

            if settings.MOCK:
                category_data = load_json('categories', '17')
            else:
                with magento.Category(*settings.ARGS) as category_api:
                    category_tree = category_api.tree(
                        website.magento_root_category_id
                    )
                    category_data = category_api.info(
                        category_tree['children'][0]['category_id']
                    )

            category = category_obj.create_using_magento_data(
                txn.cursor, txn.user, category_data, context=context
            )

            product_id = product_obj.create(
                txn.cursor, txn.user, {
                    'name': 'Test product',
                    'default_code': 'code',
                    'description': 'This is a product description',
                    'list_price': 100,
                }, context=context
            )
            product = product_obj.browse(
                txn.cursor, txn.user, product_id, context=context
            )

            if settings.MOCK:
                with patch(
                    'magento.Product', mock_product_api(), create=True
                ):
                    product_obj.export_to_magento(
                        txn.cursor, txn.user, product, category, context
                    )
            else:
                product_obj.export_to_magento(
                    txn.cursor, txn.user, product, category, context
                )
示例#5
0
    def test_0080_export_product_stock_information(self):
        """
        This test checks if the method to call for updation of product
        stock info does not break anywhere in between.
        This method does not check the API calls
        """
        product_obj = POOL.get('product.product')
        website_obj = POOL.get('magento.instance.website')
        category_obj = POOL.get('product.category')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            category_data = load_json('categories', '17')

            category_obj.create_using_magento_data(txn.cursor,
                                                   txn.user,
                                                   category_data,
                                                   context=context)

            product_data = load_json('products', '135')
            product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            website = website_obj.browse(txn.cursor, txn.user,
                                         self.website_id1, context)

            with patch('magento.Inventory', mock_inventory_api(), create=True):
                website_obj.export_inventory_to_magento(
                    txn.cursor, txn.user, website, context)
    def test_0040_import_configurable_product(self):
        """Test the import of a configurable product using magento data
        """
        category_obj = POOL.get('product.category')
        product_obj = POOL.get('product.product')
        website_obj = POOL.get('magento.instance.website')
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            website = website_obj.browse(
                txn.cursor, txn.user, self.website_id1, txn.context
            )

            if settings.MOCK:
                category_data = load_json('categories', '17')
            else:
                with magento.Category(*settings.ARGS) as category_api:
                    category_tree = category_api.tree(
                        website.magento_root_category_id
                    )
                    category_data = category_api.info(
                        category_tree['children'][0]['category_id']
                    )

            category_obj.create_using_magento_data(
                txn.cursor, txn.user, category_data, context=context
            )

            magento_store_id = website.stores[0].store_views[0].magento_id

            if settings.MOCK:
                product_data = load_json('products', '135')
            else:
                with magento.Product(*settings.ARGS) as product_api:
                    product_list = product_api.list(
                        store_view=magento_store_id
                    )
                    for product in product_list:
                        if product['type'] == 'configurable':
                            product_data = product_api.info(
                                product=product['product_id'],
                                store_view=magento_store_id
                            )
                            break

            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context
            )
            self.assertTrue(
                str(product.categ_id.magento_ids[0].magento_id) in
                product_data['categories']
            )
            self.assertEqual(
                product.magento_product_type, product_data['type']
            )
示例#7
0
    def test0010_create_partner(self):
        """
        Tests if customers imported from magento is created as partners
        in openerp
        """
        partner_obj = POOL.get('res.partner')
        magento_partner_obj = POOL.get('magento.website.partner')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            self.setup_defaults(txn)

            context = deepcopy(CONTEXT)
            context.update({'magento_website': self.website_id1})
            values = load_json('customers', '1')

            partners = magento_partner_obj.search(txn.cursor,
                                                  txn.user, [],
                                                  context=context)
            self.assertEqual(len(partners), 0)

            # Create partner
            partner = partner_obj.find_or_create(txn.cursor, txn.user, values,
                                                 context)
            self.assert_(partner)

            self.assertTrue(
                partner_obj.search(txn.cursor,
                                   txn.user, [('email', '=', values['email'])],
                                   context=context))
            partners = magento_partner_obj.search(txn.cursor,
                                                  txn.user, [],
                                                  context=context)

            self.assertEqual(len(partners), 1)
示例#8
0
    def test0040_match_address(self):
        """
        Tests if address matching works as expected
        """
        partner_obj = POOL.get('res.partner')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            self.setup_defaults(txn)

            context = deepcopy(CONTEXT)
            context.update({'magento_website': self.website_id1})
            customer_data = load_json('customers', '1')

            # Create partner
            partner = partner_obj.find_or_create(txn.cursor, txn.user,
                                                 customer_data, context)

            address_data = load_json('addresses', '1')

            address = partner_obj.\
                find_or_create_address_as_partner_using_magento_data(
                    txn.cursor, txn.user, address_data, partner, context
                )

            # Same address imported again
            self.assertTrue(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address, load_json('addresses',
                                                             '1')))

            # Exactly similar address imported again
            self.assertTrue(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address,
                    load_json('addresses', '1a')))

            # Similar with different country
            self.assertFalse(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address,
                    load_json('addresses', '1b')))

            # Similar with different state
            self.assertFalse(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address,
                    load_json('addresses', '1c')))

            # Similar with different telephone
            self.assertFalse(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address,
                    load_json('addresses', '1d')))

            # Similar with different street
            self.assertFalse(
                partner_obj.match_address_with_magento_data(
                    txn.cursor, txn.user, address,
                    load_json('addresses', '1e')))
示例#9
0
    def test_0020_create_website(self):
        """
        Test creation of a new website under an instance
        Also check if the related field for company works as expected
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            instance_obj = POOL.get('magento.instance')
            website_obj = POOL.get('magento.instance.website')

            values = {
                'name': 'Test Instance',
                'url': 'some test url',
                'api_user': '******',
                'api_key': 'testkey',
            }
            instance_id = instance_obj.create(
                txn.cursor, txn.user, values, txn.context
            )
            instance = instance_obj.browse(txn.cursor, txn.user, instance_id)

            website_id = website_obj.create(txn.cursor, txn.user, {
                'name': 'A test website',
                'magento_id': 1,
                'code': 'test_code',
                'instance': instance.id,
            })
            website = website_obj.browse(txn.cursor, txn.user, website_id)
            self.assertEqual(website.name, 'A test website')
            self.assertEqual(website.company, instance.company)
            self.assertEqual(instance.websites[0].id, website.id)
示例#10
0
    def test_0030_search_state_using_magento_region(self):
        """
        Tests if state can be searched using magento region
        """
        state_obj = POOL.get('res.country.state')
        country_obj = POOL.get('res.country')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            country = country_obj.search_using_magento_code(
                txn.cursor, txn.user, 'US', txn.context)
            state_ids = state_obj.search(txn.cursor,
                                         txn.user, [
                                             ('name', '=', 'Florida'),
                                             ('country_id', '=', country.id),
                                         ],
                                         context=txn.context)
            self.assertTrue(state_ids)
            self.assertEqual(len(state_ids), 1)

            # Create state and it should return id of existing record instead
            # of creating new one
            state = state_obj.find_or_create_using_magento_region(
                txn.cursor, txn.user, country, 'Florida', txn.context)

            self.assertEqual(state.id, state_ids[0])

            state_ids = state_obj.search(txn.cursor,
                                         txn.user, [
                                             ('name', '=', 'Florida'),
                                             ('country_id', '=', country.id),
                                         ],
                                         context=txn.context)
            self.assertEqual(len(state_ids), 1)
示例#11
0
    def test_0005_import_sale_order_states(self):
        """Test the import and creation of sale order states for an instance
        """
        magento_order_state_obj = POOL.get('magento.order_state')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
            })

            states_before_import = magento_order_state_obj.search(
                txn.cursor, txn.user, [], context=context)
            states = magento_order_state_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('order-states', 'all'),
                context=context)
            states_after_import = magento_order_state_obj.search(
                txn.cursor, txn.user, [], context=context)

            self.assertTrue(states_after_import > states_before_import)

            for state in states:
                self.assertEqual(state.instance.id,
                                 context['magento_instance'])
示例#12
0
    def test_0040_create_state_using_magento_region(self):
        """
        Tests if state is being created when not found using magento region
        """
        state_obj = POOL.get('res.country.state')
        country_obj = POOL.get('res.country')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            country = country_obj.search_using_magento_code(
                txn.cursor, txn.user, 'IN', txn.context)

            states = state_obj.search(txn.cursor,
                                      txn.user, [
                                          ('name', '=', 'UP'),
                                          ('country_id', '=', country.id),
                                      ],
                                      context=txn.context)
            self.assertEqual(len(states), 0)

            # Create state
            state_obj.find_or_create_using_magento_region(
                txn.cursor, txn.user, country, 'UP', txn.context)

            states = state_obj.search(txn.cursor,
                                      txn.user, [
                                          ('name', '=', 'UP'),
                                          ('country_id', '=', country.id),
                                      ],
                                      context=txn.context)
            self.assertEqual(len(states), 1)
    def test0010_create_partner(self):
        """
        Tests if customers imported from magento is created as partners
        in openerp
        """
        partner_obj = POOL.get('res.partner')
        magento_partner_obj = POOL.get('magento.website.partner')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            self.setup_defaults(txn)

            context = deepcopy(CONTEXT)
            context.update({
                'magento_website': self.website_id1,
                'magento_store_view': self.store_view_id,
            })

            if settings.MOCK:
                customer_data = load_json('customers', '1')
            else:
                with magento.Order(*settings.ARGS) as order_api:
                    orders = order_api.list()
                    order_data = order_api.info(orders[0]['increment_id'])
                with magento.Customer(*settings.ARGS) as customer_api:
                    if order_data.get('customer_id'):
                        customer_data = customer_api.info(
                            order_data['customer_id']
                        )
                    else:
                        customer_data = {
                            'firstname': order_data['customer_firstname'],
                            'lastname': order_data['customer_lastname'],
                            'email': order_data['customer_email'],
                            'magento_id': 0
                        }

            partners_before_import = magento_partner_obj.search(
                txn.cursor, txn.user, [], context=context
            )

            # Create partner
            partner = partner_obj.find_or_create(
                txn.cursor, txn.user, customer_data, context
            )
            self.assert_(partner)

            self.assertTrue(
                partner_obj.search(
                    txn.cursor, txn.user, [
                        ('email', '=', customer_data['email'])
                    ], context=context
                )
            )
            partners_after_import = magento_partner_obj.search(
                txn.cursor, txn.user, [], context=context
            )

            self.assertTrue(partners_after_import > partners_before_import)
示例#14
0
    def test_0020_find_or_create_order_using_increment_id(self):
        """
        Tests finding and creating order using increment id
        """
        sale_obj = POOL.get('sale.order')
        partner_obj = POOL.get('res.partner')
        category_obj = POOL.get('product.category')
        magento_order_state_obj = POOL.get('magento.order_state')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_store_view': self.store_view_id,
                'magento_website': self.website_id1,
            })

            magento_order_state_obj.create_all_using_magento_data(
                txn.cursor, txn.user, load_json('order-states', 'all'),
                context=context
            )

            category_tree = load_json('categories', 'category_tree')
            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context
            )

            orders = sale_obj.search(txn.cursor, txn.user, [], context=context)
            self.assertEqual(len(orders), 0)

            order_data = load_json('orders', '100000001')

            with patch('magento.Customer', mock_customer_api(), create=True):
                partner_obj.find_or_create_using_magento_id(
                    txn.cursor, txn.user, order_data['customer_id'], context
                )

            # Create sale order using magento increment_id
            with nested(
                patch('magento.Product', mock_product_api(), create=True),
                patch('magento.Order', mock_order_api(), create=True),
            ):
                order = sale_obj.find_or_create_using_magento_increment_id(
                    txn.cursor, txn.user, order_data['increment_id'],
                    context=context
                )

            orders = sale_obj.search(txn.cursor, txn.user, [], context=context)

            self.assertEqual(len(orders), 1)

            # Item lines + shipping line should be equal to lines on openerp
            self.assertEqual(
                len(order.order_line), len(order_data['items']) + 1
            )
            self.assertEqual(
                order.amount_total, float(order_data['base_grand_total'])
            )
示例#15
0
    def test_0020_import_simple_product(self):
        """Test the import of simple product using magento data
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            category_obj = POOL.get('product.category')
            product_obj = POOL.get('product.product')
            magento_product_obj = POOL.get('magento.website.product')

            category_data = load_json('categories', '8')

            category_obj.create_using_magento_data(txn.cursor,
                                                   txn.user,
                                                   category_data,
                                                   context=context)

            products_before_import = product_obj.search(txn.cursor,
                                                        txn.user, [],
                                                        context=context,
                                                        count=True)

            product_data = load_json('products', '17')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            self.assertEqual(product.categ_id.magento_ids[0].magento_id, 8)
            self.assertEqual(product.magento_product_type, 'simple')
            self.assertEqual(product.name, 'BlackBerry 8100 Pearl')

            products_after_import = product_obj.search(txn.cursor,
                                                       txn.user, [],
                                                       context=context,
                                                       count=True)
            self.assertTrue(products_after_import > products_before_import)

            self.assertEqual(
                product,
                product_obj.find_using_magento_data(txn.cursor, txn.user,
                                                    product_data, context))

            # Make sure the categs created only in website1 and not in
            # website2
            self.assertTrue(
                magento_product_obj.search(txn.cursor,
                                           txn.user, [('website', '=',
                                                       self.website_id1)],
                                           count=True) > 0)
            self.assertTrue(
                magento_product_obj.search(txn.cursor,
                                           txn.user, [('website', '=',
                                                       self.website_id2)],
                                           count=True) == 0)
示例#16
0
    def test_00395_import_sale_with_shipping_tax(self):
        """
        Tests import of sale order with shipping tax
        """
        sale_obj = POOL.get('sale.order')
        partner_obj = POOL.get('res.partner')
        category_obj = POOL.get('product.category')
        tax_obj = POOL.get('account.tax')
        magento_order_state_obj = POOL.get('magento.order_state')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            tax_obj.create(txn.cursor, txn.user, {
                'name': 'VAT on Shipping',
                'amount': float('0.20'),
                'used_on_magento': True,
                'apply_on_magento_shipping': True,
                'price_include': True,
            })
            context.update({
                'magento_instance': self.instance_id1,
                'magento_store_view': self.store_view_id,
                'magento_website': self.website_id1,
            })

            magento_order_state_obj.create_all_using_magento_data(
                txn.cursor, txn.user, load_json('order-states', 'all'),
                context=context
            )

            category_tree = load_json('categories', 'category_tree')
            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context
            )

            order_data = load_json('orders', '100000057')

            with patch('magento.Customer', mock_customer_api(), create=True):
                partner_obj.find_or_create_using_magento_id(
                    txn.cursor, txn.user, order_data['customer_id'], context
                )

            # Create sale order using magento data
            with patch('magento.Product', mock_product_api(), create=True):
                order = sale_obj.find_or_create_using_magento_data(
                    txn.cursor, txn.user, order_data, context=context
                )

            self.assertEqual(
                order.amount_total, float(order_data['base_grand_total'])
            )

            # Item lines + shipping line should be equal to lines on openerp
            self.assertEqual(len(order.order_line), 2)
示例#17
0
    def test_0090_tier_prices(self):
        """Checks the function field on product price tiers
        """
        product_obj = POOL.get('product.product')
        store_obj = POOL.get('magento.website.store')
        category_obj = POOL.get('product.category')
        pricelist_item_obj = POOL.get('product.pricelist.item')
        product_price_tier = POOL.get('product.price_tier')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
                'magento_store': self.store_id,
            })
            store = store_obj.browse(txn.cursor,
                                     txn.user,
                                     self.store_id,
                                     context=context)

            category_data = load_json('categories', '17')

            category_obj.create_using_magento_data(txn.cursor,
                                                   txn.user,
                                                   category_data,
                                                   context=context)

            product_data = load_json('products', '135')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)

            pricelist_item_obj.create(
                txn.cursor,
                txn.user, {
                    'name': 'Test line',
                    'price_version_id':
                    store.shop.pricelist_id.version_id[0].id,
                    'product_id': product.id,
                    'min_quantity': 10,
                    'base': 1,
                    'price_surcharge': -5,
                },
                context=context)

            tier_id = product_price_tier.create(txn.cursor, txn.user, {
                'product': product.id,
                'quantity': 10,
            }, context)
            tier = product_price_tier.browse(txn.cursor, txn.user, tier_id,
                                             context)

            self.assertEqual(product.lst_price - 5, tier.price)
示例#18
0
    def test_0020_search_country_with_invalid_code(self):
        """
        Tests if error is raised for searching country with invalid code
        """
        country_obj = POOL.get('res.country')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            code = 'abc'

            with self.assertRaises(Exception):
                country_obj.search_using_magento_code(txn.cursor, txn.user,
                                                      code, txn.context)
示例#19
0
    def test_0040_create_store_view(self):
        """
        Test creation of a new store view under a store
        Also check if the related fields work as expected
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            instance_obj = POOL.get('magento.instance')
            website_obj = POOL.get('magento.instance.website')
            store_obj = POOL.get('magento.website.store')
            store_view_obj = POOL.get('magento.store.store_view')

            values = {
                'name': 'Test Instance',
                'url': 'some test url',
                'api_user': '******',
                'api_key': 'testkey',
            }
            instance_id = instance_obj.create(
                txn.cursor, txn.user, values, txn.context
            )
            instance = instance_obj.browse(txn.cursor, txn.user, instance_id)

            website_id = website_obj.create(txn.cursor, txn.user, {
                'name': 'A test website',
                'magento_id': 1,
                'code': 'test_code',
                'instance': instance.id,
            })
            website = website_obj.browse(txn.cursor, txn.user, website_id)

            store_id = store_obj.create(txn.cursor, txn.user, {
                'name': 'A test store',
                'magento_id': 1,
                'website': website.id,
            })
            store = store_obj.browse(txn.cursor, txn.user, store_id)

            store_view_id = store_view_obj.create(txn.cursor, txn.user, {
                'name': 'A test store view',
                'code': 'test_code',
                'magento_id': 1,
                'store': store.id,
            })
            store_view = store_view_obj.browse(
                txn.cursor, txn.user, store_view_id
            )

            self.assertEqual(store_view.name, 'A test store view')
            self.assertEqual(store_view.instance, store.instance)
            self.assertEqual(store_view.company, store.company)
            self.assertEqual(store.store_views[0].id, store_view.id)
示例#20
0
    def test_0010_import_product_categories(self):
        """Test the import of product category using magento data
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({'magento_instance': self.instance_id1})

            category_obj = POOL.get('product.category')
            magento_category_obj = POOL.get(
                'magento.instance.product_category')

            categories_before_import = category_obj.search(txn.cursor,
                                                           txn.user, [],
                                                           count=True)

            category_tree = load_json('categories', 'category_tree')

            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context)

            categories_after_import = category_obj.search(txn.cursor,
                                                          txn.user, [],
                                                          count=True)
            self.assertTrue(categories_before_import < categories_after_import)

            # Look for root category
            root_category_id, = category_obj.search(txn.cursor, txn.user,
                                                    [('magento_ids', '!=', []),
                                                     ('parent_id', '=', None)])
            root_category = category_obj.browse(txn.cursor, txn.user,
                                                root_category_id, context)
            self.assertEqual(root_category.magento_ids[0].magento_id, 1)

            self.assertEqual(len(root_category.child_id), 1)
            self.assertEqual(len(root_category.child_id[0].child_id), 4)

            # Make sure the categs created only in instance1 and not in
            # instance2
            self.assertTrue(
                magento_category_obj.search(txn.cursor,
                                            txn.user, [('instance', '=',
                                                        self.instance_id1)],
                                            count=True) > 0)
            self.assertTrue(
                magento_category_obj.search(txn.cursor,
                                            txn.user, [('instance', '=',
                                                        self.instance_id2)],
                                            count=True) == 0)
示例#21
0
    def test_0036_import_sale_with_bundle_plus_child_separate(self):
        """
        Tests import of sale order with bundle product using magento data
        One of the children of the bundle is bought separately too
        Make sure that the lines are created correctly
        """
        sale_obj = POOL.get('sale.order')
        partner_obj = POOL.get('res.partner')
        category_obj = POOL.get('product.category')
        magento_order_state_obj = POOL.get('magento.order_state')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_store_view': self.store_view_id,
                'magento_website': self.website_id1,
            })

            magento_order_state_obj.create_all_using_magento_data(
                txn.cursor, txn.user, load_json('order-states', 'all'),
                context=context
            )

            category_tree = load_json('categories', 'category_tree')
            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context
            )

            order_data = load_json('orders', '100000004')

            with patch('magento.Customer', mock_customer_api(), create=True):
                partner_obj.find_or_create_using_magento_id(
                    txn.cursor, txn.user, order_data['customer_id'], context
                )

            # Create sale order using magento data
            with patch('magento.Product', mock_product_api(), create=True):
                order = sale_obj.find_or_create_using_magento_data(
                    txn.cursor, txn.user, order_data, context=context
                )

            self.assertEqual(
                order.amount_total, float(order_data['base_grand_total'])
            )

            # Item lines + shipping line should be equal to lines on openerp
            self.assertEqual(len(order.order_line), 3)
示例#22
0
    def test_0103_update_product_using_magento_id(self):
        """Check if the product gets updated
        """
        product_obj = POOL.get('product.product')
        category_obj = POOL.get('product.category')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
                'magento_store': self.store_id,
            })

            category_data = load_json('categories', '17')

            category_obj.create_using_magento_data(txn.cursor,
                                                   txn.user,
                                                   category_data,
                                                   context=context)

            product_data = load_json('products', '135001')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            product_before_updation = product_obj.read(txn.cursor,
                                                       txn.user,
                                                       product.id, [],
                                                       context=txn.context)

            # Use a JSON file with product name, code and description changed
            # and everything else same
            with patch('magento.Product', mock_product_api(), create=True):
                product = product_obj.update_from_magento(
                    txn.cursor, txn.user, product, context)
            product_after_updation = product_obj.read(txn.cursor,
                                                      txn.user,
                                                      product.id, [],
                                                      context=txn.context)

            self.assertEqual(product_before_updation['id'],
                             product_after_updation['id'])
            self.assertNotEqual(product_before_updation['name'],
                                product_after_updation['name'])
            self.assertNotEqual(product_before_updation['default_code'],
                                product_after_updation['default_code'])
            self.assertNotEqual(product_before_updation['description'],
                                product_after_updation['description'])
    def test_0030_import_product_wo_categories(self):
        """Test the import of a product using magento data which does not have
        any categories associated
        """
        product_obj = POOL.get('product.product')
        website_obj = POOL.get('magento.instance.website')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            website = website_obj.browse(
                txn.cursor, txn.user, self.website_id1, txn.context
            )

            store_view_magento_id = website.stores[0].store_views[0].magento_id

            if settings.MOCK:
                product_data = load_json('products', '17-wo-category')
            else:
                with magento.Product(*settings.ARGS) as product_api:
                    product_list = product_api.list(
                        store_view=store_view_magento_id
                    )
                    for product in product_list:
                        if not product.get('category_ids'):
                            product_data = product_api.info(
                                product=product['product_id'],
                                store_view=store_view_magento_id
                            )
                            break

            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context
            )
            self.assertEqual(
                product.magento_product_type, product_data['type']
            )
            self.assertEqual(product.name, product_data['name'])
            self.assertEqual(
                product.categ_id.name, 'Unclassified Magento Products'
            )
示例#24
0
    def test_0010_search_country_with_valid_code(self):
        """
        Tests if country can be searched using magento code
        """
        country_obj = POOL.get('res.country')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            code = 'US'

            country_id, = country_obj.search(txn.cursor,
                                             txn.user, [('code', '=', code)],
                                             context=txn.context)

            self.assertEqual(
                country_obj.search_using_magento_code(txn.cursor, txn.user,
                                                      code, txn.context).id,
                country_id)
示例#25
0
    def test_0010_create_instance(self):
        """
        Test creation of a new instance
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            instance_obj = POOL.get('magento.instance')

            values = {
                'name': 'Test Instance',
                'url': 'some test url',
                'api_user': '******',
                'api_key': 'testkey',
            }
            instance_id = instance_obj.create(
                txn.cursor, txn.user, values, txn.context
            )
            instance = instance_obj.browse(txn.cursor, txn.user, instance_id)
            self.assertEqual(instance.name, values['name'])
示例#26
0
    def test_0070_import_downloadable_product(self):
        """Test the import of a downloadable product using magento data
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            product_obj = POOL.get('product.product')

            product_data = load_json('products', '170')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            self.assertEqual(product.magento_product_type, 'downloadable')
            self.assertEqual(product.categ_id.name,
                             'Unclassified Magento Products')
示例#27
0
    def test0030_create_address(self):
        """
        Tests if address creation works as expected
        """
        partner_obj = POOL.get('res.partner')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:

            self.setup_defaults(txn)

            context = deepcopy(CONTEXT)
            context.update({'magento_website': self.website_id1})
            customer_data = load_json('customers', '1')

            # Create partner
            partner = partner_obj.find_or_create(txn.cursor, txn.user,
                                                 customer_data, context)

            address_data = load_json('addresses', '1')

            partners_before_address = partner_obj.search(txn.cursor,
                                                         txn.user, [],
                                                         context=context,
                                                         count=True)

            address_partner = partner_obj.\
                find_or_create_address_as_partner_using_magento_data(
                    txn.cursor, txn.user, address_data, partner, context
                )

            partners_after_address = partner_obj.search(txn.cursor,
                                                        txn.user, [],
                                                        context=context,
                                                        count=True)

            self.assertTrue(partners_after_address > partners_before_address)

            self.assertEqual(
                address_partner.name,
                ' '.join([address_data['firstname'],
                          address_data['lastname']]))
示例#28
0
    def test_0030_import_product_wo_categories(self):
        """Test the import of a product using magento data which does not have
        any categories associated
        """
        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_website': self.website_id1,
            })

            product_obj = POOL.get('product.product')

            product_data = load_json('products', '17-wo-category')
            product = product_obj.find_or_create_using_magento_data(
                txn.cursor, txn.user, product_data, context)
            self.assertEqual(product.magento_product_type, 'simple')
            self.assertEqual(product.name, 'BlackBerry 8100 Pearl')
            self.assertEqual(product.categ_id.name,
                             'Unclassified Magento Products')
示例#29
0
    def test_0060_export_shipment_status_with_tracking_info(self):
        """
        Tests if Tracking information is being updated for shipments
        """
        sale_obj = POOL.get('sale.order')
        partner_obj = POOL.get('res.partner')
        category_obj = POOL.get('product.category')
        magento_order_state_obj = POOL.get('magento.order_state')
        store_view_obj = POOL.get('magento.store.store_view')
        carrier_obj = POOL.get('delivery.carrier')
        product_obj = POOL.get('product.product')
        magento_carrier_obj = POOL.get('magento.instance.carrier')
        picking_obj = POOL.get('stock.picking')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_store_view': self.store_view_id,
                'magento_website': self.website_id1,
            })

            store_view = store_view_obj.browse(txn.cursor,
                                               txn.user,
                                               self.store_view_id,
                                               context=context)

            magento_order_state_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('order-states', 'all'),
                context=context)

            category_tree = load_json('categories', 'category_tree')
            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context)

            orders = sale_obj.search(txn.cursor, txn.user, [], context=context)
            self.assertEqual(len(orders), 0)

            order_data = load_json('orders', '100000001')

            with patch('magento.Customer', mock_customer_api(), create=True):
                partner = partner_obj.find_or_create_using_magento_id(
                    txn.cursor, txn.user, order_data['customer_id'], context)

            # Create sale order using magento data
            with patch('magento.Product', mock_product_api(), create=True):
                order = sale_obj.find_or_create_using_magento_data(
                    txn.cursor, txn.user, order_data, context=context)

            magento_carrier_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('carriers', 'shipping_methods'),
                context=context)

            product_id = product_obj.search(txn.cursor,
                                            txn.user, [],
                                            context=context)[0]

            # Create carrier
            carrier_id = carrier_obj.create(txn.cursor,
                                            txn.user, {
                                                'name': 'DHL',
                                                'partner_id': partner.id,
                                                'product_id': product_id,
                                            },
                                            context=context)

            # Set carrier for sale order
            sale_obj.write(txn.cursor,
                           txn.user,
                           order.id, {'carrier_id': carrier_id},
                           context=context)
            order = sale_obj.browse(txn.cursor, txn.user, order.id, context)

            # Set picking as delivered
            picking_obj.action_assign(txn.cursor, txn.user,
                                      map(int, order.picking_ids))
            picking_obj.action_process(txn.cursor, txn.user,
                                       map(int, order.picking_ids))
            picking_obj.action_done(txn.cursor, txn.user,
                                    map(int, order.picking_ids))

            with patch('magento.Shipment', mock_shipment_api(), create=True):
                # Export shipment status
                shipments = store_view_obj.export_shipment_status_to_magento(
                    txn.cursor, txn.user, store_view, context=context)

                # Export Tracking info
                self.assertEqual(
                    store_view_obj.export_tracking_info_to_magento(
                        txn.cursor, txn.user, shipments[0], context=context),
                    True)
示例#30
0
    def test_0080_export_shipment_status_with_last_export_date_case2(self):
        """
        Tests that if last shipment export time is there then shipment status
        are exported for shipments delivered after last shipment export time
        """
        sale_obj = POOL.get('sale.order')
        partner_obj = POOL.get('res.partner')
        category_obj = POOL.get('product.category')
        magento_order_state_obj = POOL.get('magento.order_state')
        store_view_obj = POOL.get('magento.store.store_view')
        carrier_obj = POOL.get('delivery.carrier')
        product_obj = POOL.get('product.product')
        magento_carrier_obj = POOL.get('magento.instance.carrier')
        picking_obj = POOL.get('stock.picking')

        with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
            self.setup_defaults(txn)
            context = deepcopy(CONTEXT)
            context.update({
                'magento_instance': self.instance_id1,
                'magento_store_view': self.store_view_id,
                'magento_website': self.website_id1,
            })

            store_view = store_view_obj.browse(txn.cursor,
                                               txn.user,
                                               self.store_view_id,
                                               context=context)

            magento_order_state_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('order-states', 'all'),
                context=context)

            category_tree = load_json('categories', 'category_tree')
            category_obj.create_tree_using_magento_data(
                txn.cursor, txn.user, category_tree, context)

            orders = sale_obj.search(txn.cursor, txn.user, [], context=context)
            self.assertEqual(len(orders), 0)

            order_data = load_json('orders', '100000001')

            with patch('magento.Customer', mock_customer_api(), create=True):
                partner = partner_obj.find_or_create_using_magento_id(
                    txn.cursor, txn.user, order_data['customer_id'], context)

            # Create sale order using magento data
            with patch('magento.Product', mock_product_api(), create=True):
                order = sale_obj.find_or_create_using_magento_data(
                    txn.cursor, txn.user, order_data, context=context)

            magento_carrier_obj.create_all_using_magento_data(
                txn.cursor,
                txn.user,
                load_json('carriers', 'shipping_methods'),
                context=context)

            product_id = product_obj.search(txn.cursor,
                                            txn.user, [],
                                            context=context)[0]

            # Create carrier
            carrier_id = carrier_obj.create(txn.cursor,
                                            txn.user, {
                                                'name': 'DHL',
                                                'partner_id': partner.id,
                                                'product_id': product_id,
                                            },
                                            context=context)

            # Set carrier for sale order
            sale_obj.write(txn.cursor,
                           txn.user,
                           order.id, {'carrier_id': carrier_id},
                           context=context)
            order = sale_obj.browse(txn.cursor, txn.user, order.id, context)

            # Set picking as delivered
            picking_obj.action_assign(txn.cursor, txn.user,
                                      map(int, order.picking_ids))
            picking_obj.action_process(txn.cursor, txn.user,
                                       map(int, order.picking_ids))
            picking_obj.action_done(txn.cursor, txn.user,
                                    map(int, order.picking_ids))

            pickings = picking_obj.browse(txn.cursor,
                                          txn.user,
                                          map(int, order.picking_ids),
                                          context=context)

            export_date = datetime.date.today() - relativedelta(days=1)
            store_view_obj.write(
                txn.cursor,
                txn.user,
                store_view.id, {
                    'last_shipment_export_time':
                    export_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
                },
                context=context)
            store_view = store_view_obj.browse(txn.cursor,
                                               txn.user,
                                               store_view.id,
                                               context=context)

            # Since write date is greater than last shipment export time. It
            # should export shipment status successfully
            for picking in pickings:
                self.assertTrue(
                    picking.write_date >= store_view.last_shipment_export_time)

            with patch('magento.Shipment', mock_shipment_api(), create=True):
                # Export shipment status
                store_view_obj.export_shipment_status_to_magento(
                    txn.cursor, txn.user, store_view, context=context)