[FIX] mrp: mrp timer traceback

To reproduce:
1. Open the shop floor
2. Open assembly station 1

Current behavior:
The MRP timer immediately causes a traceback when being rendered in the
shop floor.
After the changes in [1], the duration was changed to a property on the
timer component.
However, the duration is set on multiple occasions, including in the
onWillStart function of the timer component, resulting in the traceback.

Expected behavior:
This commit addresses this by reverting the changes from [1] for the
duration on the mrp timer, and using useRecordObserver instead of
onWillUpdateProps.

[1] https://github.com/odoo/odoo/pull/135842

Community PR: https://github.com/odoo/odoo/pull/137561

closes odoo/odoo#137561

Signed-off-by: Steve Van Essche <svs@odoo.com>
This commit is contained in:
Pieter Claeys (clpi)
2023-10-12 16:12:06 +00:00
parent cbab7b013e
commit 16bea0dca7
+6 -11
View File
@@ -4,6 +4,7 @@ import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
import { parseFloatTime } from "@web/views/fields/parsers";
import { useInputField } from "@web/views/fields/input_field_hook";
import { useRecordObserver } from "@web/model/relational_model/utils";
import { standardFieldProps } from "@web/views/fields/standard_field_props";
import { Component, useState, onWillUpdateProps, onWillStart, onWillDestroy } from "@odoo/owl";
@@ -94,18 +95,17 @@ class MrpTimerField extends Component {
parse: (v) => parseFloatTime(v),
});
onWillStart(async () => {
if (
!this.props.record.model.useSampleModel &&
this.props.record.data.state == "progress"
) {
useRecordObserver(async (record) => {
if (!this.props.record.model.useSampleModel && record.data.state === "progress") {
this.duration = await this.orm.call(
"mrp.workorder",
"get_duration",
[this.props.record.resId]
);
} else {
this.duration = record.data[this.props.name];
}
});
})
onWillDestroy(() => clearTimeout(this.timer));
}
@@ -120,11 +120,6 @@ class MrpTimerField extends Component {
get ongoing() {
return this.props.record.data.is_user_working;
}
get duration() {
// duration is expected to be given in minutes
return this.props.record.data[this.props.name];
}
}
export const mrpTimerField = {