diff options
Diffstat (limited to 'addons/mrp_subcontracting/tests/test_subcontracting.py')
| -rw-r--r-- | addons/mrp_subcontracting/tests/test_subcontracting.py | 97 |
1 files changed, 35 insertions, 62 deletions
diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index 281e32c96ea..c282950ee97 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -415,7 +415,7 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): 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 = 5 + 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 @@ -442,39 +442,26 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): '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() - register_form = Form(self.env['mrp.product.produce'].with_context( - active_id=picking_receipt._get_subcontracted_productions().id, - default_subcontract_move_id=picking_receipt.move_lines.id - )) - register_form.qty_producing = 3.0 - self.assertEqual(len(register_form._values['raw_workorder_line_ids']), 2, - 'Register Components Form should contains one line per component.') - self.assertTrue(all(p[2]['product_id'] in (self.comp1 | self.comp2).ids for p in register_form._values['raw_workorder_line_ids']), - 'Register Components Form should contains component.') - with register_form.raw_workorder_line_ids.edit(0) as pl: - pl.lot_id = lot_c1 - with register_form.raw_workorder_line_ids.edit(1) as pl: - pl.lot_id = lot_c2 - register_form.finished_lot_id = lot_f1 - register_wizard = register_form.save() - action = register_wizard.continue_production() - register_form = Form(self.env['mrp.product.produce'].with_context( - **action['context'] - )) - with register_form.raw_workorder_line_ids.edit(0) as pl: - pl.lot_id = lot_c1 - with register_form.raw_workorder_line_ids.edit(1) as pl: - pl.lot_id = lot_c2 - register_form.finished_lot_id = lot_f1 - register_wizard = register_form.save() - register_wizard.do_produce() - - self.assertEqual(move_comp1.quantity_done, 5.0) + 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, 5.0) + 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, 5.0) + 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({ @@ -484,31 +471,17 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): }) details_operation_form = Form(picking_receipt.move_lines, view=self.env.ref('stock.view_stock_move_operations')) - for i in range(len(details_operation_form._values['move_line_ids'])): - with details_operation_form.move_line_ids.edit(i) as ml: - if ml._values['qty_done']: - ml.lot_id = corrected_final_lot + 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) - details_subcontract_moves_form = Form(move_raw_comp_1, view=self.env.ref('mrp_subcontracting.mrp_subcontracting_move_form_view')) - for i in range(len(details_subcontract_moves_form._values['move_line_ids'])): - with details_subcontract_moves_form.move_line_ids.edit(i) as sc: - if sc._values['qty_done']: - sc.lot_produced_ids.remove(index=0) - sc.lot_produced_ids.add(corrected_final_lot) - details_subcontract_moves_form.save() - details_subcontract_moves_form = Form(move_raw_comp_2, view=self.env.ref('mrp_subcontracting.mrp_subcontracting_move_form_view')) - for i in range(len(details_subcontract_moves_form._values['move_line_ids'])): - with details_subcontract_moves_form.move_line_ids.edit(i) as sc: - if sc._values['qty_done']: - sc.lot_produced_ids.remove(index=0) - sc.lot_produced_ids.add(corrected_final_lot) - details_subcontract_moves_form.save() - - self.assertEqual(move_comp1.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).lot_produced_ids.name, 'LOT F2') - self.assertEqual(move_comp2.move_line_ids.filtered(lambda ml: not ml.product_uom_qty).lot_produced_ids.name, 'LOT F2') + 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')]) @@ -693,20 +666,20 @@ class TestSubcontractingTracking(TransactionCase): 'product_id': self.comp1_sn.id, 'company_id': self.env.company.id, }) - produce_form = Form(self.env['mrp.product.produce'].with_context({ - 'active_id': mo.id, - 'active_ids': [mo.id], - })) - produce_form.finished_lot_id = lot_id - produce_form.raw_workorder_line_ids._records[0]['lot_id'] = serial_id.id - wiz_produce = produce_form.save() - wiz_produce.do_produce() + + mo_form = Form(mo.with_context(subcontract_move_id=picking_receipt.move_lines.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 + ml.lot_id = serial_id + details_operation_form.save() # We should not be able to call the 'record_components' button self.assertFalse(picking_receipt.display_action_record_components) - picking_receipt.move_lines.quantity_done = 1 - picking_receipt.move_lines.move_line_ids.lot_id = lot_id.id picking_receipt.button_validate() self.assertEqual(mo.state, 'done') |
