summaryrefslogtreecommitdiff
path: root/addons/calendar/models
diff options
context:
space:
mode:
authorAdrien Widart <awt@odoo.com>2021-04-12 08:11:24 +0000
committerAdrien Widart <awt@odoo.com>2021-04-12 08:11:24 +0000
commit02886f65e9026e1f7617c8b23c3d87edd358b168 (patch)
tree521de73106af181e52389ddcb28bb74ef7d336b5 /addons/calendar/models
parentf05dd3596ac22c5a8fb8c3feff7bf978a7698c73 (diff)
[FIX] calendar: extend month_day SQL constraint
When creating a recurrent event, an SQL contraint requires the field `day` to be correcly defined. However, if the recurrence rule is like "every last Monday of the month", the field becomes useless and may be undefined. As a result, the SQL constraint will prevent the creation of such a recurrent event. For example, the situation will happen when the user creates this recurrent event on Microsoft Calendar and then tries to sync with Odoo. The recurrent event data will contain: ```python { 'rrule_type': 'monthly', 'day': 0, 'byday': '2', 'month_by': 'day', 'weekday': 'TU', # ... } ``` OPW-2439814 closes odoo/odoo#69106 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Diffstat (limited to 'addons/calendar/models')
-rw-r--r--addons/calendar/models/calendar_recurrence.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/addons/calendar/models/calendar_recurrence.py b/addons/calendar/models/calendar_recurrence.py
index b25cdb9a34c..5d428ebc70b 100644
--- a/addons/calendar/models/calendar_recurrence.py
+++ b/addons/calendar/models/calendar_recurrence.py
@@ -118,7 +118,13 @@ class RecurrenceRule(models.Model):
until = fields.Date('Repeat Until')
_sql_constraints = [
- ('month_day', "CHECK (rrule_type != 'monthly' OR month_by != 'day' OR day >= 1 AND day <= 31)", "The day must be between 1 and 31"),
+ ('month_day',
+ "CHECK (rrule_type != 'monthly' "
+ "OR month_by != 'day' "
+ "OR day >= 1 AND day <= 31 "
+ "OR weekday in %s AND byday in %s)"
+ % (tuple(wd[0] for wd in WEEKDAY_SELECTION), tuple(bd[0] for bd in BYDAY_SELECTION)),
+ "The day must be between 1 and 31"),
]
@api.depends('rrule')