diff --git a/addons/sale_stock/tests/test_create_perf.py b/addons/sale_stock/tests/test_create_perf.py index 2f9394b25a8..e0700c822ca 100644 --- a/addons/sale_stock/tests/test_create_perf.py +++ b/addons/sale_stock/tests/test_create_perf.py @@ -6,9 +6,10 @@ import logging import random import time +from odoo.addons.base.tests.common import TransactionCaseWithUserDemo from odoo.fields import Command -from odoo.tests import common, tagged +from odoo.tests import tagged from odoo.tests.common import users, warmup _logger = logging.getLogger(__name__) @@ -25,7 +26,7 @@ def prepare(func, self): @tagged('so_batch_perf') -class TestPERF(common.TransactionCase): +class TestPERF(TransactionCaseWithUserDemo): @classmethod def setUpClass(cls): @@ -42,7 +43,7 @@ class TestPERF(common.TransactionCase): 'name': 'Partner %s' % i, } for i in range(cls.ENTITIES)]) - cls.salesmans = cls.env.ref('base.user_admin') | cls.env.ref('base.user_demo') + cls.salesmans = cls.env.ref('base.user_admin') | cls.user_demo cls.env.flush_all() diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index acabea8f517..6b9bba16b29 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -710,7 +710,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): self.assertEqual(sale_order.order_line.qty_delivered, 0) picking = sale_order.picking_ids initial_product = sale_order.order_line.product_id - + picking.picking_type_id.show_operations = True # Could be false without demo data, as the lot group is disabled picking_form = Form(picking) with picking_form.move_ids_without_package.edit(0) as move: move.quantity = 5 @@ -801,7 +801,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): self.assertEqual(sale_order.order_line.qty_delivered, 0) pick = sale_order.picking_ids.filtered(lambda p: p.picking_type_code == 'internal') delivery = sale_order.picking_ids.filtered(lambda p: p.picking_type_code == 'outgoing') - + pick.picking_type_id.show_operations = True # Could be false without demo data, as the lot group is disabled picking_form = Form(pick) with picking_form.move_ids_without_package.edit(0) as move: move.quantity = 10 @@ -809,6 +809,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): pick.move_ids.picked = True pick.button_validate() + delivery.picking_type_id.show_operations = True # Could be false without demo data, as the lot group is disabled picking_form = Form(delivery) with picking_form.move_ids_without_package.edit(0) as move: move.quantity = 10 @@ -1054,7 +1055,8 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): 'factor_inv': 0.9144, 'uom_type': 'bigger', }) - product = self.env.ref('product.product_product_11').copy({ + product = self.env['product.product'].create({ + 'name': 'Test Product', 'uom_id': self.env.ref('uom.product_uom_meter').id, 'uom_po_id': yards_uom.id, }) diff --git a/addons/sale_stock/tests/test_sale_stock_report.py b/addons/sale_stock/tests/test_sale_stock_report.py index 2b013f30d0a..63cb6296cb0 100644 --- a/addons/sale_stock/tests/test_sale_stock_report.py +++ b/addons/sale_stock/tests/test_sale_stock_report.py @@ -91,7 +91,7 @@ class TestSaleStockInvoices(TestSaleCommon): def setUp(self): super(TestSaleStockInvoices, self).setUp() - + self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('stock.group_production_lot').id)]}) self.product_by_lot = self.env['product.product'].create({ 'name': 'Product By Lot', 'type': 'product', diff --git a/addons/stock/tests/common.py b/addons/stock/tests/common.py index 49aca34b7a6..103d044bd74 100644 --- a/addons/stock/tests/common.py +++ b/addons/stock/tests/common.py @@ -18,6 +18,7 @@ class TestStockCommon(common.TransactionCase): cls.PickingObj = cls.env['stock.picking'] cls.MoveObj = cls.env['stock.move'] cls.LotObj = cls.env['stock.lot'] + cls.StockLocationObj = cls.env['stock.location'] # Model Data cls.picking_type_in = cls.ModelDataObj._xmlid_to_res_id('stock.picking_type_in') @@ -25,6 +26,15 @@ class TestStockCommon(common.TransactionCase): cls.env['stock.picking.type'].browse(cls.picking_type_out).reservation_method = 'manual' cls.supplier_location = cls.ModelDataObj._xmlid_to_res_id('stock.stock_location_suppliers') cls.stock_location = cls.ModelDataObj._xmlid_to_res_id('stock.stock_location_stock') + location = cls.StockLocationObj.browse(cls.stock_location) + if not location.child_ids: + cls.StockLocationObj.create([{ + 'name': 'Shelf 1', + 'location_id': location.id, + }, { + 'name': 'Shelf 2', + 'location_id': location.id, + }]) pack_location = cls.env.ref('stock.location_pack_zone') pack_location.active = True cls.pack_location = pack_location.id @@ -97,6 +107,11 @@ class TestStockCommon(common.TransactionCase): cls.kgB = cls.ProductObj.create({'name': 'kg-B', 'type': 'product', 'uom_id': cls.uom_kg.id, 'uom_po_id': cls.uom_kg.id}) cls.gB = cls.ProductObj.create({'name': 'g-B', 'type': 'product', 'uom_id': cls.uom_gm.id, 'uom_po_id': cls.uom_gm.id}) + cls.env.ref('base.group_user').write({'implied_ids': [ + (4, cls.env.ref('base.group_multi_company').id), + (4, cls.env.ref('stock.group_production_lot').id), + ]}) + def url_extract_rec_id_and_model(self, url): rec_id = re.findall(r'[?&]id=([^&]+).*', url) model_name = re.findall(r'[?&]model=([^&]+).*', url) diff --git a/addons/stock/tests/test_generate_serial_numbers.py b/addons/stock/tests/test_generate_serial_numbers.py index 985cdf222ab..385cbfba62f 100644 --- a/addons/stock/tests/test_generate_serial_numbers.py +++ b/addons/stock/tests/test_generate_serial_numbers.py @@ -10,6 +10,7 @@ class StockGenerateCommon(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() + cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]}) Product = cls.env['product.product'] cls.product_serial = Product.create({ 'name': 'Tracked by SN', diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index ebc8fd348ed..86727cb656d 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -12,8 +12,20 @@ class StockMove(TransactionCase): def setUpClass(cls): super(StockMove, cls).setUpClass() group_stock_multi_locations = cls.env.ref('stock.group_stock_multi_locations') - cls.env.user.write({'groups_id': [(4, group_stock_multi_locations.id, 0)]}) + group_production_lot = cls.env.ref('stock.group_production_lot') + cls.env.user.write({'groups_id': [ + (4, group_stock_multi_locations.id), + (4, group_production_lot.id) + ]}) cls.stock_location = cls.env.ref('stock.stock_location_stock') + if not cls.stock_location.child_ids: + cls.stock_location.create([{ + 'name': 'Shelf 1', + 'location_id': cls.stock_location.id, + }, { + 'name': 'Shelf 2', + 'location_id': cls.stock_location.id, + }]) cls.customer_location = cls.env.ref('stock.stock_location_customers') cls.supplier_location = cls.env.ref('stock.stock_location_suppliers') cls.pack_location = cls.env.ref('stock.location_pack_zone') diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index 4c575ae0e01..5156f30a81f 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -799,6 +799,7 @@ class StockQuant(TransactionCase): def test_quant_display_name(self): """ Check the display name of a quant. """ + self.env.user.groups_id += self.env.ref('stock.group_production_lot') sn1 = self.env['stock.lot'].create({ 'name': 'sn1', 'product_id': self.product_serial.id, diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 448c7a744ac..9f57f611148 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -11,6 +11,7 @@ class TestStockFlow(TestStockCommon): @classmethod def setUpClass(cls): super().setUpClass() + cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]}) decimal_product_uom = cls.env.ref('product.decimal_product_uom') decimal_product_uom.digits = 3 cls.partner_company2 = cls.env['res.partner'].create({ diff --git a/addons/stock_account/tests/test_stockvaluationlayer.py b/addons/stock_account/tests/test_stockvaluationlayer.py index 2c68e564f88..07de2016893 100644 --- a/addons/stock_account/tests/test_stockvaluationlayer.py +++ b/addons/stock_account/tests/test_stockvaluationlayer.py @@ -923,6 +923,7 @@ class TestStockValuationChangeCostMethod(TestStockValuationCommon): self.assertEqual(self.product1.quantity_svl, 19) +@tagged('post_install', '-at_install', 'change_valuation') class TestStockValuationChangeValuation(TestStockValuationCommon): @classmethod def setUpClass(cls): @@ -1020,8 +1021,13 @@ class TestStockValuationChangeValuation(TestStockValuationCommon): self.assertEqual(len(self.product1.stock_valuation_layer_ids.account_move_id), 0) self.assertEqual(len(self.product1.stock_valuation_layer_ids), 1) - self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time' - + self.product1.product_tmpl_id.categ_id.write({ + 'property_stock_account_input_categ_id': self.stock_input_account.id, + 'property_stock_account_output_categ_id': self.stock_output_account.id, + 'property_stock_valuation_account_id': self.stock_valuation_account.id, + 'property_stock_journal': self.stock_journal.id, + 'property_valuation': 'real_time', + }) self.assertEqual(self.product1.value_svl, -100) self.assertEqual(self.product1.quantity_svl, -10) # An accounting entry should only be created for the replenish now that the category is perpetual. diff --git a/addons/stock_picking_batch/tests/test_batch_picking.py b/addons/stock_picking_batch/tests/test_batch_picking.py index 0b3f9458c19..272b0de3644 100644 --- a/addons/stock_picking_batch/tests/test_batch_picking.py +++ b/addons/stock_picking_batch/tests/test_batch_picking.py @@ -668,6 +668,14 @@ class TestBatchPicking02(TransactionCase): def setUp(self): super().setUp() self.stock_location = self.env.ref('stock.stock_location_stock') + if not self.stock_location.child_ids: + self.stock_location.create([{ + 'name': 'Shelf 1', + 'location_id': self.stock_location.id, + }, { + 'name': 'Shelf 2', + 'location_id': self.stock_location.id, + }]) self.picking_type_internal = self.env.ref('stock.picking_type_internal') self.productA = self.env['product.product'].create({ 'name': 'Product A', diff --git a/addons/stock_picking_batch/tests/test_wave_picking.py b/addons/stock_picking_batch/tests/test_wave_picking.py index 99c37181d87..4582a179f37 100644 --- a/addons/stock_picking_batch/tests/test_wave_picking.py +++ b/addons/stock_picking_batch/tests/test_wave_picking.py @@ -387,9 +387,8 @@ class TestBatchPicking(TransactionCase): wizard.attach_pickings() with self.assertRaises(UserError): - companies = self.env['res.company'].search([]) - self.picking_client_1.company_id = companies[0] - self.picking_client_2.company_id = companies[1] + self.picking_client_1.company_id = self.env.company + self.picking_client_2.company_id = self.env['res.company'].create({'name': 'Company 2'}) lines = (self.picking_client_1 | self.picking_client_2).move_line_ids res_dict = lines.action_open_add_to_wave() res_dict['context'] = {'active_model': 'stock.move.line', 'active_ids': lines.ids}