[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 <svs@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
@@ -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):
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user