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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
1914
Lượt xem
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 7 23
|
3912 | ||
|
2
thg 11 22
|
7101 | ||
How to add my widget to a form view
Đã xử lý
|
|
1
thg 11 19
|
7392 | |
|
0
thg 9 23
|
2176 | ||
|
1
thg 4 24
|
2098 |