diff options
Diffstat (limited to 'addons/mrp/tests/test_workorder_operation.py')
| -rw-r--r-- | addons/mrp/tests/test_workorder_operation.py | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py index ab4bf83ad8b..474aa909168 100644 --- a/addons/mrp/tests/test_workorder_operation.py +++ b/addons/mrp/tests/test_workorder_operation.py @@ -2,9 +2,10 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import datetime, timedelta -import unittest -from odoo.tests import Form + from odoo.addons.mrp.tests.common import TestMrpCommon +from odoo.exceptions import UserError +from odoo.tests import Form class TestWorkOrderProcess(TestMrpCommon): @@ -95,7 +96,7 @@ class TestWorkOrderProcess(TestMrpCommon): finished_lot =self.env['stock.production.lot'].create({'product_id': production_table.product_id.id}) workorder.write({'final_lot_id': finished_lot.id}) workorder.button_start() - for workorder_line_id in workorder.workorder_line_ids: + for workorder_line_id in workorder._workorder_line_ids(): if workorder_line_id.product_id.id == product_bolt.id: workorder_line_id.write({'lot_id': lot_bolt.id, 'qty_done': 1}) if workorder_line_id.product_id.id == product_table_sheet.id: @@ -199,7 +200,7 @@ class TestWorkOrderProcess(TestMrpCommon): finished_lot = self.env['stock.production.lot'].create({'product_id': production_table.product_id.id}) workorders[0].write({'final_lot_id': finished_lot.id, 'qty_producing': 1.0}) workorders[0].button_start() - workorders[0].workorder_line_ids[0].write({'lot_id': lot_sheet.id, 'qty_done': 1}) + workorders[0]._workorder_line_ids()[0].write({'lot_id': lot_sheet.id, 'qty_done': 1}) self.assertEqual(workorders[0].state, 'progress') workorders[0].record_production() @@ -211,7 +212,7 @@ class TestWorkOrderProcess(TestMrpCommon): # --------------------------------------------------------- workorders[1].button_start() workorders[1].qty_producing = 1.0 - workorders[1].workorder_line_ids[0].write({'lot_id': lot_leg.id, 'qty_done': 4}) + workorders[1]._workorder_line_ids()[0].write({'lot_id': lot_leg.id, 'qty_done': 4}) workorders[1].record_production() move_leg = production_table.move_raw_ids.filtered(lambda p: p.product_id == product_table_leg) #self.assertEqual(workorders[1].state, 'done') @@ -222,7 +223,7 @@ class TestWorkOrderProcess(TestMrpCommon): # --------------------------------------------------------- workorders[2].button_start() workorders[2].qty_producing = 1.0 - move_lot = workorders[2].workorder_line_ids[0] + move_lot = workorders[2]._workorder_line_ids()[0] move_lot.write({'lot_id': lot_bolt.id, 'qty_done': 4}) move_table_bolt = production_table.move_raw_ids.filtered(lambda p: p.product_id.id == product_bolt.id) workorders[2].record_production() @@ -486,7 +487,7 @@ class TestWorkOrderProcess(TestMrpCommon): laptop_lot_001 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id}) product_form.final_lot_id = laptop_lot_001 product_consume = product_form.save() - product_consume.workorder_line_ids[0].qty_done = 12 + product_consume._workorder_line_ids()[0].qty_done = 12 product_consume.do_produce() # Check consumed move after produce 6 quantity of customized laptop. @@ -513,8 +514,8 @@ class TestWorkOrderProcess(TestMrpCommon): laptop_lot_002 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id}) produce_form.final_lot_id = laptop_lot_002 product_consume = produce_form.save() - self.assertEquals(len(product_consume.workorder_line_ids), 2) - product_consume.workorder_line_ids[0].qty_done = 8 + self.assertEquals(len(product_consume._workorder_line_ids()), 2) + product_consume._workorder_line_ids()[0].qty_done = 8 product_consume.do_produce() charger_move = mo_custom_laptop.move_raw_ids.filtered(lambda x: x.product_id.id == product_charger.id and x.state != 'done') keybord_move = mo_custom_laptop.move_raw_ids.filtered(lambda x: x.product_id.id == product_keybord.id and x.state !='done') @@ -652,9 +653,9 @@ class TestWorkOrderProcess(TestMrpCommon): produce_form.final_lot_id = lot_a product_consume = produce_form.save() # laptop_lot_002 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id}) - self.assertEquals(len(product_consume.workorder_line_ids), 2) - product_consume.workorder_line_ids.filtered(lambda x: x.product_id == product_C).write({'qty_done': 3000}) - product_consume.workorder_line_ids.filtered(lambda x: x.product_id == product_B).write({'qty_done': 20}) + self.assertEquals(len(product_consume._workorder_line_ids()), 2) + product_consume._workorder_line_ids().filtered(lambda x: x.product_id == product_C).write({'qty_done': 3000}) + product_consume._workorder_line_ids().filtered(lambda x: x.product_id == product_B).write({'qty_done': 20}) product_consume.do_produce() mo_custom_product.post_inventory() @@ -720,6 +721,64 @@ class TestWorkOrderProcess(TestMrpCommon): workorder.record_production() self.assertEqual(workorder.state, 'done') + def test_03b_test_serial_number_defaults(self): + """ Check the constraint on the workorder final_lot. The first workorder + produces 2/2 units without serial number (serial is only required when + you register a component) then the second workorder try to register a + 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') + product = bom.product_tmpl_id.product_variant_id + product.tracking = 'serial' + + lot_1 = self.env['stock.production.lot'].create({ + 'product_id': product.id, + 'name': 'LOT000001' + }) + + lot_2 = self.env['stock.production.lot'].create({ + 'product_id': product.id, + 'name': 'LOT000002' + }) + self.env['stock.production.lot'].create({ + 'product_id': product.id, + 'name': 'LOT000003' + }) + + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = product + mo_form.bom_id = bom + mo_form.product_qty = 2.0 + mo = mo_form.save() + + mo.action_confirm() + mo.button_plan() + + workorder_0 = mo.workorder_ids[0] + workorder_0.record_production() + workorder_0.record_production() + with self.assertRaises(UserError): + workorder_0.record_production() + + workorder_1 = mo.workorder_ids[1] + with Form(workorder_1) as wo: + wo.final_lot_id = lot_1 + workorder_1.record_production() + + self.assertTrue(len(workorder_1.allowed_lots_domain) > 1) + with Form(workorder_1) as wo: + wo.final_lot_id = lot_2 + workorder_1.record_production() + + workorder_2 = mo.workorder_ids[2] + self.assertEqual(workorder_2.allowed_lots_domain, lot_1 | lot_2) + + self.assertEqual(workorder_0.finished_workorder_line_ids.qty_done, 2) + self.assertFalse(workorder_0.finished_workorder_line_ids.lot_id) + self.assertEqual(sum(workorder_1.finished_workorder_line_ids.mapped('qty_done')), 2) + self.assertEqual(workorder_1.finished_workorder_line_ids.mapped('lot_id'), lot_1 | lot_2) + def test_04_test_planning_date(self): """ Test that workorder are planned at the correct time. """ # Remove attendances linked to the calendar, this means that the workcenter is working 24/7 |
