From 58bfeb6f3629abc502019bfd614647f2a60596f8 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Tue, 18 Jun 2019 09:29:53 +0000 Subject: [PATCH 01/11] [IMP] stock: pass tests without demo data for file test_move. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_move.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 76a156d14ba..db6cc6081e9 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -715,7 +715,7 @@ class StockMove(SavepointCase): }) # putaway from stock to shelf1 putaway = self.env['stock.putaway.rule'].create({ - 'product_id': self.env.ref('product.product_product_5').id, + 'product_id': self.product.id, 'location_in_id': self.stock_location.id, 'location_out_id': shelf1_location.id, }) @@ -728,7 +728,7 @@ class StockMove(SavepointCase): 'name': 'test_putaway_2', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.env.ref('product.product_product_5').id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -766,7 +766,7 @@ class StockMove(SavepointCase): 'location_out_id': shelf1_location.id, }) putaway_product = self.env['stock.putaway.rule'].create({ - 'product_id': self.env.ref('stock.product_cable_management_box').id, + 'product_id': self.product.id, 'location_in_id': self.supplier_location.id, 'location_out_id': shelf2_location.id, }) @@ -782,8 +782,8 @@ class StockMove(SavepointCase): 'name': 'test_putaway_3', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.env.ref('stock.product_cable_management_box').id, - 'product_uom': self.env.ref('uom.product_uom_kgm').id, + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) move1._action_confirm() @@ -822,7 +822,7 @@ class StockMove(SavepointCase): 'location_out_id': shelf1_location.id, }) putaway_product = self.env['stock.putaway.rule'].create({ - 'product_id': self.env.ref('stock.product_cable_management_box').id, + 'product_id': self.product_consu.id, 'location_in_id': self.stock_location.id, 'location_out_id': shelf2_location.id, }) @@ -876,14 +876,13 @@ class StockMove(SavepointCase): putaway.id, ])], }) - # creation move1 = self.env['stock.move'].create({ 'name': 'test_putaway_5', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.env.ref('stock.product_cable_management_box').id, - 'product_uom': self.env.ref('uom.product_uom_kgm').id, + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) move1._action_confirm() @@ -920,7 +919,7 @@ class StockMove(SavepointCase): 'location_out_id': shelf1_location.id, }) putaway_category_office_furn = self.env['stock.putaway.rule'].create({ - 'category_id': self.env.ref('product.product_category_5').id, + 'category_id': self.ref('product.product_category_all'), 'location_in_id': self.supplier_location.id, 'location_out_id': shelf2_location.id, }) @@ -930,14 +929,15 @@ class StockMove(SavepointCase): putaway_category_office_furn.id, ])], }) + self.product.categ_id = self.ref('product.product_category_all') # creation move1 = self.env['stock.move'].create({ 'name': 'test_putaway_6', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.env.ref('stock.product_cable_management_box').id, - 'product_uom': self.env.ref('uom.product_uom_kgm').id, + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) move1._action_confirm() From 0ff7d7840dd01acfe95ee3b7c4ca05cae2bd61b8 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 05:10:39 +0000 Subject: [PATCH 02/11] [IMP] stock: pass tests without demo data for file test_move2. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_move2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 93d73faa16f..d0dcae56666 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -1892,6 +1892,7 @@ class TestRoutes(TestStockCommon): 'categ_id': self.env.ref('product.product_category_all').id, }) self.uom_unit = self.env.ref('uom.product_uom_unit') + self.partner = self.env['res.partner'].create({'name': 'Partner'}) def _enable_pick_ship(self): self.wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) @@ -2040,7 +2041,7 @@ class TestRoutes(TestStockCommon): """ warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) warehouse.delivery_steps = 'pick_pack_ship' - partner_demo_customer = self.env.ref('base.res_partner_1') + partner_demo_customer = self.partner final_location = partner_demo_customer.property_stock_customer product_a = self.env['product.product'].create({ 'name': 'ProductA', @@ -2098,7 +2099,7 @@ class TestRoutes(TestStockCommon): """ warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) warehouse.delivery_steps = 'pick_pack_ship' - partner_demo_customer = self.env.ref('base.res_partner_1') + partner_demo_customer = self.partner final_location = partner_demo_customer.property_stock_customer product_a = self.env['product.product'].create({ 'name': 'ProductA', @@ -2144,7 +2145,7 @@ class TestRoutes(TestStockCommon): """ warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) warehouse.delivery_steps = 'pick_pack_ship' - partner_demo_customer = self.env.ref('base.res_partner_1') + partner_demo_customer = self.partner final_location = partner_demo_customer.property_stock_customer product_a = self.env['product.product'].create({ 'name': 'ProductA', @@ -2237,7 +2238,7 @@ class TestRoutes(TestStockCommon): """ warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) warehouse.delivery_steps = 'pick_pack_ship' - partner_demo_customer = self.env.ref('base.res_partner_1') + partner_demo_customer = self.partner final_location = partner_demo_customer.property_stock_customer product_a = self.env['product.product'].create({ 'name': 'ProductA', From 3f02ae8996661a57db98e5bf5d80b643f4f409b3 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 05:21:10 +0000 Subject: [PATCH 03/11] [IMP] stock: pass tests without demo data for file test_packing_neg. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_packing_neg.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/stock/tests/test_packing_neg.py b/addons/stock/tests/test_packing_neg.py index 13a897c231b..f534b42b237 100644 --- a/addons/stock/tests/test_packing_neg.py +++ b/addons/stock/tests/test_packing_neg.py @@ -7,6 +7,15 @@ from odoo.tests.common import TransactionCase class TestPackingNeg(TransactionCase): def test_packing_neg(self): + res_partner_2 = self.env['res.partner'].create({ + 'name': 'Deco Addict', + 'email': 'deco.addict82@example.com', + }) + + res_partner_4 = self.env['res.partner'].create({ + 'name': 'Ready Mat', + 'email': 'ready.mat28@example.com', + }) # Create a new "negative" storable product product_neg = self.env['product.product'].create({ @@ -17,7 +26,7 @@ class TestPackingNeg(TransactionCase): 'standard_price': 70.0, 'seller_ids': [(0, 0, { 'delay': 1, - 'name': self.ref('base.res_partner_2'), + 'name': res_partner_2.id, 'min_qty': 2.0,})], 'uom_id': self.ref('uom.product_uom_unit'), 'uom_po_id': self.ref('uom.product_uom_unit'), @@ -26,7 +35,7 @@ class TestPackingNeg(TransactionCase): # Create an incoming picking for this product of 300 PCE from suppliers to stock vals = { 'name': 'Incoming picking (negative product)', - 'partner_id': self.ref('base.res_partner_2'), + 'partner_id': res_partner_2.id, 'picking_type_id': self.ref('stock.picking_type_in'), 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), @@ -83,7 +92,7 @@ class TestPackingNeg(TransactionCase): # Make a delivery order of 300 pieces to the customer vals = { 'name': 'outgoing picking (negative product)', - 'partner_id': self.ref('base.res_partner_4'), + 'partner_id': res_partner_4.id, 'picking_type_id': self.ref('stock.picking_type_out'), 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), @@ -140,7 +149,7 @@ class TestPackingNeg(TransactionCase): # Create a picking for reconciling the negative quant vals = { 'name': 'reconciling_delivery', - 'partner_id': self.ref('base.res_partner_4'), + 'partner_id': res_partner_4.id, 'picking_type_id': self.ref('stock.picking_type_in'), 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), From a31ee1c0c6e0d3fed68ae36007ae375dff5fb8d3 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 05:44:04 +0000 Subject: [PATCH 04/11] [IMP] stock: pass tests without demo data for file proc_rule. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_proc_rule.py | 42 +++++++++++++++++----------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/addons/stock/tests/test_proc_rule.py b/addons/stock/tests/test_proc_rule.py index 39e958e7701..7789563ad21 100644 --- a/addons/stock/tests/test_proc_rule.py +++ b/addons/stock/tests/test_proc_rule.py @@ -9,6 +9,16 @@ from odoo.tools import mute_logger class TestProcRule(TransactionCase): + def setUp(self): + super(TestProcRule, self).setUp() + + self.uom_unit = self.env.ref('uom.product_uom_unit') + self.product = self.env['product.product'].create({ + 'name': 'Desk Combination', + 'type': 'consu', + }) + self.partner = self.env['res.partner'].create({'name': 'Partner'}) + def test_proc_rule(self): # Create a product route containing a stock rule that will # generate a move from Stock for every procurement created in Output @@ -25,14 +35,14 @@ class TestProcRule(TransactionCase): }) # Set this route on `product.product_product_3` - self.env.ref('product.product_product_3').write({ + self.product.write({ 'route_ids': [(4, product_route.id)]}) # Create Delivery Order of 10 `product.product_product_3` from Output -> Customer - product = self.env.ref('product.product_product_3') + product = self.product vals = { 'name': 'Delivery order for procurement', - 'partner_id': self.ref('base.res_partner_2'), + 'partner_id': self.partner.id, 'picking_type_id': self.ref('stock.picking_type_out'), 'location_id': self.ref('stock.stock_location_output'), 'location_dest_id': self.ref('stock.stock_location_customers'), @@ -60,7 +70,7 @@ class TestProcRule(TransactionCase): # Check that a picking was created from stock to output. moves = self.env['stock.move'].search([ - ('product_id', '=', self.ref('product.product_product_3')), + ('product_id', '=', self.product.id), ('location_id', '=', self.ref('stock.stock_location_stock')), ('location_dest_id', '=', self.ref('stock.stock_location_output')), ('move_dest_ids', 'in', [pick_output.move_lines[0].id]) @@ -70,16 +80,16 @@ class TestProcRule(TransactionCase): def test_rule_propagate_1(self): move_dest = self.env['stock.move'].create({ 'name': 'move_dest', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'location_id': self.ref('stock.stock_location_output'), 'location_dest_id': self.ref('stock.stock_location_customers'), }) move_orig = self.env['stock.move'].create({ 'name': 'move_orig', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'move_dest_ids': [(4, move_dest.id)], 'propagate_date': True, 'propagate_date_minimum_delta': 5, @@ -102,16 +112,16 @@ class TestProcRule(TransactionCase): def test_rule_propagate_2(self): move_dest = self.env['stock.move'].create({ 'name': 'move_dest', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'location_id': self.ref('stock.stock_location_output'), 'location_dest_id': self.ref('stock.stock_location_customers'), }) move_orig = self.env['stock.move'].create({ 'name': 'move_orig', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'move_dest_ids': [(4, move_dest.id)], 'propagate_date': False, 'propagate_date_minimum_delta': 5, @@ -132,16 +142,16 @@ class TestProcRule(TransactionCase): def test_rule_propagate_3(self): move_dest = self.env['stock.move'].create({ 'name': 'move_dest', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'location_id': self.ref('stock.stock_location_output'), 'location_dest_id': self.ref('stock.stock_location_customers'), }) move_orig = self.env['stock.move'].create({ 'name': 'move_orig', - 'product_id': self.ref('product.product_product_3'), - 'product_uom': self.ref('uom.product_uom_unit'), + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, 'move_dest_ids': [(4, move_dest.id)], 'propagate_date': True, 'propagate_date_minimum_delta': 5, From 5262be0a43fec44efe4c10d9e687eedd331cb977 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 06:15:48 +0000 Subject: [PATCH 05/11] [IMP] stock: pass tests without demo data for file test_quant_inventory_mode. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_quant_inventory_mode.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/stock/tests/test_quant_inventory_mode.py b/addons/stock/tests/test_quant_inventory_mode.py index 6076b8e0964..3cca7ba49e0 100644 --- a/addons/stock/tests/test_quant_inventory_mode.py +++ b/addons/stock/tests/test_quant_inventory_mode.py @@ -197,7 +197,13 @@ class TestEditableQuant(SavepointCase): """ Try to edit a record without the inventory mode. Must raise an error. """ - user_demo = self.env.ref('base.user_demo') + self.demo_user = self.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True}).create({ + 'name': 'Pauline Poivraisselle', + 'login': 'pauline', + 'email': 'p.p@example.com', + 'notification_type': 'inbox', + 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])] + }) user_admin = self.env.ref('base.user_admin') quant = self.Quant.create({ 'product_id': self.product.id, @@ -207,7 +213,7 @@ class TestEditableQuant(SavepointCase): self.assertEqual(quant.quantity, 12) # Try to write on quant without permission with self.assertRaises(AccessError): - quant.with_user(user_demo).write({'inventory_quantity': 8}) + quant.with_user(self.demo_user).write({'inventory_quantity': 8}) self.assertEqual(quant.quantity, 12) # Try to write on quant with permission From a90fe83dbaacafddabc444ce61debf60a419a4f1 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 06:30:30 +0000 Subject: [PATCH 06/11] [IMP] stock: pass tests without demo data for file test_stock_flow. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_stock_flow.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 0fe521d992c..2b7fb864678 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -6,6 +6,17 @@ from odoo.tools import mute_logger, float_round from odoo.exceptions import UserError class TestStockFlow(TestStockCommon): + def setUp(cls): + super(TestStockFlow, cls).setUp() + cls.partner_company2 = cls.env['res.partner'].create({ + 'name': 'My Company (Chicago)-demo', + 'email': 'chicago@yourcompany.com', + }) + cls.company = cls.env['res.company'].create({ + 'currency_id': cls.env.ref('base.USD').id, + 'partner_id': cls.partner_company2.id, + 'name': 'My Company (Chicago)-demo', + }) @mute_logger('odoo.addons.base.models.ir_model', 'odoo.models') def test_00_picking_create_and_transfer_quantity(self): @@ -1806,7 +1817,7 @@ class TestStockFlow(TestStockCommon): self.env.user.write({'groups_id': [(4, grp_multi_routes.id)]}) self.env.user.write({'groups_id': [(4, grp_multi_companies.id)]}) - company_2 = self.env.ref('stock.res_company_1') + company_2 = self.company # Need to add a new company on user. self.env.user.write({'company_ids': [(4, company_2.id)]}) @@ -1870,7 +1881,7 @@ class TestStockFlow(TestStockCommon): self.env.user.write({'groups_id': [(4, grp_multi_routes.id)]}) self.env.user.write({'groups_id': [(4, grp_multi_companies.id)]}) - company_2 = self.env.ref('stock.res_company_1') + company_2 = self.company # Need to add a new company on user. self.env.user.write({'company_ids': [(4, company_2.id)]}) From 7c70fbe5b8411394704c5c78f3f6c8fdc384d63f Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 06:35:54 +0000 Subject: [PATCH 07/11] [IMP] stock: pass tests without demo data for file test_stock_location_search. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_stock_location_search.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/stock/tests/test_stock_location_search.py b/addons/stock/tests/test_stock_location_search.py index d19cfa8d775..ac83eebdfdc 100644 --- a/addons/stock/tests/test_stock_location_search.py +++ b/addons/stock/tests/test_stock_location_search.py @@ -7,10 +7,15 @@ class TestStockLocationSearch(common.TransactionCase): def setUp(self): super(TestStockLocationSearch, self).setUp() self.location = self.env['stock.location'] - self.location_barcode = self.env.ref('stock.stock_location_14') - self.location_barcode_id = self.location_barcode.id - self.barcode = self.location_barcode.barcode - self.name = self.location_barcode.name + self.stock_location = self.env.ref('stock.stock_location_stock') + self.sublocation = self.env['stock.location'].create({ + 'name': 'Shelf 2', + 'barcode': 1201985, + 'location_id': self.stock_location.id + }) + self.location_barcode_id = self.sublocation.id + self.barcode = self.sublocation.barcode + self.name = self.sublocation.name def test_10_location_search_by_barcode(self): """Search stock location by barcode""" From 0dff7da0b45a5f49941b88be38267483a49ec8e2 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 06:45:46 +0000 Subject: [PATCH 08/11] [IMP] stock: pass tests without demo data for file test_warehouse. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_warehouse.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index 413f3d45d4c..8867f098761 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -6,6 +6,11 @@ from odoo.exceptions import AccessError class TestWarehouse(TestStockCommon): + + def setUp(self): + super(TestWarehouse, self).setUp() + self.partner = self.env['res.partner'].create({'name': 'Deco Addict'}) + def test_inventory_product(self): self.product_1.type = 'product' product_1_quant = self.env['stock.quant'].with_context(inventory_mode=True).create({ @@ -90,7 +95,7 @@ class TestWarehouse(TestStockCommon): product = self.product_3.with_user(self.user_stock_manager) product.type = 'product' picking_out = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': self.warehouse_1.lot_stock_id.id, 'location_dest_id': self.env.ref('stock.stock_location_customers').id, @@ -151,7 +156,7 @@ class TestWarehouse(TestStockCommon): # Create a picking out and force availability picking_out = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': stock_location.id, 'location_dest_id': customer_location.id, @@ -194,7 +199,7 @@ class TestWarehouse(TestStockCommon): # Create a picking out and force availability picking_out = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': stock_location.id, 'location_dest_id': customer_location.id, @@ -279,7 +284,7 @@ class TestWarehouse(TestStockCommon): }) picking_out = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': warehouse_shop.lot_stock_id.id, 'location_dest_id': self.env.ref('stock.stock_location_customers').id, @@ -359,7 +364,7 @@ class TestWarehouse(TestStockCommon): # Create the move for the shop Namur. Should create a resupply from # distribution warehouse Namur. picking_out_namur = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': warehouse_shop_namur.lot_stock_id.id, 'location_dest_id': customer_location.id, @@ -403,7 +408,7 @@ class TestWarehouse(TestStockCommon): # Create the move for the shop Wavre. Should create a resupply from # distribution warehouse Wavre. picking_out_wavre = self.env['stock.picking'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_id': self.partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': warehouse_shop_wavre.lot_stock_id.id, 'location_dest_id': customer_location.id, From e7e7284b866d01adfd95b05dadd89da68132f035 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Wed, 19 Jun 2019 07:17:40 +0000 Subject: [PATCH 09/11] [IMP] stock: pass tests without demo data for file test_wise_operator. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_wise_operator.py | 38 +++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/addons/stock/tests/test_wise_operator.py b/addons/stock/tests/test_wise_operator.py index 79e638b2768..168c3b49098 100644 --- a/addons/stock/tests/test_wise_operator.py +++ b/addons/stock/tests/test_wise_operator.py @@ -17,10 +17,26 @@ class TestWiseOperator(TransactionCase): 'uom_po_id': self.ref('uom.product_uom_unit'), }) + self.partner = self.env['res.partner'].create({'name': 'Deco Addict'}) + + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + self.shelf2 = self.env['stock.location'].create({ + 'name': 'Shelf 2', + 'barcode': 1231985, + 'location_id': warehouse.lot_stock_id.id + }) + self.shelf1 = self.env['stock.location'].create({ + 'name': 'Shelf 1', + 'barcode': 1231892, + 'location_id': warehouse.lot_stock_id.id + }) + + self.partner2 = self.env['res.partner'].create({'name': 'Ready Mat'}) + # Create an incoming picking for this product of 10 PCE from suppliers to stock vals = { 'name': 'Incoming picking (wise unit)', - 'partner_id': self.ref('base.res_partner_2'), + 'partner_id': self.partner.id, 'picking_type_id': self.ref('stock.picking_type_in'), 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), @@ -46,7 +62,7 @@ class TestWiseOperator(TransactionCase): pick1_wise.move_line_ids[0].write({ 'result_package_id': package1.id, 'qty_done': 4, - 'location_dest_id': self.ref('stock.stock_location_components') + 'location_dest_id': self.shelf1.id }) new_pack1 = self.env['stock.move.line'].create({ 'product_id': product_wise.id, @@ -54,7 +70,7 @@ class TestWiseOperator(TransactionCase): 'picking_id': pick1_wise.id, 'qty_done': 6.0, 'location_id': self.ref('stock.stock_location_suppliers'), - 'location_dest_id': self.ref('stock.stock_location_14') + 'location_dest_id': self.shelf2.id }) # Transfer the receipt @@ -67,7 +83,7 @@ class TestWiseOperator(TransactionCase): # Make a delivery order of 5 pieces to the customer vals = { 'name': 'outgoing picking 1 (wise unit)', - 'partner_id': self.ref('base.res_partner_4'), + 'partner_id': self.partner2.id, 'picking_type_id': self.ref('stock.picking_type_out'), 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), @@ -92,7 +108,7 @@ class TestWiseOperator(TransactionCase): # Make a delivery order of 5 pieces to the customer vals = { 'name': 'outgoing picking 2 (wise unit)', - 'partner_id': self.ref('base.res_partner_4'), + 'partner_id': self.partner2.id, 'picking_type_id': self.ref('stock.picking_type_out'), 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), @@ -121,10 +137,10 @@ class TestWiseOperator(TransactionCase): pack_ids1 = delivery_order_wise1.move_line_ids pack_ids2 = delivery_order_wise2.move_line_ids - self.assertEqual(pack_ids1.location_id.id, self.ref('stock.stock_location_14')) + self.assertEqual(pack_ids1.location_id.id, self.shelf2.id) self.assertEqual(set(pack_ids2.mapped('location_id.id')), set([ - self.ref('stock.stock_location_components'), - self.ref('stock.stock_location_14')])) + self.shelf1.id, + self.shelf2.id])) # put the move lines from delivery_order_wise2 into delivery_order_wise1 for pack_id2 in pack_ids2: @@ -136,8 +152,8 @@ class TestWiseOperator(TransactionCase): self.assertEqual(sum(new_move_lines.mapped('product_qty')), 0) self.assertEqual(sum(new_move_lines.mapped('qty_done')), 5) self.assertEqual(set(new_move_lines.mapped('location_id.id')), set([ - self.ref('stock.stock_location_components'), - self.ref('stock.stock_location_14')])) + self.shelf1.id, + self.shelf2.id])) # put the move line from delivery_order_wise1 into delivery_order_wise2 new_pack_id2 = pack_ids1.copy(default={'picking_id': delivery_order_wise2.id, 'move_id': move2.id}) @@ -148,7 +164,7 @@ class TestWiseOperator(TransactionCase): self.assertEqual(len(new_move_lines), 1) self.assertEqual(sum(new_move_lines.mapped('product_qty')), 0) self.assertEqual(sum(new_move_lines.mapped('qty_done')), 5) - self.assertEqual(new_move_lines.location_id.id, self.ref('stock.stock_location_14')) + self.assertEqual(new_move_lines.location_id.id, self.shelf2.id) # Process this picking delivery_order_wise1.action_done() From 9bf453acb8803373b193be994073d06819aa9476 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Thu, 20 Jun 2019 05:54:22 +0000 Subject: [PATCH 10/11] [IMP] stock: pass tests without demo data for file test_quant. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_quant.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index 26a0bd68e10..211ae4e1f80 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -47,7 +47,15 @@ class StockQuant(SavepointCase): 'type': 'product', 'tracking': 'serial', }) - cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.stock_location = cls.env['stock.location'].create({ + 'name': 'stock_location', + 'usage': 'internal', + }) + cls.stock_subloc2 = cls.env['stock.location'].create({ + 'name': 'subloc2', + 'usage': 'internal', + 'location_id': cls.stock_location.id, + }) def gather_relevant(self, product_id, location_id, lot_id=None, package_id=None, owner_id=None, strict=False): quants = self.env['stock.quant']._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) @@ -163,7 +171,7 @@ class StockQuant(SavepointCase): 'location_id': self.stock_location.id, 'quantity': 1.0, }) - self.env = self.env(user=self.env.ref('base.user_demo')) + self.env = self.env(user=self.demo_user) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_increase_available_quantity_1(self): @@ -191,6 +199,8 @@ class StockQuant(SavepointCase): the reserved quanntity for the same product. """ quant = self.env['stock.quant'].search([('location_id', '=', self.stock_location.id)], limit=1) + if not quant: + self.skipTest('Cannot test concurrent transactions without demo data.') product = quant.product_id available_quantity = self.env['stock.quant']._get_available_quantity(product, self.stock_location) # opens a new cursor and SELECT FOR UPDATE the quant, to simulate another concurrent reserved @@ -207,7 +217,7 @@ class StockQuant(SavepointCase): def test_increase_available_quantity_4(self): """ Increase the available quantity when no quants are already in a location with a user without access right. """ - self.env = self.env(user=self.env.ref('base.user_demo')) + self.env = self.env(user=self.demo_user) self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) def test_increase_available_quantity_5(self): @@ -246,6 +256,7 @@ class StockQuant(SavepointCase): """ Setting a location's usage as "view" should be forbidden if it already contains quant. """ + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) self.assertTrue(len(self.stock_location.quant_ids.ids) > 0) with self.assertRaises(UserError): self.stock_location.usage = 'view' @@ -277,6 +288,8 @@ class StockQuant(SavepointCase): the reserved quanntity for the same product. """ quant = self.env['stock.quant'].search([('location_id', '=', self.stock_location.id)], limit=1) + if not quant: + self.skipTest('Cannot test concurrent transactions without demo data.') product = quant.product_id available_quantity = self.env['stock.quant']._get_available_quantity(product, self.stock_location) @@ -579,8 +592,14 @@ class StockQuant(SavepointCase): def test_in_date_4b(self): """ Check for LIFO and max with/without in_date that it handles the LIFO NULLS LAST well """ - stock_location1 = self.env.ref('stock.stock_location_components') - stock_location2 = self.env.ref('stock.stock_location_14') + stock_location1 = self.env['stock.location'].create({ + 'name': 'Shelf 1', + 'location_id': self.stock_location.id + }) + stock_location2 = self.env['stock.location'].create({ + 'name': 'Shelf 2', + 'location_id': self.stock_location.id + }) lifo_strategy = self.env['product.removal'].search([('method', '=', 'lifo')]) self.stock_location.removal_strategy_id = lifo_strategy From 49fb56a8d39cb745c8d9fc59958562e55b685b35 Mon Sep 17 00:00:00 2001 From: Hetashree Chauhan Date: Mon, 8 Jul 2019 10:07:37 +0000 Subject: [PATCH 11/11] [IMP] stock: pass tests without demo data for file test_inventory. pass all test cases without any demo data. If a user has not installed any demo data, then also test cases must not be break. task-2024202 closes : https://github.com/odoo/odoo/pull/34258 --- addons/stock/tests/test_inventory.py | 7 +++++++ addons/stock/tests/test_quant_inventory_mode.py | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/stock/tests/test_inventory.py b/addons/stock/tests/test_inventory.py index f06e9f033ef..f93e388f09b 100644 --- a/addons/stock/tests/test_inventory.py +++ b/addons/stock/tests/test_inventory.py @@ -315,6 +315,13 @@ class TestInventory(SavepointCase): """ Check inventory lines product quantity is 0 when inventory is started with `prefill_counted_quantity` disable. """ + self.env['stock.quant'].create({ + 'product_id': self.product1.id, + 'product_uom_id': self.uom_unit.id, + 'location_id': self.stock_location.id, + 'quantity': 7, + 'reserved_quantity': 0, + }) inventory_form = Form(self.env['stock.inventory'].with_context( default_prefill_counted_quantity=False, ), view='stock.view_inventory_form') diff --git a/addons/stock/tests/test_quant_inventory_mode.py b/addons/stock/tests/test_quant_inventory_mode.py index 3cca7ba49e0..a189499a967 100644 --- a/addons/stock/tests/test_quant_inventory_mode.py +++ b/addons/stock/tests/test_quant_inventory_mode.py @@ -201,7 +201,6 @@ class TestEditableQuant(SavepointCase): 'name': 'Pauline Poivraisselle', 'login': 'pauline', 'email': 'p.p@example.com', - 'notification_type': 'inbox', 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])] }) user_admin = self.env.ref('base.user_admin')