From 34656b29f7e9ec2fb14f5166426d8024d77c886e Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 14 Apr 2023 16:25:29 +0000 Subject: [PATCH] [IMP] stock,mrp: only reserve product on the forecast When using the Reserve / Unreserve buttons on the forecast report, this will [un]reserve every move of the picking / production. We want to be able to do it on a product base, so that when using the [un]reserve from the forecast of a product, it will only affect the said product. Part of task-3218314 Part-of: odoo/odoo#119381 --- addons/mrp/report/stock_forecasted.py | 14 -------------- addons/stock/report/stock_forecasted.py | 13 +++++++------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/addons/mrp/report/stock_forecasted.py b/addons/mrp/report/stock_forecasted.py index b2cadba8b54..30aa117bee0 100644 --- a/addons/mrp/report/stock_forecasted.py +++ b/addons/mrp/report/stock_forecasted.py @@ -7,20 +7,6 @@ from odoo import api, models class StockForecasted(models.AbstractModel): _inherit = 'stock.forecasted_product_product' - @api.model - def action_reserve_linked_picks(self, move_id): - """ In case of move connected to MOs instead of picking we want to reserve the MO - """ - linked_move_ids = super().action_reserve_linked_picks(move_id) - production_ids = linked_move_ids.raw_material_production_id | linked_move_ids.production_id - production_ids.filtered(lambda m: m.state not in ['draft', 'cancel', 'done']).action_assign() - - @api.model - def action_unreserve_linked_picks(self, move_id): - linked_move_ids = super().action_unreserve_linked_picks(move_id) - production_ids = linked_move_ids.raw_material_production_id | linked_move_ids.production_id - production_ids.filtered(lambda m: m.state not in ['draft', 'cancel', 'done']).do_unreserve() - def _prepare_report_line(self, quantity, move_out=None, move_in=None, replenishment_filled=True, product=False, reserved_move=False, in_transit=False, read=True): line = super()._prepare_report_line(quantity, move_out, move_in, replenishment_filled, product, reserved_move, in_transit, read) diff --git a/addons/stock/report/stock_forecasted.py b/addons/stock/report/stock_forecasted.py index e8da19730a5..e0db2f8c776 100644 --- a/addons/stock/report/stock_forecasted.py +++ b/addons/stock/report/stock_forecasted.py @@ -372,17 +372,18 @@ class StockForecasted(models.AbstractModel): @api.model def action_reserve_linked_picks(self, move_id): move_id = self.env['stock.move'].browse(move_id) - move_ids = move_id.browse(move_id._rollup_move_origs()) - picking_ids = move_ids.picking_id.filtered(lambda p: p.state not in ['draft', 'cancel', 'done']) - if picking_ids: - picking_ids.action_assign() + move_ids = move_id.browse(move_id._rollup_move_origs()).filtered(lambda m: m.state not in ['draft', 'cancel', 'assigned', 'done']) + if move_ids: + move_ids._action_assign() return move_ids @api.model def action_unreserve_linked_picks(self, move_id): move_id = self.env['stock.move'].browse(move_id) - move_ids = move_id.browse(move_id._rollup_move_origs()) - move_ids.picking_id.filtered(lambda p: p.state not in ['draft', 'cancel', 'done']).do_unreserve() + move_ids = move_id.browse(move_id._rollup_move_origs()).filtered(lambda m: m.state not in ['draft', 'cancel', 'done']) + if move_ids: + move_ids._do_unreserve() + move_ids.picking_id.package_level_ids.filtered(lambda p: not p.move_ids).unlink() return move_ids