[FIX] hr_timesheet: Fetch server time before render
1) Add a hidden optional field to the timesheet tree view. 2) Try to display that field by checking the checkbox. => the column appears then directly disappears. Asynchronous calls (here: fetching the server time) should always be in the `willStart` method. Task 2204084 closes odoo/odoo#48775 X-original-commit: 39fa08c4d6a1b467b520bdd0f75950d2c33f4a2e Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com> Signed-off-by: lul-odoo <LucasLefevre@users.noreply.github.com>
This commit is contained in:
@@ -86,32 +86,36 @@ const FieldTimesheetTime = basicFields.FieldFloatTime.extend({
|
||||
this.parseOptions.factor = session.timesheet_uom_factor;
|
||||
}
|
||||
},
|
||||
_render: async function () {
|
||||
this._super.apply(this, arguments);
|
||||
willstart() {
|
||||
const timePromise = this._rpc({
|
||||
model: 'timer.timer',
|
||||
method: 'get_server_time',
|
||||
args: []
|
||||
}).then((time) => {
|
||||
this.serverTime = time;
|
||||
});
|
||||
return Promise.all([
|
||||
this._super(...arguments),
|
||||
timePromise,
|
||||
]);
|
||||
},
|
||||
|
||||
_render: async function () {
|
||||
await this._super.apply(this, arguments);
|
||||
// Check if the timer_start exists and it's not false
|
||||
// In other word, when user clicks on play button, this button
|
||||
// launches the "action_timer_start".
|
||||
if (this.recordData.timer_start && !this.recordData.timer_pause) {
|
||||
const time = await this._rpc({
|
||||
model: 'timer.timer',
|
||||
method: 'get_server_time',
|
||||
args: []
|
||||
});
|
||||
this.time = Timer.createTimer(this.recordData.unit_amount, this.recordData.timer_start, time);
|
||||
return this._startTimeCounter();
|
||||
} else if (this.mode === "edit") {
|
||||
return this._renderEdit();
|
||||
} else if (this.mode === 'readonly') {
|
||||
return this._renderReadonly();
|
||||
this.time = Timer.createTimer(this.recordData.unit_amount, this.recordData.timer_start, this.serverTime);
|
||||
this._startTimeCounter();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
destroy: function () {
|
||||
this._super.apply(this, arguments);
|
||||
clearTimeout(this.timer);
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
_startTimeCounter: function () {
|
||||
if (this.time) {
|
||||
|
||||
Reference in New Issue
Block a user