[FIX] web: correct count of day
Introduced at 2f67881d45
Taken an event with
start_date: 2020-10-01
stop_date: 2020-10-02
allday: True
The date was displayed as "01/10 - 03/10 (2 days)" instead of "01/10 -
02/10 (2 days)"
closes odoo/odoo#60254
X-original-commit: 5eed28cf927bc504b103cc872712ab0e49830a38
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
@@ -750,10 +750,15 @@ return AbstractRenderer.extend({
|
||||
* @param {moment} start
|
||||
* @param {moment} end
|
||||
* @param {boolean} showDayName
|
||||
* @param {boolean} allDay
|
||||
*/
|
||||
_getFormattedDate: function (start, end, showDayName) {
|
||||
_getFormattedDate: function (start, end, showDayName, allDay) {
|
||||
const isSameDayEvent = start.clone().add(1, 'minute')
|
||||
.isSame(end.clone().subtract(1, 'minute'), 'day');
|
||||
if (allDay) {
|
||||
// cancel correction done in _recordToCalendarEvent
|
||||
end = end.clone().subtract(1, 'day');
|
||||
}
|
||||
if (!isSameDayEvent && start.isSame(end, 'month')) {
|
||||
// Simplify date-range if an event occurs into the same month (eg. '4-5 August 2019')
|
||||
return start.clone().format('MMMM D') + '-' + end.clone().format('D, YYYY');
|
||||
@@ -806,7 +811,6 @@ return AbstractRenderer.extend({
|
||||
}
|
||||
|
||||
if (!this.hideDate) {
|
||||
context.eventDate.date = this._getFormattedDate(start, end, true);
|
||||
|
||||
if (eventData.extendedProps.record.allday && isSameDayEvent) {
|
||||
context.eventDate.duration = _t("All day");
|
||||
@@ -815,6 +819,8 @@ return AbstractRenderer.extend({
|
||||
var days = moment.duration(end.diff(start)).days();
|
||||
context.eventDate.duration = daysLocaleData.relativeTime(days, true, 'dd');
|
||||
}
|
||||
|
||||
context.eventDate.date = this._getFormattedDate(start, end, true, eventData.extendedProps.record.allday);
|
||||
}
|
||||
|
||||
return context;
|
||||
@@ -874,7 +880,7 @@ return AbstractRenderer.extend({
|
||||
for (const event of events) {
|
||||
const start = moment(event.extendedProps.r_start);
|
||||
const end = moment(event.extendedProps.r_end);
|
||||
const key = this._getFormattedDate(start, end, false);
|
||||
const key = this._getFormattedDate(start, end, false, event.extendedProps.record.allday);
|
||||
if (!(key in groupedEvents)) {
|
||||
groupedEvents[key] = [];
|
||||
groupKeys.push({
|
||||
|
||||
@@ -334,7 +334,7 @@ QUnit.module('Views', {
|
||||
});
|
||||
|
||||
QUnit.test('create and change events', async function (assert) {
|
||||
assert.expect(26);
|
||||
assert.expect(28);
|
||||
|
||||
var calendar = await createCalendarView({
|
||||
View: CalendarView,
|
||||
@@ -462,6 +462,14 @@ QUnit.module('Views', {
|
||||
assert.hasAttrValue($newevent2.closest('.fc-event-container'),
|
||||
'colspan', "2","the new record should have 2 days");
|
||||
|
||||
await testUtils.dom.click(calendar.$('.fc-event:contains(new event in quick create 2) .fc-content'));
|
||||
var $popover_description = calendar.$('.o_cw_popover .o_cw_body .list-group-item');
|
||||
assert.strictEqual($popover_description.children()[1].textContent,'December 20-21, 2016',
|
||||
"The popover description should indicate the correct range");
|
||||
assert.strictEqual($popover_description.children()[2].textContent,'(2 days)',
|
||||
"The popover description should indicate 2 days");
|
||||
await testUtils.dom.click(calendar.$('.o_cw_popover .fa-close'));
|
||||
|
||||
// delete the a record
|
||||
|
||||
await testUtils.dom.click(calendar.$('.fc-event:contains(event 4) .fc-content'));
|
||||
|
||||
Reference in New Issue
Block a user