From a46773742043aedcf3b0658f793881df7576d8ff Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Mon, 19 Jun 2023 16:05:52 +0000 Subject: [PATCH] [IMP] mrp*: make some MO's methods public The `mrp.production` method `_pre_button_mark_done` will now be public so it can be called since the web client. This change is done in order to know if trying to mark as done a production will return a wizard or not, which is needed in the new MRP Display view since there is a delay before a MO is actually marked as done and we don't want to see the wizard poping up after this delay but before ! The method `_set_qty_producing` public is also public now because it's called in `_onchange_producing` but saddly, the onchanges don't happen in the MES view, so this way we can manually call it when needed. task-3231200 Part-of: odoo/odoo#127250 --- addons/mrp/models/mrp_production.py | 9 +++++++-- addons/mrp_product_expiry/models/mrp_production.py | 4 ++-- addons/mrp_subcontracting/models/mrp_production.py | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index c89cea5fe00..a5232143ea7 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1246,6 +1246,11 @@ class MrpProduction(models.Model): parent_moves = self.procurement_group_id.stock_move_ids.move_dest_ids return (dest_moves | parent_moves).group_id.mrp_production_ids.filtered(lambda p: p.origin != self.origin) - self + def set_qty_producing(self): + # This method is used to call `_set_lot_producing` when the onchange doesn't apply. + self.ensure_one() + self._set_qty_producing() + def _set_lot_producing(self): self.ensure_one() self.lot_producing_id = self.env['stock.lot'].create(self._prepare_stock_lot_values()) @@ -1882,7 +1887,7 @@ class MrpProduction(models.Model): def button_mark_done(self): self._button_mark_done_sanity_checks() - res = self._pre_button_mark_done() + res = self.pre_button_mark_done() if res is not True: return res @@ -1963,7 +1968,7 @@ class MrpProduction(models.Model): }) return action - def _pre_button_mark_done(self): + def pre_button_mark_done(self): for production in self: if float_is_zero(production.qty_producing, precision_rounding=production.product_uom_id.rounding): production._set_quantities() diff --git a/addons/mrp_product_expiry/models/mrp_production.py b/addons/mrp_product_expiry/models/mrp_production.py index 21522a84f60..76a954ca30a 100644 --- a/addons/mrp_product_expiry/models/mrp_production.py +++ b/addons/mrp_product_expiry/models/mrp_production.py @@ -7,11 +7,11 @@ from odoo import models, _ class MrpWorkorder(models.Model): _inherit = 'mrp.production' - def _pre_button_mark_done(self): + def pre_button_mark_done(self): confirm_expired_lots = self._check_expired_lots() if confirm_expired_lots: return confirm_expired_lots - return super()._pre_button_mark_done() + return super().pre_button_mark_done() def _check_expired_lots(self): # We use the 'skip_expired' context key to avoid to make the check when diff --git a/addons/mrp_subcontracting/models/mrp_production.py b/addons/mrp_subcontracting/models/mrp_production.py index a9ab62ef40c..8fc7a28d55a 100644 --- a/addons/mrp_subcontracting/models/mrp_production.py +++ b/addons/mrp_subcontracting/models/mrp_production.py @@ -92,10 +92,10 @@ class MrpProduction(models.Model): return action return {'type': 'ir.actions.act_window_close'} - def _pre_button_mark_done(self): + def pre_button_mark_done(self): if self._get_subcontract_move(): return True - return super()._pre_button_mark_done() + return super().pre_button_mark_done() def _update_finished_move(self): """ After producing, set the move line on the subcontract picking. """