[FIX] mrp: update quantity after post inventory

This commit is contained in:
Arnold Moyaux
2019-09-24 07:45:31 +00:00
parent 21e11c1e32
commit 49aa98ab99
2 changed files with 41 additions and 1 deletions
+2 -1
View File
@@ -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:
+39
View File
@@ -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).