[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.
This commit is contained in:
mreficent
2018-10-19 09:12:55 +00:00
committed by Thibault Delavallée
parent 64971170d2
commit 4f9afa6a64
6 changed files with 20 additions and 20 deletions
+7 -7
View File
@@ -11,43 +11,43 @@
<field name="name">15 Minute(s)</field>
<field name="duration" eval="15" />
<field name="interval">minutes</field>
<field name="type">notification</field>
<field name="alarm_type">notification</field>
</record>
<record id="alarm_notif_2" model="calendar.alarm">
<field name="name">30 Minute(s)</field>
<field name="duration" eval="30" />
<field name="interval">minutes</field>
<field name="type">notification</field>
<field name="alarm_type">notification</field>
</record>
<record id="alarm_notif_3" model="calendar.alarm">
<field name="name">1 Hour(s)</field>
<field name="duration" eval="1" />
<field name="interval">hours</field>
<field name="type">notification</field>
<field name="alarm_type">notification</field>
</record>
<record id="alarm_notif_4" model="calendar.alarm">
<field name="name">2 Hour(s)</field>
<field name="duration" eval="2" />
<field name="interval">hours</field>
<field name="type">notification</field>
<field name="alarm_type">notification</field>
</record>
<record id="alarm_notif_5" model="calendar.alarm">
<field name="name">1 Day(s)</field>
<field name="duration" eval="1" />
<field name="interval">days</field>
<field name="type">notification</field>
<field name="alarm_type">notification</field>
</record>
<record id="alarm_mail_1" model="calendar.alarm">
<field name="name">3 Hour(s), by e-mail</field>
<field name="duration" eval="3" />
<field name="interval">hours</field>
<field name="type">email</field>
<field name="alarm_type">email</field>
</record>
<record id="alarm_mail_2" model="calendar.alarm">
<field name="name">6 Hour(s), by e-mail</field>
<field name="duration" eval="6" />
<field name="interval">hours</field>
<field name="type">email</field>
<field name="alarm_type">email</field>
</record>
</data>
</odoo>
+6 -6
View File
@@ -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):
+1 -1
View File
@@ -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|
+2 -2
View File
@@ -26,7 +26,7 @@
<field name="arch" type="xml">
<tree string="Calendar Alarm" editable="bottom">
<field name="name"/>
<field name="type"/>
<field name="alarm_type"/>
<field name="duration"/>
<field name="interval"/>
</tree>
@@ -41,7 +41,7 @@
<group>
<group>
<field name="name"/>
<field name="type" groups="base.group_no_one"/>
<field name="alarm_type" groups="base.group_no_one"/>
</group>
<group>
<label for="duration"/>
+1 -1
View File
@@ -28,7 +28,7 @@ class CalendarEvent(models.Model):
class CalendarAlarm(models.Model):
_inherit = 'calendar.alarm'
type = fields.Selection(selection_add=[('sms', 'SMS Text Message')])
alarm_type = fields.Selection(selection_add=[('sms', 'SMS Text Message')])
class AlarmManager(models.AbstractModel):
@@ -215,7 +215,7 @@ class GoogleCalendar(models.AbstractModel):
reminders = []
for alarm in event.alarm_ids:
reminders.append({
"method": "email" if alarm.type == "email" else "popup",
"method": "email" if alarm.alarm_type == "email" else "popup",
"minutes": alarm.duration_minutes
})
data = {
@@ -458,13 +458,13 @@ class GoogleCalendar(models.AbstractModel):
for google_alarm in single_event_dict.get('reminders', {}).get('overrides', []):
alarm = CalendarAlarm.search(
[
('type', '=', google_alarm['method'] if google_alarm['method'] == 'email' else 'notification'),
('alarm_type', '=', google_alarm['method'] if google_alarm['method'] == 'email' else 'notification'),
('duration_minutes', '=', google_alarm['minutes'])
], limit=1
)
if not alarm:
data = {
'type': google_alarm['method'] if google_alarm['method'] == 'email' else 'notification',
'alarm_type': google_alarm['method'] if google_alarm['method'] == 'email' else 'notification',
'duration': google_alarm['minutes'],
'interval': 'minutes',
'name': "%s minutes - %s" % (google_alarm['minutes'], google_alarm['method'])