From 4f9afa6a645d24d86b10649e52f777beb40b2a09 Mon Sep 17 00:00:00 2001 From: mreficent Date: Tue, 25 Sep 2018 13:33:03 +0000 Subject: [PATCH 1/7] [REF] calendar: rename calendar.alarm type to alarm_type Purpose of this commit is to rename type column to something matching the the real business use of the field. That way it is easier to find and grep in the code. It also lessens potential conflicts with type build-in python function. It also lessens conflicts when using the field in JS as type is a build-in attribute. Renaming type column is a long-living issue. We choose to do it at the beginning of the v13 development to catch errors as soon as possible. This commit is linked to task ID 1896245. It is also a subpart of community PR #27599. --- addons/calendar/data/calendar_data.xml | 14 +++++++------- addons/calendar/models/calendar.py | 12 ++++++------ addons/calendar/tests/test_calendar.py | 2 +- addons/calendar/views/calendar_views.xml | 4 ++-- addons/calendar_sms/models/calendar.py | 2 +- addons/google_calendar/models/google_calendar.py | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/addons/calendar/data/calendar_data.xml b/addons/calendar/data/calendar_data.xml index 29083593e32..a6bdafed7a6 100644 --- a/addons/calendar/data/calendar_data.xml +++ b/addons/calendar/data/calendar_data.xml @@ -11,43 +11,43 @@ 15 Minute(s) minutes - notification + notification 30 Minute(s) minutes - notification + notification 1 Hour(s) hours - notification + notification 2 Hour(s) hours - notification + notification 1 Day(s) days - notification + notification 3 Hour(s), by e-mail hours - email + email 6 Hour(s), by e-mail hours - email + email \ No newline at end of file diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py index 45647cd49a5..7a3d35fbd12 100644 --- a/addons/calendar/models/calendar.py +++ b/addons/calendar/models/calendar.py @@ -251,7 +251,7 @@ class AlarmManager(models.AbstractModel): FROM calendar_alarm_calendar_event_rel AS rel LEFT JOIN calendar_alarm AS alarm ON alarm.id = rel.calendar_alarm_id - WHERE alarm.type = %s + WHERE alarm.alarm_type = %s GROUP BY rel.calendar_event_id """ base_request = """ @@ -340,7 +340,7 @@ class AlarmManager(models.AbstractModel): # TODO: remove event_maxdelta and if using it if one_date - timedelta(minutes=(missing and 0 or event_maxdelta)) < datetime.datetime.now() + timedelta(seconds=in_the_next_X_seconds): # if an alarm is possible for this date for alarm in event.alarm_ids: - if alarm.type == alarm_type and \ + if alarm.alarm_type == alarm_type and \ one_date - timedelta(minutes=(missing and 0 or alarm.duration_minutes)) < datetime.datetime.now() + timedelta(seconds=in_the_next_X_seconds) and \ (not after or one_date - timedelta(minutes=alarm.duration_minutes) > fields.Datetime.from_string(after)): alert = { @@ -438,7 +438,7 @@ class AlarmManager(models.AbstractModel): alarm = self.env['calendar.alarm'].browse(alert['alarm_id']) result = False - if alarm.type == 'email': + if alarm.alarm_type == 'email': result = meeting.attendee_ids.filtered(lambda r: r.state != 'declined')._send_mail_to_attendees('calendar.calendar_template_meeting_reminder', force_send=True) return result @@ -446,7 +446,7 @@ class AlarmManager(models.AbstractModel): alarm = self.env['calendar.alarm'].browse(alert['alarm_id']) meeting = self.env['calendar.event'].browse(alert['event_id']) - if alarm.type == 'notification': + if alarm.alarm_type == 'notification': message = meeting.display_time delta = alert['notify_at'] - datetime.datetime.now() @@ -490,7 +490,7 @@ class Alarm(models.Model): _interval_selection = {'minutes': 'Minute(s)', 'hours': 'Hour(s)', 'days': 'Day(s)'} name = fields.Char('Name', translate=True, required=True) - type = fields.Selection([('notification', 'Notification'), ('email', 'Email')], 'Type', required=True, default='email') + alarm_type = fields.Selection([('notification', 'Notification'), ('email', 'Email')], string='Type', required=True, default='email', oldname='type') duration = fields.Integer('Remind Before', required=True, default=1) interval = fields.Selection(list(_interval_selection.items()), 'Unit', required=True, default='hours') duration_minutes = fields.Integer('Duration in minutes', compute='_compute_duration_minutes', store=True, help="Duration in minutes") @@ -505,7 +505,7 @@ class Alarm(models.Model): cron = self.env['ir.model.data'].sudo().get_object('calendar', 'ir_cron_scheduler_alarm') except ValueError: return False - return cron.toggle(model=self._name, domain=[('type', '=', 'email')]) + return cron.toggle(model=self._name, domain=[('alarm_type', '=', 'email')]) @api.model def create(self, values): diff --git a/addons/calendar/tests/test_calendar.py b/addons/calendar/tests/test_calendar.py index fbf86ace9e1..c671d1f7eb9 100644 --- a/addons/calendar/tests/test_calendar.py +++ b/addons/calendar/tests/test_calendar.py @@ -93,7 +93,7 @@ class TestCalendar(TransactionCase): 'name': '1 Day before event starts', 'duration': 1, 'interval': 'days', - 'type': 'notification' + 'alarm_type': 'notification' }) # Now I will assign this reminder to all day event| diff --git a/addons/calendar/views/calendar_views.xml b/addons/calendar/views/calendar_views.xml index f8b5487c1e9..a59e24fb855 100644 --- a/addons/calendar/views/calendar_views.xml +++ b/addons/calendar/views/calendar_views.xml @@ -26,7 +26,7 @@ - + @@ -41,7 +41,7 @@ - +