diff options
| author | Rémy Voet (ryv) <ryv@odoo.com> | 2020-07-01 12:50:04 +0000 |
|---|---|---|
| committer | Rémy Voet (ryv) <ryv@odoo.com> | 2020-07-30 12:09:10 +0000 |
| commit | e7fd2ba5c88eda06363389339eb651cc541fc4dd (patch) | |
| tree | 532ad6f86a82ac56bdfdf362134f9e1a1054178b /addons/mrp_subcontracting/tests | |
| parent | 2458098f606931a845b5acbe0aa9ede89a6a94c3 (diff) | |
[FIX] mrp_subcontracting: fix flow with tracked component
After the odoo/odoo#52949 , the registering of tracked component,
in case of subcontracting, was broken. Fix and try to mimic
the same flow than before. The produce wizard has been replaced
by a clean MO form to register component and use backorder mechanisme
of MO to manage tracked finished product + tracked component.
task-2278147
closes odoo/odoo#54994
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/mrp_subcontracting/tests')
| -rw-r--r-- | addons/mrp_subcontracting/tests/test_subcontracting.py | 181 |
1 files changed, 88 insertions, 93 deletions
diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index c282950ee97..22cea05aed4 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -402,87 +402,6 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): self.assertEqual(sum(move_finished.mapped('product_uom_qty')), 3.0) self.assertEqual(sum(move_finished.mapped('quantity_done')), 3.0) - def test_flow_7(self): - """ Process a subcontracting receipt with tracked component and - finished product. Simulate the regiter components button. - Once the components are registered, try to do a correction on exisiting - move lines and check that the subcontracting document is updated. - """ - # Create a receipt picking from the subcontractor - (self.comp1 | self.comp2 | self.finished).write({'tracking': 'lot'}) - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = self.env.ref('stock.picking_type_in') - picking_form.partner_id = self.subcontractor_partner1 - with picking_form.move_ids_without_package.new() as move: - move.product_id = self.finished - move.product_uom_qty = 3 # FIXME sle: need to handle the backorder in subcontract - picking_receipt = picking_form.save() - picking_receipt.action_confirm() - mo = picking_receipt.move_lines.move_orig_ids.production_id - move_comp1 = mo.move_raw_ids.filtered(lambda m: m.product_id == self.comp1) - move_comp2 = mo.move_raw_ids.filtered(lambda m: m.product_id == self.comp2) - # move_finished is linked to receipt and not MO finished move. - move_finished = picking_receipt.move_lines - - self.assertEqual(move_comp1.quantity_done, 0) - self.assertEqual(move_comp2.quantity_done, 0) - - lot_c1 = self.env['stock.production.lot'].create({ - 'name': 'LOT C1', - 'product_id': self.comp1.id, - 'company_id': self.env.company.id, - }) - lot_c2 = self.env['stock.production.lot'].create({ - 'name': 'LOT C2', - 'product_id': self.comp2.id, - 'company_id': self.env.company.id, - }) - lot_f1 = self.env['stock.production.lot'].create({ - 'name': 'LOT F1', - 'product_id': self.finished.id, - 'company_id': self.env.company.id, - }) - mo_form = Form(picking_receipt._get_subcontracted_productions().with_context(subcontract_move_id=picking_receipt.move_lines.id)) - mo_form.qty_producing = 3 - mo_form.lot_producing_id = lot_f1 - mo = mo_form.save() - details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations')) - with details_operation_form.move_line_ids.new() as ml: - ml.lot_id = lot_c1 - ml.qty_done = 3 - details_operation_form.save() - details_operation_form = Form(mo.move_raw_ids[1], view=self.env.ref('stock.view_stock_move_operations')) - with details_operation_form.move_line_ids.new() as ml: - ml.lot_id = lot_c2 - ml.qty_done = 3 - details_operation_form.save() - - self.assertEqual(move_comp1.quantity_done, 3) - self.assertEqual(move_comp1.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).lot_id.name, 'LOT C1') - self.assertEqual(move_comp2.quantity_done, 3) - self.assertEqual(move_comp2.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).lot_id.name, 'LOT C2') - self.assertEqual(move_finished.quantity_done, 3) - self.assertEqual(move_finished.move_line_ids.filtered(lambda ml: ml.product_uom_qty).lot_id.name, 'LOT F1') - - corrected_final_lot = self.env['stock.production.lot'].create({ - 'name': 'LOT F2', - 'product_id': self.finished.id, - 'company_id': self.env.company.id, - }) - - details_operation_form = Form(picking_receipt.move_lines, view=self.env.ref('stock.view_stock_move_operations')) - with details_operation_form.move_line_ids.edit(0) as ml: - ml.lot_id = corrected_final_lot - details_operation_form.save() - move_raw_comp_1 = picking_receipt.move_lines.move_orig_ids.production_id.move_raw_ids.filtered(lambda m: m.product_id == self.comp1) - move_raw_comp_2 = picking_receipt.move_lines.move_orig_ids.production_id.move_raw_ids.filtered(lambda m: m.product_id == self.comp2) - - picking_receipt.move_lines.move_orig_ids.production_id.lot_producing_id = corrected_final_lot - picking_receipt.move_lines.move_orig_ids.production_id.button_mark_done() - - self.assertEqual(move_comp1.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).produce_line_ids.lot_id.name, 'LOT F2') - self.assertEqual(move_comp2.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).produce_line_ids.lot_id.name, 'LOT F2') - def test_flow_8(self): resupply_sub_on_order_route = self.env['stock.location.route'].search([('name', '=', 'Resupply Subcontractor on Order')]) (self.comp1 + self.comp2).write({'route_ids': [(4, resupply_sub_on_order_route.id, None)]}) @@ -596,7 +515,7 @@ class TestSubcontractingTracking(TransactionCase): }) # 2.2. Finished prodcut has tracking by serial number - self.finished_lot = self.env['product.product'].create({ + self.finished_product = self.env['product.product'].create({ 'name': 'finished', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, @@ -605,7 +524,7 @@ class TestSubcontractingTracking(TransactionCase): bom_form = Form(self.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.subcontractor_ids.add(self.subcontractor_partner1) - bom_form.product_tmpl_id = self.finished_lot.product_tmpl_id + bom_form.product_tmpl_id = self.finished_product.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp1_sn bom_line.product_qty = 1 @@ -622,7 +541,7 @@ class TestSubcontractingTracking(TransactionCase): picking_form.picking_type_id = self.env.ref('stock.picking_type_in') picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: - move.product_id = self.finished_lot + move.product_id = self.finished_product move.product_uom_qty = 1 picking_receipt = picking_form.save() picking_receipt.action_confirm() @@ -633,7 +552,6 @@ class TestSubcontractingTracking(TransactionCase): # Check the created manufacturing order mo = self.env['mrp.production'].search([('bom_id', '=', self.bom_tracked.id)]) self.assertEqual(len(mo), 1) - self.assertEqual(mo.state, 'confirmed') self.assertEqual(len(mo.picking_ids), 0) wh = picking_receipt.picking_type_id.warehouse_id self.assertEqual(mo.picking_type_id, wh.subcontracting_type_id) @@ -658,7 +576,7 @@ class TestSubcontractingTracking(TransactionCase): lot_id = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.finished_lot.id, + 'product_id': self.finished_product.id, 'company_id': self.env.company.id, }) serial_id = self.env['stock.production.lot'].create({ @@ -667,15 +585,15 @@ class TestSubcontractingTracking(TransactionCase): 'company_id': self.env.company.id, }) - mo_form = Form(mo.with_context(subcontract_move_id=picking_receipt.move_lines.id)) + action = picking_receipt.action_record_components() + mo = self.env['mrp.production'].browse(action['res_id']) + mo_form = Form(mo.with_context(**action['context']), view=action['view_id']) mo_form.qty_producing = 1 mo_form.lot_producing_id = lot_id - mo = mo_form.save() - details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations')) - with details_operation_form.move_line_ids.new() as ml: - ml.qty_done = 1 + with mo_form.move_line_raw_ids.edit(0) as ml: ml.lot_id = serial_id - details_operation_form.save() + mo = mo_form.save() + mo.subcontracting_record_component() # We should not be able to call the 'record_components' button self.assertFalse(picking_receipt.display_action_record_components) @@ -686,7 +604,84 @@ class TestSubcontractingTracking(TransactionCase): # Available quantities should be negative at the subcontracting location for each components avail_qty_comp1 = self.env['stock.quant']._get_available_quantity(self.comp1_sn, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) avail_qty_comp2 = self.env['stock.quant']._get_available_quantity(self.comp2, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) - avail_qty_finished = self.env['stock.quant']._get_available_quantity(self.finished_lot, wh.lot_stock_id) + avail_qty_finished = self.env['stock.quant']._get_available_quantity(self.finished_product, wh.lot_stock_id) self.assertEqual(avail_qty_comp1, -1) self.assertEqual(avail_qty_comp2, -1) self.assertEqual(avail_qty_finished, 1) + + def test_flow_tracked_backorder(self): + """ This test uses tracked (serial and lot) component and tracked (serial) finished product """ + todo_nb = 4 + self.comp2.tracking = 'lot' + self.finished_product.tracking = 'serial' + + # Create a receipt picking from the subcontractor + picking_form = Form(self.env['stock.picking']) + picking_form.picking_type_id = self.env.ref('stock.picking_type_in') + picking_form.partner_id = self.subcontractor_partner1 + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.finished_product + move.product_uom_qty = todo_nb + picking_receipt = picking_form.save() + picking_receipt.action_confirm() + + # We should be able to call the 'record_components' button + self.assertTrue(picking_receipt.display_action_record_components) + + # Check the created manufacturing order + mo = self.env['mrp.production'].search([('bom_id', '=', self.bom_tracked.id)]) + self.assertEqual(len(mo), 1) + self.assertEqual(len(mo.picking_ids), 0) + wh = picking_receipt.picking_type_id.warehouse_id + self.assertEqual(mo.picking_type_id, wh.subcontracting_type_id) + self.assertFalse(mo.picking_type_id.active) + + lot_comp2 = self.env['stock.production.lot'].create({ + 'name': 'lot_comp2', + 'product_id': self.comp2.id, + 'company_id': self.env.company.id, + }) + serials_finished = [] + serials_comp1 = [] + for i in range(todo_nb): + serials_finished.append(self.env['stock.production.lot'].create({ + 'name': 'serial_fin_%s' % i, + 'product_id': self.finished_product.id, + 'company_id': self.env.company.id, + })) + serials_comp1.append(self.env['stock.production.lot'].create({ + 'name': 'serials_comp1_%s' % i, + 'product_id': self.comp1_sn.id, + 'company_id': self.env.company.id, + })) + + for i in range(todo_nb): + action = picking_receipt.action_record_components() + mo = self.env['mrp.production'].browse(action['res_id']) + mo_form = Form(mo.with_context(**action['context']), view=action['view_id']) + mo_form.lot_producing_id = serials_finished[i] + with mo_form.move_line_raw_ids.edit(0) as ml: + self.assertEqual(ml.product_id, self.comp1_sn) + ml.lot_id = serials_comp1[i] + with mo_form.move_line_raw_ids.edit(1) as ml: + self.assertEqual(ml.product_id, self.comp2) + ml.lot_id = lot_comp2 + mo = mo_form.save() + mo.subcontracting_record_component() + + # We should not be able to call the 'record_components' button + self.assertFalse(picking_receipt.display_action_record_components) + + picking_receipt.button_validate() + self.assertEqual(mo.state, 'done') + self.assertEqual(mo.procurement_group_id.mrp_production_ids.mapped("state"), ['done'] * todo_nb) + self.assertEqual(len(mo.procurement_group_id.mrp_production_ids), todo_nb) + self.assertEqual(mo.procurement_group_id.mrp_production_ids.mapped("qty_produced"), [1] * todo_nb) + + # Available quantities should be negative at the subcontracting location for each components + avail_qty_comp1 = self.env['stock.quant']._get_available_quantity(self.comp1_sn, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) + avail_qty_comp2 = self.env['stock.quant']._get_available_quantity(self.comp2, self.subcontractor_partner1.property_stock_subcontractor, allow_negative=True) + avail_qty_finished = self.env['stock.quant']._get_available_quantity(self.finished_product, wh.lot_stock_id) + self.assertEqual(avail_qty_comp1, -todo_nb) + self.assertEqual(avail_qty_comp2, -todo_nb) + self.assertEqual(avail_qty_finished, todo_nb) |
