[IMP] mrp: Set quantity in consumption warning
In consumption warning, we add a new button that can correct all qty_done according to should_consumed_qty. closes odoo/odoo#113538 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, api
|
||||
from odoo import _, fields, models, api
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_compare, float_round
|
||||
|
||||
|
||||
class MrpConsumptionWarning(models.TransientModel):
|
||||
@@ -38,6 +40,21 @@ class MrpConsumptionWarning(models.TransientModel):
|
||||
action_from_mark_done = self.mrp_production_ids.with_context(ctx, skip_consumption=True).button_mark_done()
|
||||
return action_from_do_finish or action_from_mark_done
|
||||
|
||||
def action_set_qty(self):
|
||||
self.mrp_production_ids.action_assign()
|
||||
for production in self.mrp_production_ids:
|
||||
for move in production.move_raw_ids:
|
||||
rounding = move.product_uom.rounding
|
||||
if float_compare(move.quantity_done, move.should_consume_qty, precision_rounding=rounding) == 0:
|
||||
continue
|
||||
new_qty = float_round((production.qty_producing - production.qty_produced) * move.unit_factor, precision_rounding=move.product_uom.rounding)
|
||||
if move.has_tracking in ('lot', 'serial'):
|
||||
if not (production.use_auto_consume_components_lots and
|
||||
float_compare(move.reserved_availability, new_qty, precision_rounding=move.product_uom.rounding) >= 0):
|
||||
raise UserError(_('You need to supply Lot/Serial Number'))
|
||||
move.quantity_done = new_qty
|
||||
return self.action_confirm()
|
||||
|
||||
def action_cancel(self):
|
||||
if self.env.context.get('from_workorder') and len(self.mrp_production_ids) == 1:
|
||||
return {
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
colspan="1" type="object" class="btn-primary"/>
|
||||
<button name="action_confirm" string="Confirm" attrs="{'invisible': [('consumption', '=', 'strict')]}" data-hotkey="q"
|
||||
colspan="1" type="object" class="btn-primary"/>
|
||||
<button name="action_set_qty" string="Set Quantities & Validate" colspan="1" type="object" class="btn-secondary"/>
|
||||
<button name="action_cancel" string="Discard" data-hotkey="w"
|
||||
colspan="1" type="object" class="btn-secondary"/>
|
||||
</footer>
|
||||
|
||||
Reference in New Issue
Block a user