[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
This commit is contained in:
clesgow
2023-05-09 21:04:02 +02:00
parent b56f76711b
commit 34656b29f7
2 changed files with 7 additions and 20 deletions
-14
View File
@@ -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)
+7 -6
View File
@@ -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