[FIX] mail: fix default value of date in clock model
The first date should be the date of the record creation instead of the time the model was initialized. closes odoo/odoo#91372 X-original-commit: 2635b29193ba16d85f62aabd8bddd7d7692007f0 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com> Signed-off-by: Louis Wicket (wil) <wil@odoo.com>
This commit is contained in:
@@ -78,6 +78,9 @@ registerModel({
|
||||
if (!this.activity.dateDeadline) {
|
||||
return clear();
|
||||
}
|
||||
if (!this.clockWatcher.clock.date) {
|
||||
return clear();
|
||||
}
|
||||
const today = moment(this.clockWatcher.clock.date.getTime()).startOf('day');
|
||||
const momentDeadlineDate = moment(auto_str_to_date(this.activity.dateDeadline));
|
||||
// true means no rounding
|
||||
|
||||
@@ -16,6 +16,17 @@ registerModel({
|
||||
},
|
||||
},
|
||||
recordMethods: {
|
||||
/**
|
||||
* The date is set by a compute rather than using a default value. Thus,
|
||||
* the date set at first is the time of the record creation, and not the
|
||||
* time of the model initialization.
|
||||
*
|
||||
* @private
|
||||
* @returns {Date}
|
||||
*/
|
||||
_computeDate() {
|
||||
return new Date();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {integer}
|
||||
@@ -40,10 +51,11 @@ registerModel({
|
||||
},
|
||||
fields: {
|
||||
/**
|
||||
* A Date object set at the current date, updated at every tick.
|
||||
* A Date object set to the current date at the time the record is
|
||||
* created, then updated at every tick.
|
||||
*/
|
||||
date: attr({
|
||||
default: new Date(),
|
||||
compute: '_computeDate',
|
||||
}),
|
||||
/**
|
||||
* An integer representing the frequency in milliseconds at which `date`
|
||||
|
||||
@@ -189,6 +189,9 @@ registerModel({
|
||||
if (!this.message.date) {
|
||||
return clear();
|
||||
}
|
||||
if (!this.clockWatcher.clock.date) {
|
||||
return clear();
|
||||
}
|
||||
const now = moment(this.clockWatcher.clock.date.getTime());
|
||||
if (now.diff(this.message.date, 'seconds') < 45) {
|
||||
return this.env._t("now");
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import { insertAndReplace } from '@mail/model/model_field_command';
|
||||
import { start } from '@mail/../tests/helpers/test_utils';
|
||||
|
||||
import { patchDate } from '@web/../tests/helpers/utils';
|
||||
|
||||
QUnit.module('mail', {}, function () {
|
||||
QUnit.module('models', {}, function () {
|
||||
QUnit.module('clock_tests.js');
|
||||
@@ -24,5 +26,25 @@ QUnit.test('Deleting all the watchers of a clock should result in the deletion o
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('[technical] Before ticking for the first time, the clock should indicate the date of creation of the record.', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const { messaging } = await start();
|
||||
// The date is patched AFTER startup, so if the date field in Clock was set
|
||||
// at initialization (which we don't want), it will now look completely
|
||||
// different from the patched date.
|
||||
patchDate(2016, 8, 8, 14, 55, 15, 352);
|
||||
|
||||
const { clock } = messaging.models['ClockWatcher'].insert({
|
||||
clock: insertAndReplace({ frequency: 3600 * 1000 }),
|
||||
qunitTestOwner: insertAndReplace(),
|
||||
});
|
||||
assert.strictEqual(
|
||||
clock.date.getFullYear(), // no need to be more precise than the year
|
||||
2016,
|
||||
"before ticking for the first time, the clock should indicate the date of creation of the record."
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user