[FIX] stock: display forecast for the current warehouse
Steps to reproduce the bug:
- Create two warehouses in the same company
- Create a storable product “P1”:
- Add 10 units in each warehouse
- Click on the forecasted widget
Problem:
The quantity on hand is 20 instead of 10 while the current warehouse set
in the filter is "WH1", because the warehouse has not
been added in the context, so we calculate all the quantities available
in all the locations of the current company:
https://github.com/odoo/odoo/blob/c05815ae6b8bd7afceb760395af09c707c89c485/addons/stock/report/stock_forecasted.py#L164
https://github.com/odoo/odoo/blob/3ee5d7a0fbccae5f742e1aba8d3d24f8bab3cbdd/addons/stock/models/product.py#L275
for the filter, the default one is added in the context here:
https://github.com/odoo/odoo/blob/16.0/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js#L19
opw-3194872
closes odoo/odoo#115255
X-original-commit: 10ea5d0cfb08b733322d0274e191a20f7f53cd78
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
c039064ca4
commit
0ad863ba24
@@ -9,16 +9,11 @@ export class ForecastedWarehouseFilter extends Component {
|
||||
setup() {
|
||||
this.orm = useService("orm");
|
||||
this.context = this.props.action.context;
|
||||
this.warehouses = this.props.warehouses;
|
||||
onWillStart(this.onWillStart)
|
||||
}
|
||||
|
||||
async onWillStart() {
|
||||
this.warehouses = await this.orm.searchRead('stock.warehouse', [],['id', 'name', 'code']);
|
||||
|
||||
if (!this.context.warehouse) {
|
||||
this.props.setWarehouseInContext(this.warehouses[0].id);
|
||||
}
|
||||
|
||||
this.displayWarehouseFilter = (this.warehouses.length > 1);
|
||||
}
|
||||
|
||||
@@ -35,4 +30,4 @@ export class ForecastedWarehouseFilter extends Component {
|
||||
|
||||
ForecastedWarehouseFilter.template = 'stock.ForecastedWarehouseFilter';
|
||||
ForecastedWarehouseFilter.components = {Dropdown, DropdownItem};
|
||||
ForecastedWarehouseFilter.props = {action: Object, setWarehouseInContext : Function};
|
||||
ForecastedWarehouseFilter.props = {action: Object, setWarehouseInContext : Function, warehouses: Array};
|
||||
|
||||
@@ -26,6 +26,7 @@ export class StockForecasted extends Component {
|
||||
this.context.active_id = this.props.action.params.active_id;
|
||||
this.reloadReport();
|
||||
}
|
||||
this.warehouses = useState([]);
|
||||
|
||||
onWillStart(this._getReportValues);
|
||||
}
|
||||
@@ -34,6 +35,11 @@ export class StockForecasted extends Component {
|
||||
await this._getResModel();
|
||||
const isTemplate = !this.resModel || this.resModel === 'product.template';
|
||||
this.reportModelName = `stock.forecasted_product_${isTemplate ? "template" : "product"}`;
|
||||
this.warehouses.splice(0, this.warehouses.length);
|
||||
this.warehouses.push(...await this.orm.searchRead('stock.warehouse', [],['id', 'name', 'code']));
|
||||
if (!this.context.warehouse) {
|
||||
this.updateWarehouse(this.warehouses[0].id);
|
||||
}
|
||||
const reportValues = await this.orm.call(this.reportModelName, "get_report_values", [], {
|
||||
context: this.context,
|
||||
docids: [this.productId],
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</t>
|
||||
<t t-set-slot="control-panel-bottom-right">
|
||||
<div class="btn-group o_search_options position-static" role="search">
|
||||
<ForecastedWarehouseFilter action="props.action" setWarehouseInContext.bind="updateWarehouse"/>
|
||||
<ForecastedWarehouseFilter action="props.action" warehouses="warehouses" setWarehouseInContext.bind="updateWarehouse"/>
|
||||
</div>
|
||||
</t>
|
||||
</ControlPanel>
|
||||
|
||||
Reference in New Issue
Block a user