[FIX] mrp: fix forecast for product template

Following 873d6d9, the forecast would now redirect correctly to the
corresponding bom when a `product.product` was used.
The issue is that `bom_variant_ids` doesn't exist on `product.template`,
raising a traceback when the forecast was accessed through the product
themselves instead of their variants

closes odoo/odoo#115776

X-original-commit: 93f6bf8dc5319082579a2b4ecbc48b482b81cc9d
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
This commit is contained in:
clesgow
2023-03-20 15:31:35 +01:00
parent 0cef635102
commit 93446d0cf7
@@ -8,8 +8,9 @@ patch(ForecastedButtons.prototype, 'mrp.ForecastedButtons',{
setup() {
this._super.apply();
onWillStart(async () =>{
const res = (await this.orm.call(this.resModel, 'read', [this.productId], {fields: ['bom_ids', 'variant_bom_ids']}))[0];
this.bomId = res.variant_bom_ids[0] || res.bom_ids[0];
const fields = this.resModel === "product.template" ? ['bom_ids'] : ['bom_ids', 'variant_bom_ids'];
const res = (await this.orm.call(this.resModel, 'read', [this.productId], { fields }))[0];
this.bomId = res.variant_bom_ids ? res.variant_bom_ids[0] || res.bom_ids[0] : res.bom_ids[0];
});
},