From 2c794033b006b31daede9f477bda1b1e23496064 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 9 Apr 2024 19:27:07 +0200 Subject: [PATCH] mrp_usability: Allow to change the destination location until 'Mark as done' Native behavior: it is only possible to change the destination stock location of a production order in draft state. --- mrp_usability/models/mrp_production.py | 16 +++++++++++++++- mrp_usability/views/mrp_production.xml | 16 +++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mrp_usability/models/mrp_production.py b/mrp_usability/models/mrp_production.py index 94e4045..acb49fe 100644 --- a/mrp_usability/models/mrp_production.py +++ b/mrp_usability/models/mrp_production.py @@ -3,12 +3,26 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models +from odoo import fields, models, Command class MrpProduction(models.Model): _inherit = 'mrp.production' + location_dest_id = fields.Many2one(tracking=True) + + # Target: allow to modify location_dest_id until the button 'Mark as done' is pushed + # I didn't find a better implementation... feel free to improve if you find one + def _compute_move_finished_ids(self): + for prod in self: + if prod.state not in ('draft', 'done') and prod.location_dest_id: + vals = {'location_dest_id': prod.location_dest_id.id} + prod.move_finished_ids = [ + Command.update(m.id, vals) for m in prod.move_finished_ids + if m.state != 'done' + ] + super()._compute_move_finished_ids() + # Method used by the report, inherited in this module # @api.model # def get_stock_move_sold_out_report(self, move): diff --git a/mrp_usability/views/mrp_production.xml b/mrp_usability/views/mrp_production.xml index 857d0d3..5c1d54d 100644 --- a/mrp_usability/views/mrp_production.xml +++ b/mrp_usability/views/mrp_production.xml @@ -13,11 +13,17 @@ mrp.production - + + + + + + + + + 1 +