[FIX] mrp: 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 45db144ffe
commit be58bb0586
18 changed files with 179 additions and 17 deletions
+1
View File
@@ -12,6 +12,7 @@ class TestMrpProductionBackorder(TestMrpCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
cls.stock_location = cls.env.ref('stock.stock_location_stock')
warehouse_form = Form(cls.env['stock.warehouse'])
warehouse_form.name = 'Test Warehouse'
+8
View File
@@ -12,6 +12,14 @@ from freezegun import freeze_time
@freeze_time(fields.Date.today())
class TestBoM(TestMrpCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [
(4, cls.env.ref('product.group_product_variant').id),
(4, cls.env.ref('mrp.group_mrp_routings').id),
]})
def test_01_explode(self):
boms, lines = self.bom_1.explode(self.product_4, 3)
self.assertEqual(set([bom[0].id for bom in boms]), set(self.bom_1.ids))
@@ -136,6 +136,7 @@ class TestManualConsumption(TestMrpCommon):
def setUpClass(cls):
super().setUpClass()
cls.stock_location = cls.env.ref('stock.stock_location_stock')
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
def test_manual_consumption_backorder_00(self):
"""Test when use_auto_consume_components_lots is not set, manual consumption
+1
View File
@@ -10,6 +10,7 @@ class TestMrpMulticompany(common.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)]})
group_user = cls.env.ref('base.group_user')
group_mrp_manager = cls.env.ref('mrp.group_mrp_manager')
+20 -1
View File
@@ -11,8 +11,14 @@ from odoo.tools.misc import format_date
from odoo.addons.mrp.tests.common import TestMrpCommon
class TestMrpOrder(TestMrpCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
def test_access_rights_manager(self):
""" Checks an MRP manager can create, confirm and cancel a manufacturing order. """
man_order_form = Form(self.env['mrp.production'].with_user(self.user_mrp_manager))
@@ -2241,9 +2247,21 @@ class TestMrpOrder(TestMrpCommon):
def test_products_with_variants(self):
"""Check for product with different variants with same bom"""
attribute = self.env['product.attribute'].create({
'name': 'Test Attribute',
})
attribute_values = self.env['product.attribute.value'].create([{
'name': 'Value 1',
'attribute_id': attribute.id,
'sequence': 1,
}, {
'name': 'Value 2',
'attribute_id': attribute.id,
'sequence': 2,
}])
product = self.env['product.template'].create({
"attribute_line_ids": [
[0, 0, {"attribute_id": 2, "value_ids": [[6, 0, [3, 4]]]}]
[0, 0, {"attribute_id": attribute.id, "value_ids": [[6, 0, attribute_values.ids]]}]
],
"name": "Product with variants",
})
@@ -3111,6 +3129,7 @@ class TestMrpOrder(TestMrpCommon):
def test_planning_cancelled_workorder(self):
"""Test when plan start time for workorders, cancelled workorders won't be taken into account.
"""
self.env.company.resource_calendar_id.tz = 'Europe/Brussels'
workcenter_1 = self.env['mrp.workcenter'].create({
'name': 'wc1',
'default_capacity': 1,
+1
View File
@@ -121,6 +121,7 @@ class TestMrpStockReports(TestReportsCommon):
mo_1 = mo_form.save()
mo_1.action_confirm()
pick = mo_1.move_raw_ids.move_orig_ids.picking_id
pick.picking_type_id.show_operations = True # Could be false without demo data, as the lot group is disabled
pick_form = Form(pick)
with Form(pick.move_ids_without_package, view='stock.view_stock_move_operations') as form:
with form.move_line_ids.edit(0) as move_line:
+5
View File
@@ -14,6 +14,11 @@ _logger = logging.getLogger(__name__)
class TestTraceability(TestMrpCommon):
TRACKING_TYPES = ['none', 'serial', 'lot']
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
def _create_product(self, tracking):
return self.env['product.product'].create({
'name': 'Product %s' % tracking,
@@ -21,6 +21,8 @@ class TestBomPriceCommon(common.TransactionCase):
super().setUpClass()
# Required for `product_uom_id ` to be visible in the view
cls.env.user.groups_id += cls.env.ref('uom.group_uom')
# Required for `product_id ` to be visible in the view
cls.env.user.groups_id += cls.env.ref('product.group_product_variant')
cls.Product = cls.env['product.product']
cls.Bom = cls.env['mrp.bom']
@@ -7,6 +7,11 @@ from odoo.addons.mrp.tests.common import TestMrpCommon
@tagged('post_install', '-at_install')
class TestRepairTraceability(TestMrpCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
def test_tracking_repair_production(self):
"""
Test that removing a tracked component with a repair does not block the flow of using that component in another
+1 -1
View File
@@ -8,6 +8,7 @@ class TestMrpSubcontractingCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestMrpSubcontractingCommon, cls).setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('stock.group_production_lot').id)]})
# 1: Create a subcontracting partner
main_partner = cls.env['res.partner'].create({'name': 'main_partner'})
cls.subcontractor_partner1 = cls.env['res.partner'].create({
@@ -15,7 +16,6 @@ class TestMrpSubcontractingCommon(TransactionCase):
'parent_id': main_partner.id,
'company_id': cls.env.ref('base.main_company').id,
})
# 2. Create a BOM of subcontracting type
cls.comp1 = cls.env['product.product'].create({
'name': 'Component1',
@@ -742,6 +742,7 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon):
self.assertEqual(sum(subcontracted.mapped('qty_produced')), quantities[-1])
def test_change_reception_serial(self):
self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('stock.group_production_lot').id)]})
self.finished.tracking = 'serial'
self.bom.consumption = 'flexible'
@@ -913,6 +914,8 @@ class TestSubcontractingTracking(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)]})
# 1: Create a subcontracting partner
main_company_1 = cls.env['res.partner'].create({'name': 'main_partner'})
cls.subcontractor_partner1 = cls.env['res.partner'].create({
@@ -1301,7 +1304,7 @@ class TestSubcontractingPortal(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)]})
# 1: Create a subcontracting partner
main_partner = cls.env['res.partner'].create({'name': 'main_partner'})
cls.subcontractor_partner1 = cls.env['res.partner'].create({
@@ -1316,7 +1319,7 @@ class TestSubcontractingPortal(TransactionCase):
'login': 'subcontractor',
'password': 'subcontractor',
'email': 'subcontractor@subcontracting.portal',
'groups_id': [(6, 0, [cls.env.ref('base.group_portal').id])]
'groups_id': [(6, 0, [cls.env.ref('base.group_portal').id, cls.env.ref('stock.group_production_lot').id])]
})
# 2. Create a BOM of subcontracting type
@@ -2,13 +2,14 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import Command, fields
from odoo.tests.common import Form
from odoo.tests.common import Form, tagged
from odoo.tools.float_utils import float_round, float_compare
from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon
from odoo.addons.mrp_account.tests.test_bom_price import TestBomPriceCommon
@tagged('post_install', '-at_install')
class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon):
def test_subcontracting_account_flow_1(self):
# pylint: disable=bad-whitespace
@@ -16,9 +17,34 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon):
self.customer_location = self.env.ref('stock.stock_location_customers')
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
self.uom_unit = self.env.ref('uom.product_uom_unit')
product_category_all = self.env.ref('product.product_category_all')
product_category_all.property_cost_method = 'fifo'
product_category_all.property_valuation = 'real_time'
in_account = self.env['account.account'].create({
'name': 'IN Account',
'code': '000001',
'account_type': 'asset_current',
})
out_account = self.env['account.account'].create({
'name': 'OUT Account',
'code': '000002',
'account_type': 'asset_current',
})
valu_account = self.env['account.account'].create({
'name': 'VALU Account',
'code': '000003',
'account_type': 'asset_current',
})
production_cost_account = self.env['account.account'].create({
'name': 'PROD COST Account',
'code': '000004',
'account_type': 'asset_current',
})
product_category_all.property_stock_account_input_categ_id = in_account
product_category_all.property_stock_account_output_categ_id = out_account
product_category_all.property_stock_account_production_cost_id = production_cost_account
product_category_all.property_stock_valuation_account_id = valu_account
stock_in_acc_id = product_category_all.property_stock_account_input_categ_id.id
stock_out_acc_id = product_category_all.property_stock_account_output_categ_id.id
stock_valu_acc_id = product_category_all.property_stock_valuation_account_id.id
@@ -144,6 +170,30 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon):
product_category_all = self.env.ref('product.product_category_all')
product_category_all.property_cost_method = 'fifo'
product_category_all.property_valuation = 'real_time'
in_account = self.env['account.account'].create({
'name': 'IN Account',
'code': '000001',
'account_type': 'asset_current',
})
out_account = self.env['account.account'].create({
'name': 'OUT Account',
'code': '000002',
'account_type': 'asset_current',
})
valu_account = self.env['account.account'].create({
'name': 'VALU Account',
'code': '000003',
'account_type': 'asset_current',
})
production_cost_account = self.env['account.account'].create({
'name': 'PROD COST Account',
'code': '000004',
'account_type': 'asset_current',
})
product_category_all.property_stock_account_input_categ_id = in_account
product_category_all.property_stock_account_output_categ_id = out_account
product_category_all.property_stock_account_production_cost_id = production_cost_account
product_category_all.property_stock_valuation_account_id = valu_account
stock_in_acc_id = product_category_all.property_stock_account_input_categ_id.id
stock_valu_acc_id = product_category_all.property_stock_valuation_account_id.id
stock_cop_acc_id = product_category_all.property_stock_account_production_cost_id.id
@@ -356,10 +406,34 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon):
product_category_all = self.env.ref('product.product_category_all')
product_category_all.property_cost_method = 'standard'
product_category_all.property_valuation = 'real_time'
in_account = self.env['account.account'].create({
'name': 'IN Account',
'code': '000001',
'account_type': 'asset_current',
})
out_account = self.env['account.account'].create({
'name': 'OUT Account',
'code': '000002',
'account_type': 'asset_current',
})
valu_account = self.env['account.account'].create({
'name': 'VALU Account',
'code': '000003',
'account_type': 'asset_current',
})
production_cost_account = self.env['account.account'].create({
'name': 'PROD COST Account',
'code': '000004',
'account_type': 'asset_current',
})
product_category_all.property_stock_account_input_categ_id = in_account
product_category_all.property_stock_account_output_categ_id = out_account
product_category_all.property_stock_account_production_cost_id = production_cost_account
product_category_all.property_stock_valuation_account_id = valu_account
stock_in_acc_id = product_category_all.property_stock_account_input_categ_id.id
stock_valu_acc_id = product_category_all.property_stock_valuation_account_id.id
stock_cop_acc_id = product_category_all.property_stock_account_production_cost_id.id
self.comp1.standard_price = 10
self.comp2.standard_price = 20
self.finished.standard_price = 40
@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import Command
from odoo.exceptions import UserError
from odoo.fields import Date
from odoo.tests import Form
from odoo.tests import Form, tagged, loaded_demo_data
from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon
_logger = logging.getLogger(__name__)
@tagged('post_install', '-at_install')
class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
def setUp(self):
@@ -250,6 +255,9 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
"""Test that the price difference is correctly computed when a subcontracted
product is resupplied.
"""
if not loaded_demo_data(self.env):
_logger.warning("This test relies on demo data. To be rewritten independently of demo data for accurate and reliable results.")
return
resupply_sub_on_order_route = self.env['stock.route'].search([('name', '=', 'Resupply Subcontractor on Order')])
(self.comp1 + self.comp2).write({'route_ids': [(6, None, [resupply_sub_on_order_route.id])]})
product_category_all = self.env.ref('product.product_category_all')
@@ -309,6 +317,30 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
product_category_all = self.env.ref('product.product_category_all')
product_category_all.property_cost_method = 'fifo'
product_category_all.property_valuation = 'real_time'
in_account = self.env['account.account'].create({
'name': 'IN Account',
'code': '000001',
'account_type': 'asset_current',
})
out_account = self.env['account.account'].create({
'name': 'OUT Account',
'code': '000002',
'account_type': 'asset_current',
})
valu_account = self.env['account.account'].create({
'name': 'VALU Account',
'code': '000003',
'account_type': 'asset_current',
})
production_cost_account = self.env['account.account'].create({
'name': 'PROD COST Account',
'code': '000004',
'account_type': 'asset_current',
})
product_category_all.property_stock_account_input_categ_id = in_account
product_category_all.property_stock_account_output_categ_id = out_account
product_category_all.property_stock_account_production_cost_id = production_cost_account
product_category_all.property_stock_valuation_account_id = valu_account
stock_in_acc_id = product_category_all.property_stock_account_input_categ_id.id
purchase = self.env['purchase.order'].create({
'partner_id': self.subcontractor_partner1.id,
@@ -15,6 +15,8 @@ class TestMultistepManufacturing(TestMrpCommon):
cls.env.user.groups_id += cls.env.ref('uom.group_uom')
# Required for `manufacture_steps` to be visible in the view
cls.env.user.groups_id += cls.env.ref('stock.group_adv_location')
# Required for `product_id` to be visible in the view
cls.env.user.groups_id += cls.env.ref('product.group_product_variant')
cls.env.ref('stock.route_warehouse0_mto').active = True
cls.MrpProduction = cls.env['mrp.production']
@@ -247,7 +247,7 @@ class TestSaleMRPAngloSaxonValuation(ValuationReconciliationTestCommon):
# Sell 3 kits
so = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
'order_line': [
(0, 0, {
'name': kit.name,
@@ -352,7 +352,7 @@ class TestSaleMRPAngloSaxonValuation(ValuationReconciliationTestCommon):
# Sell 3 kits
so = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
'order_line': [
(0, 0, {
'name': kit.name,
+4 -4
View File
@@ -1691,7 +1691,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
# Create a SO for product Main Kit Product
order_form = Form(self.env['sale.order'])
order_form.partner_id = self.env.ref('base.res_partner_2')
order_form.partner_id = self.env['res.partner'].create({'name': 'Test Partner'})
with order_form.order_line.new() as line:
line.product_id = main_kit_product
line.product_uom_qty = 1
@@ -1794,7 +1794,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
# Create environment
self.env.company.currency_id = self.env.ref('base.USD')
self.env.company.anglo_saxon_accounting = True
self.partner = self.env.ref('base.res_partner_1')
self.partner = self.env['res.partner'].create({'name': 'Test Partner'})
self.category = self.env.ref('product.product_category_1').copy({'name': 'Test category', 'property_valuation': 'real_time', 'property_cost_method': 'fifo'})
account_receiv = self.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00', 'account_type': 'asset_receivable', 'reconcile': True})
account_expense = self.env['account.account'].create({'name': 'Expense', 'code': 'EXP00', 'account_type': 'liability_current', 'reconcile': True})
@@ -1922,7 +1922,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
def test_reconfirm_cancelled_kit(self):
so = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
'order_line': [
(0, 0, {
'name': self.kit_1.name,
@@ -2192,7 +2192,7 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
in_moves._action_done()
so = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
'order_line': [
(0, 0, {
'name': kit.name,
@@ -9,6 +9,11 @@ from odoo.tools import mute_logger
class TestSaleMrpProcurement(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref('base.group_user').write({'implied_ids': [(4, cls.env.ref('product.group_product_variant').id)]})
def test_sale_mrp(self):
# Required for `uom_id` to be visible in the view
self.env.user.groups_id += self.env.ref('uom.group_uom')
@@ -1,16 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import common
from odoo.tools import html2plaintext
@common.tagged('post_install', '-at_install')
class TestSaleMrpInvoices(common.TransactionCase):
class TestSaleMrpInvoices(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.product_by_lot = cls.env['product.product'].create({
'name': 'Product By Lot',
'type': 'product',
@@ -37,7 +40,7 @@ class TestSaleMrpInvoices(common.TransactionCase):
'product_qty': 1,
})]
})
cls.partner = cls.env.ref('base.res_partner_1')
cls.partner = cls.env['res.partner'].create({'name': 'Test Partner'})
def test_deliver_and_invoice_tracked_components(self):
"""