diff --git a/addons/mrp/static/src/js/mrp.js b/addons/mrp/static/src/js/mrp.js
index 0bddcc64303..e266b470fe0 100644
--- a/addons/mrp/static/src/js/mrp.js
+++ b/addons/mrp/static/src/js/mrp.js
@@ -1,100 +1,7 @@
/** @odoo-module **/
import fields from 'web.basic_fields';
-import fieldUtils from 'web.field_utils';
import field_registry from 'web.field_registry';
-import time from 'web.time';
-
-var TimeCounter = fields.FieldFloatTime.extend({
-
- init: function () {
- this._super.apply(this, arguments);
- this.duration = this.record.data.duration;
- },
-
- willStart: function () {
- var self = this;
- var def = this._rpc({
- model: 'mrp.workcenter.productivity',
- method: 'search_read',
- domain: [
- ['workorder_id', '=', this.record.data.id],
- ['date_end', '=', false],
- ],
- }).then(function (result) {
- var currentDate = new Date();
- var duration = 0;
- if (result.length > 0) {
- duration += self._getDateDifference(time.auto_str_to_date(result[0].date_start), currentDate);
- }
- var minutes = duration / 60 >> 0;
- var seconds = duration % 60;
- self.duration += minutes + seconds / 60;
- if (self.mode === 'edit') {
- self.value = self.duration;
- }
- });
- return Promise.all([this._super.apply(this, arguments), def]);
- },
-
- destroy: function () {
- this._super.apply(this, arguments);
- clearTimeout(this.timer);
- },
-
- //--------------------------------------------------------------------------
- // Public
- //--------------------------------------------------------------------------
-
- /**
- * @override
- */
- isSet: function () {
- return true;
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * Compute the difference between two dates.
- *
- * @private
- * @param {string} dateStart
- * @param {string} dateEnd
- * @returns {integer} the difference in millisecond
- */
- _getDateDifference: function (dateStart, dateEnd) {
- return moment(dateEnd).diff(moment(dateStart), 'seconds');
- },
- /**
- * @override
- */
- _renderReadonly: function () {
- if (this.record.data.is_user_working) {
- this._startTimeCounter();
- } else {
- this._super.apply(this, arguments);
- }
- },
- /**
- * @private
- */
- _startTimeCounter: function () {
- var self = this;
- clearTimeout(this.timer);
- if (this.record.data.is_user_working) {
- this.timer = setTimeout(function () {
- self.duration += 1/60;
- self._startTimeCounter();
- }, 1000);
- } else {
- clearTimeout(this.timer);
- }
- this.$el.text(fieldUtils.format.float_time(this.duration));
- },
-});
var FieldEmbedURLViewer = fields.FieldChar.extend({
@@ -216,11 +123,6 @@ var FieldEmbedURLViewer = fields.FieldChar.extend({
},
});
-
-field_registry
- .add('mrp_time_counter', TimeCounter)
- .add('embed_viewer', FieldEmbedURLViewer);
-
-fieldUtils.format.mrp_time_counter = fieldUtils.format.float_time;
+field_registry.add('embed_viewer', FieldEmbedURLViewer);
export default FieldEmbedURLViewer;
diff --git a/addons/mrp/static/src/widgets/timer.js b/addons/mrp/static/src/widgets/timer.js
new file mode 100644
index 00000000000..811d69576e4
--- /dev/null
+++ b/addons/mrp/static/src/widgets/timer.js
@@ -0,0 +1,50 @@
+/** @odoo-module **/
+
+import { registry } from "@web/core/registry";
+import { formatFloatTime } from "@web/views/fields/formatters";
+
+const { Component, useState, onWillUpdateProps, onWillStart, onWillDestroy } = owl;
+
+export class MrpTimer extends Component {
+ setup() {
+ super.setup();
+ this.state = useState({
+ duration:
+ this.props.duration !== undefined
+ ? this.props.duration
+ : this.props.record.data.duration,
+ });
+
+ const newLocal = this;
+ this.ongoing =
+ this.props.ongoing !== undefined
+ ? newLocal.props.ongoing
+ : this.props.record.data.is_user_working;
+
+ onWillStart(() => this._runTimer());
+ onWillUpdateProps((nextProps) => {
+ this.ongoing = nextProps.ongoing;
+ this._runTimer();
+ });
+ onWillDestroy(() => clearTimeout(this.timer));
+ }
+
+ get duration() {
+ // formatFloatTime except 1,5 = 1h30min but in mrp case 1,5 = 1min30
+ return formatFloatTime(this.state.duration / 60, { displaySeconds: true });
+ }
+
+ _runTimer() {
+ if (this.ongoing) {
+ this.timer = setTimeout(() => {
+ this.state.duration += 1 / 60;
+ this._runTimer();
+ }, 1000);
+ }
+ }
+}
+
+MrpTimer.supportedTypes = ["float"];
+MrpTimer.template = "mrp.MrpTimer";
+
+registry.category("fields").add("mrp_timer", MrpTimer);
diff --git a/addons/mrp/static/src/widgets/timer.xml b/addons/mrp/static/src/widgets/timer.xml
new file mode 100644
index 00000000000..9b8fb491ffe
--- /dev/null
+++ b/addons/mrp/static/src/widgets/timer.xml
@@ -0,0 +1,6 @@
+
+