diff options
| author | asa-odoo <asa@odoo.com> | 2020-07-16 13:07:48 +0000 |
|---|---|---|
| committer | Dharmraj Jhala <dja@odoo.com> | 2020-08-24 12:43:34 +0000 |
| commit | d2791395d4063e9080efe3a1dd577c28d27e24bb (patch) | |
| tree | 3bd82da1f6a2776328f6e03a3677ca6ca01467cf /addons/calendar/models | |
| parent | 970335d4bb4cd470e488ce5cc6dff042e56c7cb8 (diff) | |
[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#56404
X-original-commit: cc5d090c267bac892d2e8200f8e55de88c5a0af2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: D J <dja@odoo.com>
Diffstat (limited to 'addons/calendar/models')
| -rw-r--r-- | addons/calendar/models/calendar_event.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/addons/calendar/models/calendar_event.py b/addons/calendar/models/calendar_event.py index 874c09c99f0..903e5a772a7 100644 --- a/addons/calendar/models/calendar_event.py +++ b/addons/calendar/models/calendar_event.py @@ -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'", |
