[FIX] mrp: change qty_producing when updating product_qty
Currently, when no workorders are defined for a production, updating its `product_qty` through the wizard won't update its qty_producing, meaning that if the production gets validated right afterwards, the total produced will be the same as prior the update. This is missleading and unconsistent with how things work when workorders are involved, since in that case the `qty_producing` of the production will be updated through the inverse of the workorder's `qty_producing`. Also removed the verification on `produced_qty` as it will never be set before the MO is done, and the wizard can't be accessed at this point. Part-of: odoo/odoo#142513
This commit is contained in:
@@ -6676,15 +6676,6 @@ msgid ""
|
||||
" </b>"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#. odoo-python
|
||||
#: code:addons/mrp/wizard/change_production_qty.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You have already processed %(quantity)s. Please input a quantity higher than"
|
||||
" %(quantity)s "
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: model_terms:ir.ui.view,arch_db:mrp.view_assign_serial_numbers_production
|
||||
msgid ""
|
||||
|
||||
@@ -304,18 +304,26 @@ class TestMrpOrder(TestMrpCommon):
|
||||
mo_form.qty_producing = 2
|
||||
mo = mo_form.save()
|
||||
|
||||
# Produce & backorder
|
||||
action = mo.button_mark_done()
|
||||
backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
|
||||
backorder.save().action_backorder()
|
||||
mo_backorder = mo.procurement_group_id.mrp_production_ids[-1]
|
||||
self.assertEqual(mo_backorder.product_qty, 1)
|
||||
|
||||
update_quantity_wizard = self.env['change.production.qty'].create({
|
||||
'mo_id': mo.id,
|
||||
'product_qty': 5,
|
||||
'mo_id': mo_backorder.id,
|
||||
'product_qty': 3,
|
||||
})
|
||||
update_quantity_wizard.change_prod_qty()
|
||||
mo_form = Form(mo)
|
||||
mo_form.qty_producing = 5
|
||||
mo = mo_form.save()
|
||||
mo.button_mark_done()
|
||||
mo_back_form = Form(mo_backorder)
|
||||
mo_back_form.qty_producing = 3
|
||||
mo_backorder = mo_back_form.save()
|
||||
mo_backorder.button_mark_done()
|
||||
|
||||
self.assertEqual(sum(mo.move_raw_ids.filtered(lambda m: m.product_id == p1).mapped('quantity')), 20)
|
||||
self.assertEqual(sum(mo.move_finished_ids.mapped('quantity')), 5)
|
||||
productions = mo | mo_backorder
|
||||
self.assertEqual(sum(productions.move_raw_ids.filtered(lambda m: m.product_id == p1).mapped('quantity')), 20)
|
||||
self.assertEqual(sum(productions.move_finished_ids.mapped('quantity')), 5)
|
||||
|
||||
def test_update_quantity_3(self):
|
||||
bom = self.env['mrp.bom'].create({
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_is_zero, float_round
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
|
||||
class ChangeProductionQty(models.TransientModel):
|
||||
@@ -58,16 +58,10 @@ class ChangeProductionQty(models.TransientModel):
|
||||
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||
for wizard in self:
|
||||
production = wizard.mo_id
|
||||
if wizard.product_qty < production.qty_produced:
|
||||
format_qty = '%.{precision}f'.format(precision=precision)
|
||||
raise UserError(_(
|
||||
"You have already processed %(quantity)s. Please input a quantity higher than %(quantity)s ",
|
||||
quantity=format_qty % production.qty_produced,
|
||||
))
|
||||
old_production_qty = production.product_qty
|
||||
new_production_qty = wizard.product_qty
|
||||
|
||||
factor = (new_production_qty - production.qty_produced) / (old_production_qty - production.qty_produced)
|
||||
factor = new_production_qty / old_production_qty
|
||||
update_info = production._update_raw_moves(factor)
|
||||
documents = {}
|
||||
for move, old_qty, new_qty in update_info:
|
||||
@@ -80,8 +74,12 @@ class ChangeProductionQty(models.TransientModel):
|
||||
else:
|
||||
documents[key] = [value]
|
||||
production._log_manufacture_exception(documents)
|
||||
self._update_finished_moves(production, new_production_qty - production.qty_produced, old_production_qty - production.qty_produced)
|
||||
self._update_finished_moves(production, new_production_qty, old_production_qty)
|
||||
production.write({'product_qty': new_production_qty})
|
||||
if not float_is_zero(production.qty_producing, precision_rounding=production.product_uom_id.rounding) and\
|
||||
not production.workorder_ids:
|
||||
production.qty_producing = new_production_qty
|
||||
production._set_qty_producing()
|
||||
|
||||
for wo in production.workorder_ids:
|
||||
operation = wo.operation_id
|
||||
|
||||
Reference in New Issue
Block a user