[FIX] mrp: BoM overview context

To reproduce this bug, you need to create a RFQ, add a product with
variants and click on the button to view the quantity forecast.
Then, click on Manufacturing forecast. The BoM overview does not
have the correct variant selected in the Select.

To fix this, simply added an active_product_id to the context, used it
to get the correct BoM data ans then display it in the select.

Task-3184663

X-original-commit: a4ab49d5e41debfe6b2d46840dfffe1008f0f1ec
Part-of: odoo/odoo#121783
This commit is contained in:
Martin Maes
2023-05-23 16:31:51 +02:00
parent 15f52bfb0d
commit d2058c39c2
5 changed files with 16 additions and 3 deletions
@@ -48,6 +48,9 @@ export class BomOverviewComponent extends Component {
//---- Data ----
async initBomData() {
const variantId = this.props.action.context.active_product_id;
this.state.currentVariantId = variantId ? variantId : false;
const bomData = await this.getBomData();
this.state.bomQuantity = bomData["bom_qty"];
this.state.showOptions.uom = bomData["is_uom_applied"];
@@ -55,7 +58,7 @@ export class BomOverviewComponent extends Component {
this.variants = bomData["variants"];
this.showVariants = bomData["is_variant_applied"];
if (this.showVariants) {
this.state.currentVariantId = Object.keys(this.variants)[0];
this.state.currentVariantId ||= Object.keys(this.variants)[0];
}
this.state.precision = bomData["precision"];
}
@@ -105,7 +108,7 @@ export class BomOverviewComponent extends Component {
await this.getBomData();
}
}
async onChangeVariant(variantId) {
if (this.state.currentVariantId != variantId) {
this.state.currentVariantId = variantId;
@@ -6,6 +6,7 @@
bomQuantity="state.bomQuantity"
uomName="uomName"
variants="variants"
data="state.bomData"
showOptions="state.showOptions"
showVariants="showVariants"
currentWarehouse="state.currentWarehouse"
@@ -4,6 +4,7 @@ import { ControlPanel } from "@web/search/control_panel/control_panel";
import { BomOverviewDisplayFilter } from "../bom_overview_display_filter/mrp_bom_overview_display_filter";
import { Dropdown } from "@web/core/dropdown/dropdown";
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
import { Many2XAutocomplete } from "@web/views/fields/relational_utils";
const { Component } = owl;
@@ -29,6 +30,11 @@ export class BomOverviewControlPanel extends Component {
clickUnfold() {
this.env.overviewBus.trigger("unfold-all");
}
getDomain() {
const keys = Object.keys(this.props.variants);
return [['id', 'in', keys]];
}
}
BomOverviewControlPanel.template = "mrp.BomOverviewControlPanel";
@@ -37,12 +43,14 @@ BomOverviewControlPanel.components = {
DropdownItem,
ControlPanel,
BomOverviewDisplayFilter,
Many2XAutocomplete,
};
BomOverviewControlPanel.props = {
bomQuantity: Number,
showOptions: Object,
showVariants: { type: Boolean, optional: true },
variants: { type: Object, optional: true },
data: { type: Object, optional: true },
showUom: { type: Boolean, optional: true },
uomName: { type: String, optional: true },
currentWarehouse: Object,
@@ -29,7 +29,7 @@
<div class="input-group">
<div class="input-group-text">Variant</div>
<select class="o_input form-control" t-on-change="(ev) => this.props.changeVariant(ev.target.value)">
<option t-foreach="props.variants" t-as="variant" t-att-value="variant" t-key="variant">
<option t-foreach="props.variants" t-as="variant" t-att-value="variant" t-key="variant" t-att-selected="variant == this.props.data.link_id">
<t t-esc="props.variants[variant]"/>
</option>
</select>
@@ -18,6 +18,7 @@ patch(ForecastedButtons.prototype, 'mrp.ForecastedButtons',{
return this.actionService.doAction("mrp.action_report_mrp_bom", {
additionalContext: {
active_id: this.bomId,
active_product_id: this.productId,
},
});
}