From 49aa98ab99705c0ae23d568a1a498db394f61a9e Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 23 Sep 2019 12:49:49 +0000 Subject: [PATCH] [FIX] mrp: update quantity after post inventory --- addons/mrp/models/mrp_production.py | 3 ++- addons/mrp/tests/test_order.py | 39 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 772661d479c..44b085dc5d8 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -609,12 +609,13 @@ class MrpProduction(models.Model): move = self.move_raw_ids.filtered(lambda x: x.bom_line_id.id == bom_line.id and x.state not in ('done', 'cancel')) if move: old_qty = move[0].product_uom_qty + remaining_qty = move[0].raw_material_production_id.product_qty - move[0].raw_material_production_id.qty_produced if quantity > 0: move[0]._decrease_reserved_quanity(quantity) move[0].with_context(do_not_unreserve=True).write({'product_uom_qty': quantity}) move[0]._recompute_state() move[0]._action_assign() - move[0].unit_factor = quantity / move[0].raw_material_production_id.product_qty + move[0].unit_factor = remaining_qty and quantity / remaining_qty or 1.0 return move[0], old_qty, quantity else: if move[0].quantity_done > 0: diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index ad81954003c..bcb40081ce3 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -291,6 +291,45 @@ class TestMrpOrder(TestMrpCommon): self.assertEqual(mo.move_finished_ids.product_uom_qty, 4) mo.button_mark_done() + def test_update_quantity_2(self): + """ Build 5 final products with different consumed lots, + then edit the finished quantity and update the Manufacturing + order quantity. Then check if the produced quantity do not + change and it is possible to close the MO. + """ + self.stock_location = self.env.ref('stock.stock_location_stock') + mo, bom, p_final, p1, p2 = self.generate_mo(qty_final=3) + self.assertEqual(len(mo), 1, 'MO should have been created') + + self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 20) + self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5) + mo.action_assign() + + produce_form = Form(self.env['mrp.product.produce'].with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + })) + produce_form.qty_producing = 2 + produce_wizard = produce_form.save() + produce_wizard.do_produce() + + mo.post_inventory() + update_quantity_wizard = self.env['change.production.qty'].create({ + 'mo_id': mo.id, + 'product_qty': 5, + }) + update_quantity_wizard.change_prod_qty() + produce_form = Form(self.env['mrp.product.produce'].with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + })) + produce_wizard = produce_form.save() + produce_wizard.do_produce() + mo.button_mark_done() + + self.assertEqual(sum(mo.move_raw_ids.filtered(lambda m: m.product_id == p1).mapped('quantity_done')), 20) + self.assertEqual(sum(mo.move_finished_ids.mapped('quantity_done')), 5) + def test_rounding(self): """ Checks we round up when bringing goods to produce and round half-up when producing. This implementation allows to implement an efficiency notion (see rev 347f140fe63612ee05e).