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);
});
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Bogføring
- Lager
- PoS
- Project
- MRP
Dette spørgsmål er blevet anmeldt
1
Svar
1893
Visninger
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Tilmeld digRelated Posts | Besvarelser | Visninger | Aktivitet | |
---|---|---|---|---|
|
2
jul. 23
|
3901 | ||
|
2
nov. 22
|
7084 | ||
|
1
nov. 19
|
7386 | ||
|
0
sep. 23
|
2174 | ||
|
1
apr. 24
|
2085 |