diff --git a/addons/mrp/tests/common.py b/addons/mrp/tests/common.py index b9592d4720e..382bbb849fe 100644 --- a/addons/mrp/tests/common.py +++ b/addons/mrp/tests/common.py @@ -154,3 +154,27 @@ class TestMrpCommon(common2.TestStockCommon): (0, 0, {'product_id': cls.product_4.id, 'product_qty': 8}), (0, 0, {'product_id': cls.product_2.id, 'product_qty': 12}) ]}) + cls.stock_location_14 = cls.env['stock.location'].create({ + 'name': 'Shelf 2', + 'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id, + }) + cls.stock_location_components = cls.env['stock.location'].create({ + 'name': 'Shelf 1', + 'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id, + }) + cls.laptop = cls.env['product.product'].create({ + 'name': 'Acoustic Bloc Screens', + 'uom_id': cls.env.ref("uom.product_uom_unit").id, + 'uom_po_id': cls.env.ref("uom.product_uom_unit").id, + 'type': 'product', + 'tracking': 'none', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) + cls.graphics_card = cls.env['product.product'].create({ + 'name': 'Individual Workplace', + 'uom_id': cls.env.ref("uom.product_uom_unit").id, + 'uom_po_id': cls.env.ref("uom.product_uom_unit").id, + 'type': 'product', + 'tracking': 'none', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) \ No newline at end of file diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 3cd315da16b..c7d06af6aea 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -131,7 +131,7 @@ class TestMrpOrder(TestMrpCommon): self.env['stock.quant'].with_context(inventory_mode=True).create({ 'product_id': self.product_2.id, 'inventory_quantity': 2.0, - 'location_id': self.ref('stock.stock_location_14') + 'location_id': self.stock_location_14.id }) production_2.action_assign() @@ -142,7 +142,7 @@ class TestMrpOrder(TestMrpCommon): self.env['stock.quant'].with_context(inventory_mode=True).create({ 'product_id': self.product_2.id, 'inventory_quantity': 5.0, - 'location_id': self.ref('stock.stock_location_14') + 'location_id': self.stock_location_14.id }) production_2.action_assign() @@ -163,8 +163,13 @@ class TestMrpOrder(TestMrpCommon): # create a bom for `custom_laptop` with components that aren't tracked unit = self.ref("uom.product_uom_unit") - custom_laptop = self.env.ref("product.product_product_27") - custom_laptop.tracking = 'none' + custom_laptop = self.env['product.product'].create({ + 'name': 'Drawer', + 'type': 'product', + 'uom_id': unit, + 'uom_po_id': unit, + }) + product_charger = self.env['product.product'].create({ 'name': 'Charger', 'type': 'product', @@ -191,7 +196,7 @@ class TestMrpOrder(TestMrpCommon): }) # put the needed products in stock - source_location_id = self.ref('stock.stock_location_14') + source_location_id = self.stock_location_14.id quant_before = custom_laptop.qty_available inventory = self.env['stock.inventory'].create({ 'name': 'Inventory Product Table', @@ -463,8 +468,9 @@ class TestMrpOrder(TestMrpCommon): """ # FIXME: some asserts on the quants after overproducing would be nice self.stock_location = self.env.ref('stock.stock_location_stock') - self.stock_shelf_1 = self.env.ref('stock.stock_location_components') - self.stock_shelf_2 = self.env.ref('stock.stock_location_14') + self.stock_shelf_1 = self.stock_location_components + + self.stock_shelf_2 = self.stock_location_14 mo, _, p_final, p1, p2 = self.generate_mo(tracking_base_1='lot', qty_base_1=10, qty_final=1) self.assertEqual(len(mo), 1, 'MO should have been created') @@ -530,8 +536,8 @@ class TestMrpOrder(TestMrpCommon): """ Possibility to produce with a given raw material in multiple locations. """ # FIXME sle: how is it possible to consume before producing in the interface? self.stock_location = self.env.ref('stock.stock_location_stock') - self.stock_shelf_1 = self.env.ref('stock.stock_location_components') - self.stock_shelf_2 = self.env.ref('stock.stock_location_14') + self.stock_shelf_1 = self.stock_location_components + self.stock_shelf_2 = self.stock_location_14 mo, _, p_final, p1, p2 = self.generate_mo(qty_final=1, qty_base_1=5) self.env['stock.quant']._update_available_quantity(p1, self.stock_shelf_1, 2) @@ -616,8 +622,8 @@ class TestMrpOrder(TestMrpCommon): self.assertEqual(len(mo), 1, 'MO should have been created') self.stock_location = self.env.ref('stock.stock_location_stock') - self.stock_shelf_1 = self.env.ref('stock.stock_location_components') - self.stock_shelf_2 = self.env.ref('stock.stock_location_14') + self.stock_shelf_1 = self.stock_location_components + self.stock_shelf_2 = self.stock_location_14 self.env['stock.quant']._update_available_quantity(p1, self.stock_shelf_1, 3) self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 3) @@ -1146,13 +1152,36 @@ class TestMrpOrder(TestMrpCommon): """ Produce a finished product tracked by serial number. Set another UoM on the bom. The produce wizard should keep the UoM of the product (unit) and quantity = 1.""" - - plastic_laminate = self.env.ref('mrp.product_product_plastic_laminate') - bom = self.env.ref('mrp.mrp_bom_plastic_laminate') dozen = self.env.ref('uom.product_uom_dozen') unit = self.env.ref('uom.product_uom_unit') - - plastic_laminate.tracking = 'serial' + plastic_laminate = self.env['product.product'].create({ + 'name': 'Plastic Laminate', + 'type': 'product', + 'uom_id': unit.id, + 'uom_po_id': unit.id, + 'tracking': 'serial', + }) + ply_veneer = self.env['product.product'].create({ + 'name': 'Ply Veneer', + 'type': 'product', + 'uom_id': unit.id, + 'uom_po_id': unit.id, + }) + routing = self.env['mrp.routing'].create({ + 'name': 'Secondary Assembly', + }) + bom = self.env['mrp.bom'].create({ + 'product_tmpl_id': plastic_laminate.product_tmpl_id.id, + 'product_uom_id': unit.id, + 'sequence': 1, + 'routing_id': routing.id, + 'bom_line_ids': [(0, 0, { + 'product_id': ply_veneer.id, + 'product_qty': 1, + 'product_uom_id': unit.id, + 'sequence': 1, + })] + }) mo_form = Form(self.env['mrp.production']) mo_form.product_id = plastic_laminate diff --git a/addons/mrp/tests/test_stock.py b/addons/mrp/tests/test_stock.py index c80e2bdf420..2c03f3234c1 100644 --- a/addons/mrp/tests/test_stock.py +++ b/addons/mrp/tests/test_stock.py @@ -10,6 +10,7 @@ class TestWarehouse(common.TestMrpCommon): def setUp(self): super(TestWarehouse, self).setUp() + unit = self.env.ref("uom.product_uom_unit") self.stock_location = self.env.ref('stock.stock_location_stock') self.depot_location = self.env['stock.location'].create({ 'name': 'Depot', @@ -21,18 +22,35 @@ class TestWarehouse(common.TestMrpCommon): "location_out_id": self.depot_location.id, 'category_id': self.env.ref('product.product_category_all').id, }) - - self.laptop = self.env.ref("product.product_product_25") - graphics_card = self.env.ref("product.product_product_24") - unit = self.env.ref("uom.product_uom_unit") - mrp_routing = self.env.ref("mrp.mrp_routing_0") + mrp_workcenter = self.env['mrp.workcenter'].create({ + 'name': 'Assembly Line 1', + 'resource_calendar_id': self.env.ref('resource.resource_calendar_std').id, + }) + mrp_routing = self.env['mrp.routing'].create({ + 'name': 'Primary Assembly', + 'operation_ids': [(0, 0, { + 'workcenter_id': mrp_workcenter.id, + 'name': 'Manual Assembly', + })] + }) + inventory = self.env['stock.inventory'].create({ + 'name': 'Initial inventory', + 'line_ids': [(0, 0, { + 'product_id': self.graphics_card.id, + 'product_uom_id': self.graphics_card.uom_id.id, + 'product_qty': 16.0, + 'location_id': self.stock_location_14.id, + })] + }) + inventory.action_start() + inventory.action_validate() self.bom_laptop = self.env['mrp.bom'].create({ 'product_tmpl_id': self.laptop.product_tmpl_id.id, 'product_qty': 1, 'product_uom_id': unit.id, 'bom_line_ids': [(0, 0, { - 'product_id': graphics_card.id, + 'product_id': self.graphics_card.id, 'product_qty': 1, 'product_uom_id': unit.id })], @@ -102,14 +120,14 @@ class TestWarehouse(common.TestMrpCommon): 'name': 'Stock Inventory for Stick', 'product_ids': [(4, self.product_4.id)], 'line_ids': [ - (0, 0, {'product_id': self.product_4.id, 'product_uom_id': self.product_4.uom_id.id, 'product_qty': 8, 'prod_lot_id': lot_product_4.id, 'location_id': self.ref('stock.stock_location_14')}), + (0, 0, {'product_id': self.product_4.id, 'product_uom_id': self.product_4.uom_id.id, 'product_qty': 8, 'prod_lot_id': lot_product_4.id, 'location_id': self.stock_location_14.id}), ]}) stock_inv_product_2 = self.env['stock.inventory'].create({ 'name': 'Stock Inventory for Stone Tools', 'product_ids': [(4, self.product_2.id)], 'line_ids': [ - (0, 0, {'product_id': self.product_2.id, 'product_uom_id': self.product_2.uom_id.id, 'product_qty': 12, 'prod_lot_id': lot_product_2.id, 'location_id': self.ref('stock.stock_location_14')}) + (0, 0, {'product_id': self.product_2.id, 'product_uom_id': self.product_2.uom_id.id, 'product_qty': 12, 'prod_lot_id': lot_product_2.id, 'location_id': self.stock_location_14.id}) ]}) (stock_inv_product_4 | stock_inv_product_2)._action_start() stock_inv_product_2.action_validate() diff --git a/addons/mrp/tests/test_unbuild.py b/addons/mrp/tests/test_unbuild.py index d59679265c3..bf5c6e25f47 100644 --- a/addons/mrp/tests/test_unbuild.py +++ b/addons/mrp/tests/test_unbuild.py @@ -5,11 +5,13 @@ from odoo.tests import Form from odoo.addons.mrp.tests.common import TestMrpCommon from odoo.exceptions import UserError - class TestUnbuild(TestMrpCommon): def setUp(self): super(TestUnbuild, self).setUp() self.stock_location = self.env.ref('stock.stock_location_stock') + self.env.ref('base.group_user').write({ + 'implied_ids': [(4, self.env.ref('stock.group_production_lot').id)] + }) def test_unbuild_standart(self): """ This test creates a MO and then creates 3 unbuild diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py index ee2c3bff2ad..4e0458fc068 100644 --- a/addons/mrp/tests/test_workorder_operation.py +++ b/addons/mrp/tests/test_workorder_operation.py @@ -26,7 +26,7 @@ class TestWorkOrderProcess(TestMrpCommon): @classmethod def setUpClass(cls): super(TestWorkOrderProcess, cls).setUpClass() - cls.source_location_id = cls.env.ref('stock.stock_location_14').id + cls.source_location_id = cls.stock_location_14.id cls.warehouse = cls.env.ref('stock.warehouse0') # setting up alternative workcenters cls.wc_alt_1 = cls.env['mrp.workcenter'].create({ @@ -55,22 +55,118 @@ class TestWorkOrderProcess(TestMrpCommon): (0, 0, {'product_id': cls.product_2.id, 'product_qty': 2}), (0, 0, {'product_id': cls.product_1.id, 'product_qty': 4}) ]}) + cls.dining_table = cls.env['product.product'].create({ + 'name': 'Table (MTO)', + 'type': 'product', + 'tracking': 'serial', + }) + cls.product_table_sheet = cls.env['product.product'].create({ + 'name': 'Table Top', + 'type': 'product', + 'tracking': 'serial', + }) + cls.product_table_leg = cls.env['product.product'].create({ + 'name': 'Table Leg', + 'type': 'product', + 'tracking': 'lot', + }) + cls.product_bolt = cls.env['product.product'].create({ + 'name': 'Bolt', + 'type': 'product', + }) + cls.product_screw = cls.env['product.product'].create({ + 'name': 'Screw', + 'type': 'product', + }) + + cls.mrp_workcenter = cls.env['mrp.workcenter'].create({ + 'name': 'Assembly Line 1', + 'resource_calendar_id': cls.env.ref('resource.resource_calendar_std').id, + }) + cls.routing = cls.env['mrp.routing'].create({ + 'name': 'Assemble Furniture', + 'operation_ids': [(0, 0, { + 'workcenter_id': cls.mrp_workcenter.id, + 'name': 'Manual Assembly', + })] + }) + cls.mrp_bom_desk = cls.env['mrp.bom'].create({ + 'product_tmpl_id': cls.dining_table.product_tmpl_id.id, + 'product_uom_id': cls.env.ref('uom.product_uom_unit').id, + 'sequence': 3, + 'consumption': 'flexible', + 'routing_id': cls.routing.id, + 'bom_line_ids': [ + (0, 0, { + 'product_id': cls.product_table_sheet.id, + 'product_qty': 1, + 'product_uom_id': cls.env.ref('uom.product_uom_unit').id, + 'sequence': 1, + 'operation_id': cls.routing.operation_ids.id}), + (0, 0, { + 'product_id': cls.product_table_leg.id, + 'product_qty': 4, + 'product_uom_id': cls.env.ref('uom.product_uom_unit').id, + 'sequence': 2, + 'operation_id': cls.routing.operation_ids.id}), + (0, 0, { + 'product_id': cls.product_bolt.id, + 'product_qty': 4, + 'product_uom_id': cls.env.ref('uom.product_uom_unit').id, + 'sequence': 3, + 'operation_id': cls.routing.operation_ids.id}), + (0, 0, { + 'product_id': cls.product_screw.id, + 'product_qty': 10, + 'product_uom_id': cls.env.ref('uom.product_uom_unit').id, + 'sequence': 4, + 'operation_id': cls.routing.operation_ids.id}), + ] + }) + cls.mrp_workcenter_1 = cls.env['mrp.workcenter'].create({ + 'name': 'Drill Station 1', + 'resource_calendar_id': cls.env.ref('resource.resource_calendar_std').id, + }) + cls.mrp_workcenter_3 = cls.env['mrp.workcenter'].create({ + 'name': 'Assembly Line 1', + 'resource_calendar_id': cls.env.ref('resource.resource_calendar_std').id, + }) + cls.routing_1 = cls.env['mrp.routing'].create({ + 'name': 'Secondary Assembly', + 'operation_ids': [ + (0, 0, { + 'workcenter_id': cls.mrp_workcenter_1.id, + 'name': 'Packing', + 'time_cycle': 30, + 'sequence': 5}), + (0, 0, { + 'workcenter_id': cls.mrp_workcenter_3.id, + 'name': 'Testing', + 'time_cycle': 60, + 'sequence': 10}), + (0, 0, { + 'workcenter_id': cls.mrp_workcenter_3.id, + 'name': 'Long time assembly', + 'time_cycle': 180, + 'sequence': 15}), + ] + }) + def test_00_workorder_process(self): """ Testing consume quants and produced quants with workorder """ + dining_table = self.dining_table + product_table_sheet = self.product_table_sheet + product_table_leg = self.product_table_leg + product_bolt = self.product_bolt + product_screw = self.product_screw + mrp_bom_desk = self.mrp_bom_desk - dining_table = self.env.ref("mrp.product_product_computer_desk") - product_table_sheet = self.env.ref('mrp.product_product_computer_desk_head') - product_table_leg = self.env.ref('mrp.product_product_computer_desk_leg') - product_bolt = self.env.ref('mrp.product_product_computer_desk_bolt') - product_screw = self.env.ref('mrp.product_product_computer_desk_screw') self.env['stock.move'].search([('product_id', 'in', [product_bolt.id, product_screw.id])])._do_unreserve() - (product_bolt + product_screw).write({'type': 'product'}) - self.env.ref("mrp.mrp_bom_desk").consumption = 'flexible' production_table_form = Form(self.env['mrp.production']) production_table_form.product_id = dining_table - production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk") + production_table_form.bom_id = mrp_bom_desk production_table_form.product_qty = 1.0 production_table_form.product_uom_id = dining_table.uom_id production_table = production_table_form.save() @@ -145,6 +241,12 @@ class TestWorkOrderProcess(TestMrpCommon): if workorder_line_id.product_id.id == product_table_leg.id: workorder_line_id.write({'lot_id': lot_leg.id, 'qty_done': 1}) self.assertEqual(workorder.state, 'progress') + + # YTI Clean that brol + # If mrp_workorder is installed, there could be checks defined on the + # workorder. + if hasattr(self.env['mrp.workorder'], 'check_ids'): + self.env['mrp.workorder'].search([]).write({'check_ids': False}) workorder.record_production() self.assertEqual(workorder.state, 'done') move_table_sheet = production_table.move_raw_ids.filtered(lambda x : x.product_id == product_table_sheet) @@ -162,16 +264,16 @@ class TestWorkOrderProcess(TestMrpCommon): def test_00b_workorder_process(self): """ Testing consume quants and produced quants with workorder """ - dining_table = self.env.ref("mrp.product_product_computer_desk") - product_table_sheet = self.env.ref('mrp.product_product_computer_desk_head') - product_table_leg = self.env.ref('mrp.product_product_computer_desk_leg') - product_bolt = self.env.ref('mrp.product_product_computer_desk_bolt') - self.env['stock.move'].search([('product_id', '=', product_bolt.id)])._do_unreserve() - product_bolt.type = 'product' + dining_table = self.dining_table + product_table_sheet = self.product_table_sheet + product_table_leg = self.product_table_leg + product_bolt = self.product_bolt + product_screw = self.product_screw + bom = self.mrp_bom_desk - bom = self.env['mrp.bom'].browse(self.ref("mrp.mrp_bom_desk")) - bom.routing_id = self.ref('mrp.mrp_routing_1') - bom.consumption = 'flexible' + self.env['stock.move'].search([('product_id', '=', product_bolt.id)])._do_unreserve() + + bom.routing_id = self.routing_1 bom.bom_line_ids.filtered(lambda p: p.product_id == product_table_sheet).operation_id = bom.routing_id.operation_ids[0] bom.bom_line_ids.filtered(lambda p: p.product_id == product_table_leg).operation_id = bom.routing_id.operation_ids[1] @@ -243,6 +345,12 @@ class TestWorkOrderProcess(TestMrpCommon): workorders[0].button_start() workorders[0]._workorder_line_ids()[0].write({'lot_id': lot_sheet.id, 'qty_done': 1}) self.assertEqual(workorders[0].state, 'progress') + + # YTI Clean that brol + # If mrp_workorder is installed, there could be checks defined on the + # workorder. + if hasattr(self.env['mrp.workorder'], 'check_ids'): + self.env['mrp.workorder'].search([]).write({'check_ids': False}) workorders[0].record_production() move_table_sheet = production_table.move_raw_ids.filtered(lambda p: p.product_id == product_table_sheet) @@ -352,18 +460,18 @@ class TestWorkOrderProcess(TestMrpCommon): 'product_uom_id': self.product_2.uom_id.id, 'product_qty': 30, 'prod_lot_id': lot_product_2.id, - 'location_id': self.ref('stock.stock_location_14') + 'location_id': self.stock_location_14.id }), (0, 0, { 'product_id': self.product_3.id, 'product_uom_id': self.product_3.uom_id.id, 'product_qty': 60, - 'location_id': self.ref('stock.stock_location_14') + 'location_id': self.stock_location_14.id }), (0, 0, { 'product_id': self.product_4.id, 'product_uom_id': self.product_4.uom_id.id, 'product_qty': 60, 'prod_lot_id': lot_product_4.id, - 'location_id': self.ref('stock.stock_location_14') + 'location_id': self.stock_location_14.id })] }) inventory.action_start() @@ -428,8 +536,11 @@ class TestWorkOrderProcess(TestMrpCommon): def test_01_without_workorder(self): """ Testing consume quants and produced quants without workorder """ unit = self.ref("uom.product_uom_unit") - custom_laptop = self.env.ref("product.product_product_27") - custom_laptop.tracking = 'lot' + custom_laptop = self.env['product.product'].create({ + 'name': 'Drawer', + 'type': 'product', + 'tracking': 'lot', + }) # Create new product charger and keybord # -------------------------------------- @@ -710,10 +821,10 @@ class TestWorkOrderProcess(TestMrpCommon): def test_03_test_serial_number_defaults(self): """ Test that the correct serial number is suggested on consecutive work orders. """ - laptop = self.env.ref("product.product_product_25") - graphics_card = self.env.ref("product.product_product_24") + laptop = self.laptop + graphics_card = self.graphics_card unit = self.env.ref("uom.product_uom_unit") - three_step_routing = self.env.ref("mrp.mrp_routing_1") + three_step_routing = self.routing_1 laptop.tracking = 'serial' @@ -769,7 +880,55 @@ class TestWorkOrderProcess(TestMrpCommon): serial number. It should be allowed since the first workorder did not specify a seiral number. """ - bom = self.env.ref('mrp.mrp_bom_laptop_cust_rout') + drawer = self.env['product.product'].create({ + 'name': 'Drawer', + 'type': 'product', + 'tracking': 'lot', + }) + drawer_drawer = self.env['product.product'].create({ + 'name': 'Drawer Black', + 'type': 'product', + 'tracking': 'lot', + }) + drawer_case = self.env['product.product'].create({ + 'name': 'Drawer Case Black', + 'type': 'product', + 'tracking': 'lot', + }) + bom = self.env['mrp.bom'].create({ + 'product_tmpl_id': drawer.product_tmpl_id.id, + 'product_uom_id': self.env.ref('uom.product_uom_unit').id, + 'sequence': 2, + 'routing_id': self.routing_1.id, + 'bom_line_ids': [(0, 0, { + 'product_id': drawer_drawer.id, + 'product_qty': 1, + 'product_uom_id': self.env.ref('uom.product_uom_unit').id, + 'sequence': 1, + }), (0, 0, { + 'product_id': drawer_case.id, + 'product_qty': 1, + 'product_uom_id': self.env.ref('uom.product_uom_unit').id, + 'sequence': 2, + })] + }) + inventory = self.env['stock.inventory'].create({ + 'name': 'Initial inventory', + 'line_ids': [(0, 0, { + 'product_id': drawer_drawer.id, + 'product_uom_id': drawer_drawer.uom_id.id, + 'product_qty': 50.0, + 'location_id': self.stock_location_14.id, + }), (0, 0, { + 'product_id': drawer_case.id, + 'product_uom_id': drawer_case.uom_id.id, + 'product_qty': 50.0, + 'location_id': self.stock_location_14.id, + })] + }) + inventory.action_start() + inventory.action_validate() + product = bom.product_tmpl_id.product_variant_id product.tracking = 'serial' @@ -828,11 +987,11 @@ class TestWorkOrderProcess(TestMrpCommon): # The workcenter is working 24/7 self.full_availability() - dining_table = self.env.ref("mrp.product_product_computer_desk") + dining_table = self.dining_table production_table_form = Form(self.env['mrp.production']) production_table_form.product_id = dining_table - production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk") + production_table_form.bom_id = self.mrp_bom_desk production_table_form.product_qty = 1.0 production_table_form.product_uom_id = dining_table.uom_id production_table = production_table_form.save() @@ -851,13 +1010,13 @@ class TestWorkOrderProcess(TestMrpCommon): # The workcenter is working 24/7 self.full_availability() - dining_table = self.env.ref("mrp.product_product_computer_desk") + dining_table = self.dining_table date_start = datetime.now() + timedelta(days=1) production_table_form = Form(self.env['mrp.production']) production_table_form.product_id = dining_table - production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk") + production_table_form.bom_id = self.mrp_bom_desk production_table_form.product_qty = 1.0 production_table_form.product_uom_id = dining_table.uom_id production_table_form.date_start_wo = date_start @@ -874,11 +1033,11 @@ class TestWorkOrderProcess(TestMrpCommon): def test_change_production_1(self): """Change the quantity to produce on the MO while workorders are already planned.""" - dining_table = self.env.ref("mrp.product_product_computer_desk") + dining_table = self.dining_table dining_table.tracking = 'lot' production_table_form = Form(self.env['mrp.production']) production_table_form.product_id = dining_table - production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk") + production_table_form.bom_id = self.mrp_bom_desk production_table_form.product_qty = 1.0 production_table_form.product_uom_id = dining_table.uom_id production_table = production_table_form.save() @@ -1067,7 +1226,20 @@ class TestWorkOrderProcess(TestMrpCommon): production sooner """ self.workcenter_1.alternative_workcenter_ids = self.wc_alt_1 | self.wc_alt_2 self.env['mrp.workcenter'].search([]).write({'tz': 'UTC'}) # compute all date in UTC - self.planning_bom.routing = self.env.ref("mrp.mrp_routing_0") + mrp_routing_0 = self.env['mrp.routing'].create({ + 'name': 'Primary Assembly', + }) + mrp_workcenter_3 = self.env['mrp.workcenter'].create({ + 'name': 'Assembly Line 1', + 'resource_calendar_id': self.env.ref('resource.resource_calendar_std').id, + }) + mrp_routing_workcenter_0 = self.env['mrp.routing.workcenter'].create({ + 'routing_id': mrp_routing_0.id, + 'workcenter_id': mrp_workcenter_3.id, + 'name': 'Manual Assembly', + 'time_cycle': 60, + }) + self.planning_bom.routing = mrp_routing_0 mo_form = Form(self.env['mrp.production']) mo_form.product_id = self.product_4 mo_form.bom_id = self.planning_bom @@ -1172,11 +1344,12 @@ class TestWorkOrderProcess(TestMrpCommon): mo.action_assign() mo.button_plan() - self.assertEqual(len(mo.workorder_ids), 1) - self.assertEqual(len(mo.workorder_ids.raw_workorder_line_ids), 3) - line1 = mo.workorder_ids.raw_workorder_line_ids[0] - line2 = mo.workorder_ids.raw_workorder_line_ids[1] - line3 = mo.workorder_ids.raw_workorder_line_ids[2] + self.assertEqual(len(mo.workorder_ids), 3) + long_time_assembly = mo.workorder_ids[2] + self.assertEqual(len(long_time_assembly.raw_workorder_line_ids), 3) + line1 = long_time_assembly.raw_workorder_line_ids[0] + line2 = long_time_assembly.raw_workorder_line_ids[1] + line3 = long_time_assembly.raw_workorder_line_ids[2] self.assertEqual(line1.product_id, self.product_1) self.assertEqual(line1.qty_done, 1) self.assertEqual(line2.product_id, self.product_2)