[FIX] calendar: allow creation of 'All day' events

Previously, creation of the 'All day' event was not possible in some
scenarios due to constraint error, even with proper configuration.

Scenario 1: (main spec of the task)
------------------------------------
- go to form view of calendar event
- create a new event
- enter future datetime in 'Starting at' field
- tick the 'All day' checkbox
- enter the end date which is greater than start date
- try to save the record

Scenario 2:
------------------------------------
- go to form view of calendar event
- create a new event
- enter future datetime in 'Starting at' field
- try to save the record

Scenario 3:
------------------------------------
- go to form view of calendar event
- create a new event
- enter any datetime in 'Starting at' field
- enter duration -1.00 hour
- tick the 'All day' checkbox
- enter the end date which is greater than start date
- try to save the record

In all above scenarios, user is not able to save the record even if
the there is no obvioius wrong configuration.

All of the above bugs are result of a recent refactoring[1]
where some redundant fields were removed.

The first two scenarios are result of 'stop' date not being computed
proerly based on 'start' in case the duration is set to '00:00'
(which is default duration) while the third one is due to lack of
proper check in the constraint after the fields used to validate
starting and ending dates were removed.

This commit fixes the issue by improving the compute method and by
ensuring proper validation in the constraint.

[1] - https://github.com/odoo/odoo/pull/42031/commits/6bafd7c677d016e82473f01bd0a3381ac3b24bbd

Task Id: 2299212
PR #54673

closes odoo/odoo#56411

X-original-commit: cc5d090c267bac892d2e8200f8e55de88c5a0af2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: D J <dja@odoo.com>
This commit is contained in:
asa-odoo
2020-08-24 13:07:50 +00:00
committed by Dharmraj Jhala
co-authored by D J
parent 4fd328b3e3
commit c66d10a971
+3 -3
View File
@@ -325,7 +325,7 @@ class Meeting(models.Model):
# its recomputation. To avoid this we manually mark the field as computed.
duration_field = self._fields['duration']
self.env.remove_to_compute(duration_field, self)
for event in self.filtered('duration'):
for event in self:
# Round the duration (in hours) to the minute to avoid weird situations where the event
# stops at 4:19:59, later displayed as 4:19.
event.stop = event.start + timedelta(minutes=round((event.duration or 1.0) * 60))
@@ -356,7 +356,7 @@ class Meeting(models.Model):
@api.constrains('start', 'stop', 'start_date', 'stop_date')
def _check_closing_date(self):
for meeting in self:
if meeting.start and meeting.stop and meeting.stop < meeting.start:
if not meeting.allday and meeting.start and meeting.stop and meeting.stop < meeting.start:
raise ValidationError(
_('The ending date and time cannot be earlier than the starting date and time.') + '\n' +
_("Meeting '%(name)s' starts '%(start_datetime)s' and ends '%(end_datetime)s'",
@@ -365,7 +365,7 @@ class Meeting(models.Model):
end_datetime=meeting.stop
)
)
if meeting.start_date and meeting.stop_date and meeting.stop_date < meeting.start_date:
if meeting.allday and meeting.start_date and meeting.stop_date and meeting.stop_date < meeting.start_date:
raise ValidationError(
_('The ending date cannot be earlier than the starting date.') + '\n' +
_("Meeting '%(name)s' starts '%(start_datetime)s' and ends '%(end_datetime)s'",