Skip to Content
Menu
This question has been flagged
This is my odoo12 javascript code for timer widget i want to use that widget for odoo16 aswell but i am getting an that i am unable to run that code can anybody guide me that what should i do run this code in Odoo16 as well. 
I have a float type field that i want to use that widget on that field.

odoo.define('employee_tracking.timer', function (require) {
"use strict";
var AbstractField = require('web.AbstractField');
var core = require('web.core');
var field_registry = require('web.field_registry');
var time = require('web.time');
var FieldManagerMixin = require('web.FieldManagerMixin');
var _t = core._t;
var TimeCounter = AbstractField.extend({
willStart: function () {
var self = this;
if(this.model=='emp_track.project'){
var my_domain = [['emp_task_id', '=', this.res_id]]
}
if(this.model=='qa_track.project'){
var my_domain = [['qa_task_id', '=', this.res_id]]
}
var def = this._rpc({
model: 'account.analytic.line',
method: 'search_read',
domain: my_domain,
}).then(function (result) {
if (self.mode === 'readonly') {
var currentDate = new Date();
self.duration = 0;
_.each(result, function (data) {
self.duration += data.date_end ?
self._getDateDifference(data.date_start, data.date_end) :
self._getDateDifference(time.auto_str_to_date(data.date_start), currentDate);
});
}
});
return $.when(this._super.apply(this, arguments), def);
},
destroy: function () {
this._super.apply(this, arguments);
clearInterval(this.timer);
},
isSet: function () {
return true;
},
_getDateDifference: function (dateStart, dateEnd) {
return moment(dateEnd).diff(moment(dateStart));
},
_render: function () {
this._startTimeCounter();
},
_startTimeCounter: function () {
var self = this;
clearInterval(this.timer);
if (this.record.data.is_user_working) {
this.timer = setTimeout(function () {
self.duration += 1000;
self._startTimeCounter();
}, 1000);
} else {
clearInterval(this.timer);
}
this.$el.html($('' + moment.utc(this.duration).format("HH:mm:ss") + ''));
},
});
field_registry.add('timesheet_uoms', TimeCounter);
});


Avatar
Discard
Best Answer

Hello , 

Please add 
init: function () {

this._super.apply(this, arguments);

​this.timer = this.record.data.timer;

},
and then check . 
may be it work for you. 
Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 23
3206
2
Nov 22
6673
1
Nov 19
7009
0
Sep 23
1703
1
Apr 24
1313