[FIX] stock: Make tests demo data independent

Part-of: odoo/odoo#146649
This commit is contained in:
Yannick Tivisse
2023-12-18 23:32:05 +00:00
parent 1d094d70f4
commit efb722c2af
11 changed files with 59 additions and 13 deletions
+4 -3
View File
@@ -6,9 +6,10 @@ import logging
import random import random
import time import time
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
from odoo.fields import Command from odoo.fields import Command
from odoo.tests import common, tagged from odoo.tests import tagged
from odoo.tests.common import users, warmup from odoo.tests.common import users, warmup
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@@ -25,7 +26,7 @@ def prepare(func, self):
@tagged('so_batch_perf') @tagged('so_batch_perf')
class TestPERF(common.TransactionCase): class TestPERF(TransactionCaseWithUserDemo):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
@@ -42,7 +43,7 @@ class TestPERF(common.TransactionCase):
'name': 'Partner %s' % i, 'name': 'Partner %s' % i,
} for i in range(cls.ENTITIES)]) } 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() cls.env.flush_all()
+5 -3
View File
@@ -710,7 +710,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
self.assertEqual(sale_order.order_line.qty_delivered, 0) self.assertEqual(sale_order.order_line.qty_delivered, 0)
picking = sale_order.picking_ids picking = sale_order.picking_ids
initial_product = sale_order.order_line.product_id 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) picking_form = Form(picking)
with picking_form.move_ids_without_package.edit(0) as move: with picking_form.move_ids_without_package.edit(0) as move:
move.quantity = 5 move.quantity = 5
@@ -801,7 +801,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
self.assertEqual(sale_order.order_line.qty_delivered, 0) self.assertEqual(sale_order.order_line.qty_delivered, 0)
pick = sale_order.picking_ids.filtered(lambda p: p.picking_type_code == 'internal') 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') 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) picking_form = Form(pick)
with picking_form.move_ids_without_package.edit(0) as move: with picking_form.move_ids_without_package.edit(0) as move:
move.quantity = 10 move.quantity = 10
@@ -809,6 +809,7 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
pick.move_ids.picked = True pick.move_ids.picked = True
pick.button_validate() 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) picking_form = Form(delivery)
with picking_form.move_ids_without_package.edit(0) as move: with picking_form.move_ids_without_package.edit(0) as move:
move.quantity = 10 move.quantity = 10
@@ -1054,7 +1055,8 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
'factor_inv': 0.9144, 'factor_inv': 0.9144,
'uom_type': 'bigger', '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_id': self.env.ref('uom.product_uom_meter').id,
'uom_po_id': yards_uom.id, 'uom_po_id': yards_uom.id,
}) })
@@ -91,7 +91,7 @@ class TestSaleStockInvoices(TestSaleCommon):
def setUp(self): def setUp(self):
super(TestSaleStockInvoices, self).setUp() 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({ self.product_by_lot = self.env['product.product'].create({
'name': 'Product By Lot', 'name': 'Product By Lot',
'type': 'product', 'type': 'product',
+15
View File
@@ -18,6 +18,7 @@ class TestStockCommon(common.TransactionCase):
cls.PickingObj = cls.env['stock.picking'] cls.PickingObj = cls.env['stock.picking']
cls.MoveObj = cls.env['stock.move'] cls.MoveObj = cls.env['stock.move']
cls.LotObj = cls.env['stock.lot'] cls.LotObj = cls.env['stock.lot']
cls.StockLocationObj = cls.env['stock.location']
# Model Data # Model Data
cls.picking_type_in = cls.ModelDataObj._xmlid_to_res_id('stock.picking_type_in') 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.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.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') 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 = cls.env.ref('stock.location_pack_zone')
pack_location.active = True pack_location.active = True
cls.pack_location = pack_location.id 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.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.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): def url_extract_rec_id_and_model(self, url):
rec_id = re.findall(r'[?&]id=([^&]+).*', url) rec_id = re.findall(r'[?&]id=([^&]+).*', url)
model_name = re.findall(r'[?&]model=([^&]+).*', url) model_name = re.findall(r'[?&]model=([^&]+).*', url)
@@ -10,6 +10,7 @@ class StockGenerateCommon(TransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() 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'] Product = cls.env['product.product']
cls.product_serial = Product.create({ cls.product_serial = Product.create({
'name': 'Tracked by SN', 'name': 'Tracked by SN',
+13 -1
View File
@@ -12,8 +12,20 @@ class StockMove(TransactionCase):
def setUpClass(cls): def setUpClass(cls):
super(StockMove, cls).setUpClass() super(StockMove, cls).setUpClass()
group_stock_multi_locations = cls.env.ref('stock.group_stock_multi_locations') 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') 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.customer_location = cls.env.ref('stock.stock_location_customers')
cls.supplier_location = cls.env.ref('stock.stock_location_suppliers') cls.supplier_location = cls.env.ref('stock.stock_location_suppliers')
cls.pack_location = cls.env.ref('stock.location_pack_zone') cls.pack_location = cls.env.ref('stock.location_pack_zone')
+1
View File
@@ -799,6 +799,7 @@ class StockQuant(TransactionCase):
def test_quant_display_name(self): def test_quant_display_name(self):
""" Check the display name of a quant. """ """ 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({ sn1 = self.env['stock.lot'].create({
'name': 'sn1', 'name': 'sn1',
'product_id': self.product_serial.id, 'product_id': self.product_serial.id,
+1
View File
@@ -11,6 +11,7 @@ class TestStockFlow(TestStockCommon):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() 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 = cls.env.ref('product.decimal_product_uom')
decimal_product_uom.digits = 3 decimal_product_uom.digits = 3
cls.partner_company2 = cls.env['res.partner'].create({ cls.partner_company2 = cls.env['res.partner'].create({
@@ -923,6 +923,7 @@ class TestStockValuationChangeCostMethod(TestStockValuationCommon):
self.assertEqual(self.product1.quantity_svl, 19) self.assertEqual(self.product1.quantity_svl, 19)
@tagged('post_install', '-at_install', 'change_valuation')
class TestStockValuationChangeValuation(TestStockValuationCommon): class TestStockValuationChangeValuation(TestStockValuationCommon):
@classmethod @classmethod
def setUpClass(cls): 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.account_move_id), 0)
self.assertEqual(len(self.product1.stock_valuation_layer_ids), 1) 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.value_svl, -100)
self.assertEqual(self.product1.quantity_svl, -10) self.assertEqual(self.product1.quantity_svl, -10)
# An accounting entry should only be created for the replenish now that the category is perpetual. # An accounting entry should only be created for the replenish now that the category is perpetual.
@@ -668,6 +668,14 @@ class TestBatchPicking02(TransactionCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.stock_location = self.env.ref('stock.stock_location_stock') 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.picking_type_internal = self.env.ref('stock.picking_type_internal')
self.productA = self.env['product.product'].create({ self.productA = self.env['product.product'].create({
'name': 'Product A', 'name': 'Product A',
@@ -387,9 +387,8 @@ class TestBatchPicking(TransactionCase):
wizard.attach_pickings() wizard.attach_pickings()
with self.assertRaises(UserError): with self.assertRaises(UserError):
companies = self.env['res.company'].search([]) self.picking_client_1.company_id = self.env.company
self.picking_client_1.company_id = companies[0] self.picking_client_2.company_id = self.env['res.company'].create({'name': 'Company 2'})
self.picking_client_2.company_id = companies[1]
lines = (self.picking_client_1 | self.picking_client_2).move_line_ids lines = (self.picking_client_1 | self.picking_client_2).move_line_ids
res_dict = lines.action_open_add_to_wave() res_dict = lines.action_open_add_to_wave()
res_dict['context'] = {'active_model': 'stock.move.line', 'active_ids': lines.ids} res_dict['context'] = {'active_model': 'stock.move.line', 'active_ids': lines.ids}