From 3a0678cbc39cfb56937396191ab5a5fbe7db427a Mon Sep 17 00:00:00 2001 From: Ahmed Khalaf Date: Fri, 17 Feb 2023 10:34:11 +0000 Subject: [PATCH] [FIX] stock, mrp: fix forecasted report for MOs Before this commit, the reserve and unreserve buttons did not appear for MOs. Another bug was also fixed, removed the 0 Inventory on Hand line that appeared when there are no moves in the report. closes odoo/odoo#112981 Signed-off-by: Steve Van Essche --- addons/mrp/report/stock_forecasted.py | 16 +++++++++++++++- .../src/mrp_forecasted/forecasted_details.js | 11 +++++++++++ addons/stock/report/stock_forecasted.py | 10 ++++++++-- .../src/stock_forecasted/forecasted_details.js | 9 ++++++--- .../src/stock_forecasted/stock_forecasted.js | 2 +- 5 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 addons/mrp/static/src/mrp_forecasted/forecasted_details.js diff --git a/addons/mrp/report/stock_forecasted.py b/addons/mrp/report/stock_forecasted.py index 5f863e06175..0d1ece033eb 100644 --- a/addons/mrp/report/stock_forecasted.py +++ b/addons/mrp/report/stock_forecasted.py @@ -1,12 +1,26 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import models +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): line = super()._prepare_report_line(quantity, move_out, move_in, replenishment_filled, product, reserved_move, in_transit) diff --git a/addons/mrp/static/src/mrp_forecasted/forecasted_details.js b/addons/mrp/static/src/mrp_forecasted/forecasted_details.js new file mode 100644 index 00000000000..790837c0dd1 --- /dev/null +++ b/addons/mrp/static/src/mrp_forecasted/forecasted_details.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ + +import { ForecastedDetails } from '@stock/stock_forecasted/forecasted_details'; +import { patch } from '@web/core/utils/patch'; + +patch(ForecastedDetails.prototype, 'mrp.ForecastedDetails',{ + + canReserveOperation(line){ + return this._super(line) || line.move_out?.raw_material_production_id; + } +}); diff --git a/addons/stock/report/stock_forecasted.py b/addons/stock/report/stock_forecasted.py index cbd5ffd1d20..701ddbd5c9b 100644 --- a/addons/stock/report/stock_forecasted.py +++ b/addons/stock/report/stock_forecasted.py @@ -371,12 +371,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_id.browse(move_id._rollup_move_origs()).picking_id.filtered(lambda p: p.state not in ['draft', 'cancel', 'done']).action_assign() + 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() + return move_ids @api.model def action_unreserve_linked_picks(self, move_id): move_id = self.env['stock.move'].browse(move_id) - move_id.browse(move_id._rollup_move_origs()).picking_id.filtered(lambda p: p.state not in ['draft', 'cancel', 'done']).do_unreserve() + 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() + return move_ids class StockForecastedTemplate(models.AbstractModel): diff --git a/addons/stock/static/src/stock_forecasted/forecasted_details.js b/addons/stock/static/src/stock_forecasted/forecasted_details.js index ccba90cffd4..84525c0ca03 100644 --- a/addons/stock/static/src/stock_forecasted/forecasted_details.js +++ b/addons/stock/static/src/stock_forecasted/forecasted_details.js @@ -9,7 +9,7 @@ export class ForecastedDetails extends Component { this.orm = useService("orm"); this.onHandCondition = - this.props.docs.lines && + this.props.docs.lines.length && !this.props.docs.lines.some((line) => line.document_in || line.replenishment_filled); this._formatFloat = (num) => { @@ -22,7 +22,6 @@ export class ForecastedDetails extends Component { 'stock.forecasted_product_product', 'action_reserve_linked_picks', [move_id], - // {modelId} ); this.props.reloadReport(); } @@ -44,7 +43,11 @@ export class ForecastedDetails extends Component { } displayReserve(line){ - return line.move_out && line.move_out.picking_id && !line.in_transit; + return !line.in_transit && this.canReserveOperation(line); + } + + canReserveOperation(line){ + return line.move_out?.picking_id; } get futureVirtualAvailable() { diff --git a/addons/stock/static/src/stock_forecasted/stock_forecasted.js b/addons/stock/static/src/stock_forecasted/stock_forecasted.js index 808d7f2cce7..8c6bc428fc0 100644 --- a/addons/stock/static/src/stock_forecasted/stock_forecasted.js +++ b/addons/stock/static/src/stock_forecasted/stock_forecasted.js @@ -12,7 +12,7 @@ import { ForecastedWarehouseFilter } from "./forecasted_warehouse_filter"; const { Component, onWillStart, useState, useSubEnv } = owl; -class StockForecasted extends Component { +export class StockForecasted extends Component { setup() { useSubEnv({ ...this.env,