def test_0030_import_store_views(self): """ Tests import of store view """ with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() with txn.set_context({'company': self.company.id}): instance, = self.Instance.create([{ 'name': 'Test Instance', 'url': 'some test url', 'api_user': '******', 'api_key': 'testkey', 'default_account_expense': self.get_account_by_kind('expense'), 'default_account_revenue': self.get_account_by_kind('revenue'), }]) website = self.Website.find_or_create( instance, load_json('core', 'website') ) store = self.Store.find_or_create( website, load_json('core', 'store') ) store_views_before_import = self.StoreView.search([]) self.StoreView.find_or_create( store, load_json('core', 'store_view') ) store_views_after_import = self.StoreView.search([]) self.assertTrue( store_views_after_import > store_views_before_import )
def test_0050_import_grouped_product(self): """ Test the import of a grouped product using magento data """ Category = POOL.get('product.category') Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', 22) product_data = load_json('products', 54) with txn.set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): Category.create_using_magento_data(category_data) product = Product.find_or_create_using_magento_data( product_data ) self.assertEqual( product.category.magento_ids[0].magento_id, 22 ) self.assertEqual( product.channel_listings[0].magento_product_type, 'grouped' )
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self): """ Tests import of sale order with bundle product using magento data This tests that the duplication of BoMs doesnot happen """ Sale = POOL.get('sale.sale') ProductTemplate = POOL.get('product.template') Category = POOL.get('product.category') MagentoOrderState = POOL.get('magento.order_state') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): MagentoOrderState.create_all_using_magento_data( load_json('order-states', 'all'), ) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '300000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product_template = \ ProductTemplate.find_or_create_using_magento_id(158) product = product_template.products[0] self.assertTrue(len(product.boms), 1) self.assertTrue(len(product.boms[0].bom.inputs), 2) order_data = load_json('orders', '300000001-a') # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product_template = \ ProductTemplate.find_or_create_using_magento_id( 158 ) self.assertEqual(len(product.boms), 1) self.assertEqual(len(product.boms[0].bom.inputs), 2)
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_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'] )
def test_0030_import_store_views(self): """ Tests import of store view """ with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() with txn.set_context({'company': self.company.id}): instance, = self.Instance.create([{ 'name': 'Test Instance', 'url': 'some test url', 'api_user': '******', 'api_key': 'testkey', 'default_account_expense': self.get_account_by_kind('expense'), 'default_account_revenue': self.get_account_by_kind('revenue'), }]) website = self.Website.find_or_create( instance, load_json('core', 'website')) store = self.Store.find_or_create(website, load_json('core', 'store')) store_views_before_import = self.StoreView.search([]) self.StoreView.find_or_create(store, load_json('core', 'store_view')) store_views_after_import = self.StoreView.search([]) self.assertTrue( store_views_after_import > store_views_before_import)
def test_0103_update_product_using_magento_id(self): """ Check if the product template gets updated using magento ID """ Product = POOL.get("product.product") Category = POOL.get("product.category") with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({"current_channel": self.channel1.id, "company": self.company.id}): category_data = load_json("categories", "17") Category.create_using_magento_data(category_data) product_data = load_json("products", "135001") product1 = Product.find_or_create_using_magento_data(product_data) product_id_before_updation = product1.id product_name_before_updation = product1.name product_code_before_updation = product1.products[0].code product_description_before_updation = product1.products[0].description # Use a JSON file with product name, code and description # changed and everything else same with patch("magento.Product", mock_product_api(), create=True): product2 = product1.update_from_magento() self.assertEqual(product_id_before_updation, product2.id) self.assertNotEqual(product_name_before_updation, product2.name) self.assertNotEqual(product_code_before_updation, product2.products[0].code) self.assertNotEqual(product_description_before_updation, product2.products[0].description)
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 = POOL.get('product.product') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') Product.find_or_create_using_magento_data(product_data) with patch('magento.Inventory', mock_inventory_api(), create=True): self.channel1.export_inventory()
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_0080_import_sale_order_with_bundle_product(self): """ Tests import of sale order with bundle product using magento data """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): order_states_list = load_json('order-states', 'all') for code, name in order_states_list.iteritems(): self.channel1.create_order_state(code, name) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '300000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 2) self.assertEqual( order.total_amount, Decimal(order_data['base_grand_total']) ) # There should be a BoM for the bundle product product = self.channel1.import_product('VGN-TXN27N-BW') self.assertEqual(len(product.boms), 1) self.assertEqual( len(product.boms[0].bom.inputs), 2 )
def test_0050_import_grouped_product(self): """ Test the import of a grouped product using magento data """ Category = POOL.get('product.category') ProductTemplate = POOL.get('product.template') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', 22) product_data = load_json('products', 54) with txn.set_context({ 'magento_instance': self.instance1, 'magento_website': self.website1, 'company': self.company, }): Category.create_using_magento_data(category_data) template = ProductTemplate.find_or_create_using_magento_data( product_data ) self.assertEqual( template.category.magento_ids[0].magento_id, 22 ) self.assertEqual( template.magento_product_type, 'grouped' )
def test_0120_export_channel_tier_prices_to_magento(self): """ Tests if tier prices from product listing is exported to magento """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') MagentoPriceTier = POOL.get('sale.channel.magento.price_tier') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertFalse(self.channel1.magento_price_tiers) # Add price tiers to channel MagentoPriceTier.create([{ 'channel': self.channel1.id, 'quantity': 10, }]) self.assertEqual(order.state, 'confirmed') self.assertEqual(len(Sale.search([])), 1) # Export tier prices to magento with patch('magento.ProductTierPrice', mock_tier_price_api(), create=True): product_listings = \ self.channel1.export_product_prices() self.assertEqual(product_listings, 2) self.assertEqual( self.channel1.last_product_price_export_time.date(), datetime.utcnow().date())
def test_0020_import_simple_product(self): """ Test the import of simple product using Magento Data """ Category = POOL.get("product.category") Product = POOL.get("product.product") ProductSaleChannelListing = POOL.get("product.product.channel_listing") with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json("categories", "8") with txn.set_context({"current_channel": self.channel1.id, "company": self.company.id}): Category.create_using_magento_data(category_data) products_before_import = Product.search([], count=True) product_data = load_json("products", "17") product = Product.find_or_create_using_magento_data(product_data) self.assertEqual(product.category.magento_ids[0].magento_id, 8) self.assertEqual(product.channel_listings[0].magento_product_type, "simple") self.assertEqual(product.name, "BlackBerry 8100 Pearl") products_after_import = Product.search([], count=True) self.assertTrue(products_after_import > products_before_import) # Make sure the categs are created only in channel1 and not # not in channel2 self.assertTrue(ProductSaleChannelListing.search([("channel", "=", self.channel1)], count=True) > 0) self.assertTrue(ProductSaleChannelListing.search([("channel", "=", self.channel2)], count=True) == 0)
def test_0090_tier_prices(self): """Checks the function field on product price tiers """ PriceList = POOL.get("product.price_list") ProductPriceTier = POOL.get("product.price_tier") Product = POOL.get("product.product") Category = POOL.get("product.category") User = POOL.get("res.user") with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() context = User.get_preferences(context_only=True) context.update({"current_channel": self.channel1.id, "company": self.company.id}) with txn.set_context(context): category_data = load_json("categories", "17") Category.create_using_magento_data(category_data) product_data = load_json("products", "135") product = Product.find_or_create_using_magento_data(product_data) price_list, = PriceList.create( [{"name": "Test Pricelist", "lines": [("create", [{"quantity": 10, "formula": "unit_price*0.9"}])]}] ) self.channel1.price_list = price_list self.channel1.save() self.assertEqual(len(product.channel_listings), 1) listing = product.channel_listings[0] tier, = ProductPriceTier.create([{"product_listing": listing.id, "quantity": 10}]) self.assertEqual(listing.product.list_price * Decimal("0.9"), tier.price)
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 = POOL.get('product.product') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') Product.find_or_create_using_magento_data( product_data ) with patch( 'magento.Inventory', mock_inventory_api(), create=True ): self.channel1.export_inventory()
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']) )
def test_0070_export_order_status_with_last_order_export_time_case2(self): """ Tests that sale can be exported if last order export time is smaller than sale's write date """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001-draft') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'cancel') self.assertEqual(len(Sale.search([])), 1) export_date = datetime.utcnow() - relativedelta(days=1) self.StoreView.write([self.store_view], {'last_order_export_time': export_date}) self.assertTrue( self.store_view.last_order_export_time < order.write_date) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.store_view.export_order_status_for_store_view() self.assertEqual(len(order_exported), 1) self.assertEqual(order_exported[0], order)
def test_0070_update_product_using_magento_data(self): """ Check if the product template gets updated using magento data """ ProductTemplate = POOL.get('product.template') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_website': self.website1.id, 'magento_store': self.store, 'company': self.company, }): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') product_template1 = \ ProductTemplate.find_or_create_using_magento_data( product_data ) product_template_id_before_updation = product_template1.id product_template_name_before_updation = product_template1.name product_code_before_updation = \ product_template1.products[0].code product_description_before_updation = \ product_template1.products[0].description # Use a JSON file with product name, code and description # changed and everything else same product_data = load_json('products', '135001') product_template2 = \ product_template1.update_from_magento_using_data( product_data ) self.assertEqual( product_template_id_before_updation, product_template2.id ) self.assertNotEqual( product_template_name_before_updation, product_template2.name ) self.assertNotEqual( product_code_before_updation, product_template2.products[0].code ) self.assertNotEqual( product_description_before_updation, product_template2.products[0].description )
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)
def test_0070_export_order_status_with_last_order_export_time_case2(self): """ Tests that sale can be exported if last order export time is smaller than sale's write date """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001-draft') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'cancel') self.assertEqual(len(Sale.search([])), 1) export_date = datetime.utcnow() - relativedelta(days=1) self.StoreView.write([self.store_view], { 'last_order_export_time': export_date }) self.assertTrue( self.store_view.last_order_export_time < order.write_date ) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.store_view.export_order_status_for_store_view() self.assertEqual(len(order_exported), 1) self.assertEqual(order_exported[0], order)
def test_0070_update_product_using_magento_data(self): """ Check if the product template gets updated using magento data """ Product = POOL.get('product.product') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') product1 = \ Product.find_or_create_using_magento_data( product_data ) product_id_before_updation = product1.id product_name_before_updation = product1.name product_code_before_updation = \ product1.products[0].code product_description_before_updation = \ product1.products[0].description # Use a JSON file with product name, code and description # changed and everything else same product_data = load_json('products', '135001') product2 = \ product1.update_from_magento_using_data( product_data ) self.assertEqual( product_id_before_updation, product2.id ) self.assertNotEqual( product_name_before_updation, product2.name ) self.assertNotEqual( product_code_before_updation, product2.products[0].code ) self.assertNotEqual( product_description_before_updation, product2.products[0].description )
def test_0080_import_sale_order_with_bundle_product(self): """ Tests import of sale order with bundle product using magento data """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): order_states_list = load_json('order-states', 'all') for code, name in order_states_list.iteritems(): self.channel1.create_order_state(code, name) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '300000001') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 2) self.assertEqual(order.total_amount, Decimal(order_data['base_grand_total'])) # There should be a BoM for the bundle product product = self.channel1.import_product('VGN-TXN27N-BW') self.assertEqual(len(product.boms), 1) self.assertEqual(len(product.boms[0].bom.inputs), 2)
def test_0090_find_or_create_order_using_magento_id(self): """ Tests if magento_id is not copied in duplicate sales """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch( 'magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento increment_id with patch('magento.Order', mock_order_api(), create=True): with patch( 'magento.Product', mock_product_api(), create=True ): order = \ Sale.find_or_create_using_magento_increment_id( order_data['increment_id'] ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertIsNotNone(order.magento_id) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual( len(order.lines), len(order_data['items']) + 1 ) new_sales = Sale.copy(orders) self.assertTrue(new_sales) self.assertEqual(len(new_sales), 1) self.assertIsNone(new_sales[0].magento_id)
def test_0010_create_sale_using_amazon_data_with_exception(self): """ Tests creation of sale order using amazon data """ Sale = POOL.get('sale.sale') Product = POOL.get('product.product') Party = POOL.get('party.party') ContactMechanism = POOL.get('party.contact_mechanism') ChannelException = POOL.get('channel.exception') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.sale_channel.id, }): orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', 'order_list')['Orders']['Order'] line_data = load_json('orders', 'order_items')['OrderItems']['OrderItem'] self.assertFalse( Party.search([('name', '=', order_data['BuyerEmail']['value'])])) self.assertFalse( ContactMechanism.search([ ('party.name', '=', order_data['BuyerEmail']['value']), ('type', 'in', ['phone', 'mobile']), ('value', '=', order_data['ShippingAddress']['Phone']['value']), ])) # Create product using sku product_data = load_json('products', 'product-1') product_data.update( {'Id': { 'value': line_data['SellerSKU']['value'] }}) Product.create_using_amazon_data(product_data) self.assertFalse(ChannelException.search([])) with Transaction().set_context(company=self.company.id): order = Sale.create_using_amazon_data( order_data, line_data) # Since order total does not match self.assertTrue(ChannelException.search([])) self.assertEqual(order.state, 'draft')
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)
def test_0020_import_sale_order_with_exception(self): """ Tests if exception is created for sale order when order total mismatch """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Product = POOL.get('product.product') ChannelException = POOL.get('channel.exception') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company }): orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json( 'orders', '283054010' )['OrderArray']['Order'][0] Party.create_using_ebay_data( load_json('users', 'testuser_ritu123') ) Product.create_using_ebay_data( load_json('products', '110162956809') ) Product.create_using_ebay_data( load_json('products', '110162957156') ) self.assertEqual(order_data['Total']['value'], '4.0') self.assertFalse(ChannelException.search([])) # Lets Change order total to make it raise exception order_data['Total']['value'] = '8.5' order = self.ebay_channel.import_order(order_data) self.assertTrue(ChannelException.search([])) self.assertTrue(order.has_channel_exception) self.assertNotEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 3)
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self): """ Tests import of sale order with bundle product using magento data This tests that the duplication of BoMs doesnot happen """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): order_states_list = load_json('order-states', 'all') for code, name in order_states_list.iteritems(): self.channel1.create_order_state(code, name) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '300000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product = self.channel1.import_product( 'VGN-TXN27N-BW' ) self.assertTrue(len(product.boms), 1) self.assertTrue(len(product.boms[0].bom.inputs), 2) order_data = load_json('orders', '300000001-a') # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product = self.channel1.import_product( 'VGN-TXN27N-BW' ) self.assertEqual(len(product.boms), 1) self.assertEqual(len(product.boms[0].bom.inputs), 2)
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)
def test_0060_export_order_status_with_last_order_export_time_case1(self): """ Tests that sale cannot be exported if last order export time is greater than sale's write date """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'confirmed') self.assertEqual(len(Sale.search([])), 1) export_date = datetime.utcnow() + relativedelta(days=1) self.channel1.last_order_export_time = export_date self.channel1.save() self.assertTrue( self.channel1.last_order_export_time > order.write_date ) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.channel1.export_order_status_to_magento() self.assertEqual(len(order_exported), 0)
def test_0090_find_or_create_order_using_magento_id(self): """ Tests if magento_id is not copied in duplicate sales """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento increment_id with patch('magento.Order', mock_order_api(), create=True): with patch('magento.Product', mock_product_api(), create=True): order = \ Sale.find_or_create_using_magento_increment_id( order_data['increment_id'] ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertIsNotNone(order.magento_id) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), len(order_data['items']) + 1) new_sales = Sale.copy(orders) self.assertTrue(new_sales) self.assertEqual(len(new_sales), 1) self.assertIsNone(new_sales[0].magento_id)
def test_0020_import_sale_order_with_exception(self): """ Tests if exception is created for sale order when order total mismatch """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Product = POOL.get('product.product') ChannelException = POOL.get('channel.exception') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company }): orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '283054010')['OrderArray']['Order'][0] Party.create_using_ebay_data( load_json('users', 'testuser_ritu123')) Product.create_using_ebay_data( load_json('products', '110162956809')) Product.create_using_ebay_data( load_json('products', '110162957156')) self.assertEqual(order_data['Total']['value'], '4.0') self.assertFalse(ChannelException.search([])) # Lets Change order total to make it raise exception order_data['Total']['value'] = '8.5' order = self.ebay_channel.import_order(order_data) self.assertTrue(ChannelException.search([])) self.assertTrue(order.has_channel_exception) self.assertNotEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 3)
def test_0040_find_or_create_order_using_increment_id(self): """ Tests finding and creating order using increment id """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento increment_id with patch('magento.Order', mock_order_api(), create=True): with patch('magento.Product', mock_product_api(), create=True): order = \ Sale.find_or_create_using_magento_increment_id( order_data['increment_id'] ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), len(order_data['items']) + 1)
def test_0060_export_order_status_with_last_order_export_time_case1(self): """ Tests that sale cannot be exported if last order export time is greater than sale's write date """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'confirmed') self.assertEqual(len(Sale.search([])), 1) export_date = datetime.utcnow() + relativedelta(days=1) self.channel1.last_order_export_time = export_date self.channel1.save() self.assertTrue( self.channel1.last_order_export_time > order.write_date) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.channel1.export_order_status_to_magento() self.assertEqual(len(order_exported), 0)
def test_0020_import_simple_product(self): """ Test the import of simple product using Magento Data """ Category = POOL.get('product.category') Product = POOL.get('product.product') ProductSaleChannelListing = POOL.get('product.product.channel_listing') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', '8') with txn.set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): Category.create_using_magento_data(category_data) products_before_import = Product.search([], count=True) product_data = load_json('products', '17') product = Product.find_or_create_using_magento_data( product_data ) self.assertEqual(product.category.magento_ids[0].magento_id, 8) self.assertEqual( product.channel_listings[0].magento_product_type, 'simple' ) self.assertEqual(product.name, 'BlackBerry 8100 Pearl') products_after_import = Product.search([], count=True) self.assertTrue(products_after_import > products_before_import) self.assertEqual( product, Product.find_using_magento_data( product_data ) ) # Make sure the categs are created only in channel1 and not # not in channel2 self.assertTrue(ProductSaleChannelListing.search( [('channel', '=', self.channel1)], count=True) > 0 ) self.assertTrue(ProductSaleChannelListing.search( [('channel', '=', self.channel2)], count=True) == 0 )
def test_0050_export_order_status_to_magento(self): """ Tests if order status is exported to magento """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001-draft') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'cancel') self.assertEqual(len(Sale.search([])), 1) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.store_view.export_order_status_for_store_view() self.assertEqual(len(order_exported), 1) self.assertEqual(order_exported[0], order)
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self): """ Tests import of sale order with bundle product using magento data This tests that the duplication of BoMs doesnot happen """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): order_states_list = load_json('order-states', 'all') for code, name in order_states_list.iteritems(): self.channel1.create_order_state(code, name) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '300000001') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product = self.channel1.import_product('VGN-TXN27N-BW') self.assertTrue(len(product.boms), 1) self.assertTrue(len(product.boms[0].bom.inputs), 2) order_data = load_json('orders', '300000001-a') # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product = self.channel1.import_product('VGN-TXN27N-BW') self.assertEqual(len(product.boms), 1) self.assertEqual(len(product.boms[0].bom.inputs), 2)
def test_0040_find_or_create_order_using_increment_id(self): """ Tests finding and creating order using increment id """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch( 'magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento increment_id with patch('magento.Order', mock_order_api(), create=True): with patch( 'magento.Product', mock_product_api(), create=True ): order = \ Sale.find_or_create_using_magento_increment_id( order_data['increment_id'] ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual( len(order.lines), len(order_data['items']) + 1 )
def test_0020_import_simple_product(self): """ Test the import of simple product using Magento Data """ Category = POOL.get('product.category') ProductTemplate = POOL.get('product.template') MagentoTemplate = POOL.get('magento.website.template') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', '8') with txn.set_context({ 'magento_instance': self.instance1, 'magento_website': self.website1, 'company': self.company, }): Category.create_using_magento_data(category_data) products_before_import = ProductTemplate.search([], count=True) product_data = load_json('products', '17') template = ProductTemplate.find_or_create_using_magento_data( product_data ) self.assertEqual(template.category.magento_ids[0].magento_id, 8) self.assertEqual(template.magento_product_type, 'simple') self.assertEqual(template.name, 'BlackBerry 8100 Pearl') products_after_import = ProductTemplate.search([], count=True) self.assertTrue(products_after_import > products_before_import) self.assertEqual( template, ProductTemplate.find_using_magento_data( product_data ) ) # Make sure the categs are created only in website1 and not # not in website2 self.assertTrue(MagentoTemplate.search( [('website', '=', self.website1)], count=True) > 0 ) self.assertTrue(MagentoTemplate.search( [('website', '=', self.website2)], count=True) == 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')))
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)
def test_0030_import_sale_order_with_products_with_new(self): """ Tests import of sale order using magento data with magento state as new """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch( 'magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'confirmed') self.assertFalse(order.has_magento_exception) orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual( len(order.lines), len(order_data['items']) + 1 )
def test_0010_import_sale_order(self): """ Tests import of sale order using ebay data with ebay state as new """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company }): orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json( 'orders', '283054010' )['OrderArray']['Order'][0] Party.create_using_ebay_data( load_json('users', 'testuser_ritu123') ) Product.create_using_ebay_data( load_json('products', '110162956809') ) Product.create_using_ebay_data( load_json('products', '110162957156') ) order1 = self.ebay_channel.import_order(order_data) self.assertEqual(order1.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order1.lines), 3) order2 = self.ebay_channel.import_order(order_data) orders = Sale.search([]) self.assertEqual(len(orders), 1) self.assertEqual(order1, order2)
def test0030_import_addresses_from_ebay(self): """ Test address import as party addresses and make sure no duplication is there. """ with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() # Load json of address data ebay_data = load_json('users', 'testuser_ritu123') order_data = load_json( 'orders', '283054010' )['OrderArray']['Order'][0] address_data = order_data['ShippingAddress'] party = self.Party.create_using_ebay_data(ebay_data) # Check party address before address import self.assertFalse(party.addresses) # Import address for party1 from ebay address1 = party.find_or_create_address_using_ebay_data( address_data ) # Check address after import self.assertEqual(len(party.addresses), 1) self.assertEqual(address1.party, party) self.assertEqual( address1.name, address_data['Name'] ) self.assertEqual(address1.street, address_data['Street1']) self.assertEqual(address1.zip, address_data['PostalCode']) self.assertEqual(address1.city, address_data['CityName']) self.assertEqual( address1.country.code, address_data['Country'] ) self.assertEqual( address1.subdivision.name.lower(), 'washington' ) # Try to import same address again. and it wont create new one address2 = party.find_or_create_address_using_ebay_data( address_data ) self.assertEqual(address1, address2) self.assertEqual(len(party.addresses), 1)
def test_0100_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 = POOL.get('sale.sale') Category = POOL.get('product.category') MagentoOrderState = POOL.get('magento.order_state') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): MagentoOrderState.create_all_using_magento_data( load_json('order-states', 'all'), ) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '100000004') with patch('magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.total_amount, Decimal(order_data['base_grand_total'])) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 3)
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_0035_import_sale_order_with_products_with_processing(self): """ Tests import of sale order using magento data with magento state as processing """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001-processing') with patch( 'magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'processing') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual( len(order.lines), len(order_data['items']) + 1 )
def test_0100_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 = POOL.get('sale.sale') Category = POOL.get('product.category') MagentoOrderState = POOL.get('magento.order_state') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): MagentoOrderState.create_all_using_magento_data( load_json('order-states', 'all'), ) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '100000004') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual( order.total_amount, Decimal(order_data['base_grand_total']) ) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 3)
def test_0050_export_order_status_to_magento(self): """ Tests if order status is exported to magento """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001-draft') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'cancel') self.assertEqual(len(Sale.search([])), 1) with patch('magento.Order', mock_order_api(), create=True): order_exported = \ self.store_view.export_order_status_for_store_view() self.assertEqual(len(order_exported), 1) self.assertEqual(order_exported[0], order)
def test0010_create_party(self): """ Tests if customers imported from magento is created as party in tryton """ MagentoParty = POOL.get('sale.channel.magento.party') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() Transaction().context.update({'current_channel': self.channel1.id}) magento_data = load_json('customers', '1') customer_name = u' '.join( [magento_data['firstname'], magento_data['lastname']]) self.assertFalse(self.Party.search([('name', '=', customer_name)])) parties = MagentoParty.search([]) self.assertEqual(len(parties), 0) # Create party party = self.Party.find_or_create_using_magento_data(magento_data) self.assert_(party) self.assertTrue(self.Party.search([('name', '=', customer_name)])) self.assertTrue(len(party.contact_mechanisms), 1) self.assertTrue(party.contact_mechanisms[0].email) parties = MagentoParty.search([]) self.assertEqual(len(parties), 1)
def test0010_create_party(self): """ Tests if users imported from ebay is created as party in tryton """ with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() ebay_data = load_json('users', 'testuser_shalabhaggarwal') self.assertFalse( self.Party.search([ ('name', '=', 'testuser_shalabhaggarwal') ]) ) # Create party party = self.Party.create_using_ebay_data(ebay_data) self.assert_(party) self.assertTrue( self.Party.search([ ('name', '=', 'testuser_shalabhaggarwal') ]) ) party, = self.Party.search([ ('name', '=', 'testuser_shalabhaggarwal') ]) self.assertTrue(len(party.contact_mechanisms), 1) self.assertTrue(party.contact_mechanisms[0].email) # Create party with same data again and it will raise error with self.assertRaises(UserError): self.Party.create_using_ebay_data(ebay_data)
def test0035_import_phone_from_ebay(self): """ Test address import as party addresses and make sure no duplication is there. """ with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() # Load json of address data ebay_data = load_json('users', 'testuser_shalabhaggarwal') address_data = ebay_data['User']['RegistrationAddress'] # Check party phone before import self.assertFalse(self.party.phone) self.assertEqual(len(self.party.contact_mechanisms), 0) # Add phone to party using ebay data self.party.add_phone_using_ebay_data( address_data['Phone']['value'] ) self.assertTrue(self.party.phone) self.assertEqual(len(self.party.contact_mechanisms), 1) # Add same phone again to party using ebay data, it wont # create new one self.party.add_phone_using_ebay_data( address_data['Phone']['value'] ) self.assertEqual(len(self.party.contact_mechanisms), 1)
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'])
def test0010_create_party(self): """ Tests if users imported from ebay is created as party in tryton """ with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() ebay_data = load_json('users', 'testuser_ritu123') self.assertFalse( self.Party.search([('name', '=', 'testuser_ritu123')])) # Create party party = self.Party.create_using_ebay_data(ebay_data) self.assert_(party) self.assertTrue( self.Party.search([('name', '=', 'testuser_ritu123')])) party, = self.Party.search([('name', '=', 'testuser_ritu123')]) self.assertTrue(len(party.contact_mechanisms), 1) self.assertTrue(party.contact_mechanisms[0].email) # Create party with same data again and it will raise error with self.assertRaises(UserError): self.Party.create_using_ebay_data(ebay_data)
def test0035_import_phone_from_ebay(self): """ Test address import as party addresses and make sure no duplication is there. """ with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() # Load json of address data order_data = load_json('orders', '283054010')['OrderArray']['Order'][0] address_data = order_data['ShippingAddress'] # Check party phone before import self.assertFalse(self.party.phone) self.assertEqual(len(self.party.contact_mechanisms), 0) # Add phone to party using ebay data self.party.add_phone_using_ebay_data(address_data['Phone']) self.assertTrue(self.party.phone) self.assertEqual(len(self.party.contact_mechanisms), 1) # Add same phone again to party using ebay data, it wont # create new one self.party.add_phone_using_ebay_data(address_data['Phone']) self.assertEqual(len(self.party.contact_mechanisms), 1)