From cd52000113c6efc3d741985860f445b564f1026f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Tue, 31 Mar 2020 07:10:51 +0000 Subject: [PATCH] [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) Signed-off-by: lul-odoo --- .../static/src/js/timesheet_uom.js | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/hr_timesheet/static/src/js/timesheet_uom.js b/addons/hr_timesheet/static/src/js/timesheet_uom.js index 9c7f9a869f7..6e6a3f2e953 100644 --- a/addons/hr_timesheet/static/src/js/timesheet_uom.js +++ b/addons/hr_timesheet/static/src/js/timesheet_uom.js @@ -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) {