跳至内容
菜单
此问题已终结
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);
});


形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
7月 23
3217
2
11月 22
6680
1
11月 19
7015
0
9月 23
1717
1
4月 24
1318