diff options
| author | Pierre Rousseau <pro@odoo.com> | 2019-05-24 11:43:53 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-15 08:08:49 +0000 |
| commit | a1087e301122eea626ed30f34198de4666a81bdf (patch) | |
| tree | 12791eaf5e9822f076a94c8297f713a6a007646f /addons | |
| parent | 54f5c6c70ffe4bb8020a0106d3b8fde0ca34a45b (diff) | |
[IMP] calendar_sms, hr_presence: use sms template and its API when sending SMS
Purpose of this commit is to include SMS templates and the new sms messaging
API and methods in calendar_sms and hr_presence. Templates allow people to
customize the content of sent SMS. New SMS messaging API allows to track
notification status when sending SMS.
Related to task 1922163
Linked to PR #33510
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/calendar_sms/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/calendar_sms/data/sms_data.xml | 10 | ||||
| -rw-r--r-- | addons/calendar_sms/models/calendar.py | 8 | ||||
| -rw-r--r-- | addons/hr/models/hr_employee.py | 6 | ||||
| -rw-r--r-- | addons/hr_presence/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/hr_presence/data/sms_data.xml | 12 | ||||
| -rw-r--r-- | addons/hr_presence/models/hr_employee.py | 21 |
7 files changed, 51 insertions, 8 deletions
diff --git a/addons/calendar_sms/__manifest__.py b/addons/calendar_sms/__manifest__.py index 70156156a8a..f91a362bbe2 100644 --- a/addons/calendar_sms/__manifest__.py +++ b/addons/calendar_sms/__manifest__.py @@ -9,6 +9,7 @@ 'version': '1.0', 'depends': ['calendar', 'sms'], 'data': [ + 'data/sms_data.xml', 'views/calendar_views.xml', ], 'application': False, diff --git a/addons/calendar_sms/data/sms_data.xml b/addons/calendar_sms/data/sms_data.xml new file mode 100644 index 00000000000..8016fd429fe --- /dev/null +++ b/addons/calendar_sms/data/sms_data.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<odoo> + <data noupdate="1"> + <record id="sms_template_data_calendar_reminder" model="sms.template"> + <field name="name">Calendar Event: Reminder</field> + <field name="model_id" ref="calendar.model_calendar_event"/> + <field name="body">Event reminder: ${object.name} on ${object.start_datetime or object.start_date}</field> + </record> + </data> +</odoo> diff --git a/addons/calendar_sms/models/calendar.py b/addons/calendar_sms/models/calendar.py index 0ad5bb3fb31..9071a0181a3 100644 --- a/addons/calendar_sms/models/calendar.py +++ b/addons/calendar_sms/models/calendar.py @@ -20,8 +20,12 @@ class CalendarEvent(models.Model): def _do_sms_reminder(self): """ Send an SMS text reminder to attendees that haven't declined the event """ for event in self: - sms_msg = _("Event reminder: %s on %s.") % (event.name, event.start_datetime or event.start_date) - event._message_sms(sms_msg) + event._message_sms_with_template( + template_xmlid='calendar_sms.sms_template_data_calendar_reminder', + template_fallback=_("Event reminder: %s on %s.") % (event.name, event.start_datetime or event.start_date), + partner_ids=self._sms_get_default_partners().ids, + put_in_queue=False + ) class CalendarAlarm(models.Model): diff --git a/addons/hr/models/hr_employee.py b/addons/hr/models/hr_employee.py index 887d23bd904..abdb09e996e 100644 --- a/addons/hr/models/hr_employee.py +++ b/addons/hr/models/hr_employee.py @@ -396,3 +396,9 @@ class HrEmployeePrivate(models.Model): @api.returns('mail.message', lambda value: value.id) def message_post(self, *args, **kwargs): return super(HrEmployeePrivate, self._post_author()).message_post(*args, **kwargs) + + def _sms_get_default_partners(self): + return self.mapped('user_partner_id') + + def _sms_get_number_fields(self): + return ['mobile_phone'] diff --git a/addons/hr_presence/__manifest__.py b/addons/hr_presence/__manifest__.py index 8758156cddf..d0fdba48fff 100644 --- a/addons/hr_presence/__manifest__.py +++ b/addons/hr_presence/__manifest__.py @@ -21,6 +21,7 @@ Allows to contact directly the employee in case of unjustified absence. 'views/res_config_settings_views.xml', 'data/ir_actions_server.xml', 'views/hr_employee_views.xml', + 'data/sms_data.xml', 'data/mail_data.xml', ], 'demo': [], diff --git a/addons/hr_presence/data/sms_data.xml b/addons/hr_presence/data/sms_data.xml new file mode 100644 index 00000000000..8a334c772cc --- /dev/null +++ b/addons/hr_presence/data/sms_data.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<odoo> + <data noupdate="1"> + <record id="sms_template_data_hr_presence" model="sms.template"> + <field name="name">Employee: Presence Reminder</field> + <field name="model_id" ref="hr.model_hr_employee"/> + <field name="body">Exception made if there was a mistake of ours, it seems that you are not at your office and there is not request of leaves from you. +Please, take appropriate measures in order to carry out this work absence. +Do not hesitate to contact your manager or the human resource department.</field> + </record> + </data> +</odoo> diff --git a/addons/hr_presence/models/hr_employee.py b/addons/hr_presence/models/hr_employee.py index a40dfd256eb..2f0c55a9571 100644 --- a/addons/hr_presence/models/hr_employee.py +++ b/addons/hr_presence/models/hr_employee.py @@ -122,24 +122,33 @@ class ResCompany(models.Model): "context": {'default_employee_id': self.id}, } + # -------------------------------------------------- + # Messaging + # -------------------------------------------------- + def action_send_sms(self): self.ensure_one() if not self.env.user.has_group('hr.group_hr_manager'): raise UserError(_("You don't have the right to do this. Please contact an Administrator.")) if not self.mobile_phone: raise UserError(_("There is no professional phone for this employee.")) - body = _("""Exception made if there was a mistake of ours, it seems that you are not at your office and there is not request of leaves from you. + + context = dict(self.env.context) + context.update(default_res_model='hr.employee', default_res_id=self.id, default_composition_mode='comment', default_number_field_name='mobile_phone') + + template = self.env.ref('hr_presence.sms_template_presence', False) + if not template: + context['default_body'] = _("""Exception made if there was a mistake of ours, it seems that you are not at your office and there is not request of leaves from you. Please, take appropriate measures in order to carry out this work absence. Do not hesitate to contact your manager or the human resource department.""") + else: + context['default_template_id'] = template.id + return { "type": "ir.actions.act_window", "res_model": "sms.composer", "view_mode": 'form', - "context": { - 'active_id': self.id, - 'default_message': body, - 'default_recipients': self.mobile_phone, - }, + "context": context, "name": "Send SMS", "target": "new", } |
