mrp_shared_operation/tests/test_shared_ops.py
2026-02-11 11:56:58 +07:00

72 lines
2.5 KiB
Python

import logging
from odoo.tests.common import TransactionCase, tagged
_logger = logging.getLogger(__name__)
@tagged('post_install')
class TestSharedOperations(TransactionCase):
def test_shared_operations(self):
# 1. Create a Work Center
workcenter = self.env['mrp.workcenter'].create({
'name': 'Test Work Center',
'time_efficiency': 100,
'costs_hour': 10,
})
# 2. Create a Shared Operation linked to Test Work Center
shared_op = self.env['mrp.routing.workcenter'].create({
'name': 'Shared Packaging Operation',
'workcenter_id': workcenter.id,
'time_mode': 'manual',
'time_cycle_manual': 60,
'bom_id': False, # Important: No specific BOM initially
})
# 3. Create Product A and BOM A
product_a = self.env['product.product'].create({
'name': 'Product A',
'type': 'consu',
})
bom_a = self.env['mrp.bom'].create({
'product_tmpl_id': product_a.product_tmpl_id.id,
'product_qty': 1.0,
'shared_operation_ids': [(4, shared_op.id)],
})
# 4. Create Product B and BOM B
product_b = self.env['product.product'].create({
'name': 'Product B',
'type': 'consu',
})
bom_b = self.env['mrp.bom'].create({
'product_tmpl_id': product_b.product_tmpl_id.id,
'product_qty': 1.0,
'shared_operation_ids': [(4, shared_op.id)],
})
# 5. Create MO for BOM A and verify Work Order
mo_a = self.env['mrp.production'].create({
'product_id': product_a.id,
'product_qty': 1.0,
'bom_id': bom_a.id,
})
mo_a.action_confirm()
self.assertEqual(len(mo_a.workorder_ids), 1, "MO A should have 1 work order")
self.assertEqual(mo_a.workorder_ids.operation_id, shared_op, "MO A work order should be the shared operation")
# 6. Create MO for BOM B and verify Work Order
mo_b = self.env['mrp.production'].create({
'product_id': product_b.id,
'product_qty': 1.0,
'bom_id': bom_b.id,
})
mo_b.action_confirm()
self.assertEqual(len(mo_b.workorder_ids), 1, "MO B should have 1 work order")
self.assertEqual(mo_b.workorder_ids.operation_id, shared_op, "MO B work order should be the shared operation")
print("Test Shared Operations Passed Successfully")