From ddf9296b23b472f98626e020c26d5fef14d718af Mon Sep 17 00:00:00 2001 From: odoo-pda Date: Thu, 6 Aug 2020 23:44:18 +0200 Subject: [PATCH] [ADD] send (un)subscribed mail when worker is changed. --- macavrac_base/__manifest__.py | 1 + macavrac_base/data/mail_template.xml | 16 ++++++++++++++++ macavrac_base/models/planning.py | 15 +++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 macavrac_base/data/mail_template.xml diff --git a/macavrac_base/__manifest__.py b/macavrac_base/__manifest__.py index 26268ce..4e7165c 100644 --- a/macavrac_base/__manifest__.py +++ b/macavrac_base/__manifest__.py @@ -9,6 +9,7 @@ "version": "12.0.1.0.0", "depends": ["beesdoo_shift", "contacts"], "data": [ + "data/mail_template.xml", "views/res_partner.xml", "views/shift.xml", ], diff --git a/macavrac_base/data/mail_template.xml b/macavrac_base/data/mail_template.xml new file mode 100644 index 0000000..8744965 --- /dev/null +++ b/macavrac_base/data/mail_template.xml @@ -0,0 +1,16 @@ + + + + + + Shift Subscribed + + + + + Shift Unsubscribed + + + + diff --git a/macavrac_base/models/planning.py b/macavrac_base/models/planning.py index a0d7c08..b58682b 100644 --- a/macavrac_base/models/planning.py +++ b/macavrac_base/models/planning.py @@ -62,6 +62,21 @@ class Task(models.Model): rec.can_unsubscribe = True + def write(self, vals): + if 'worker_id' in vals: + template_unsubscribed = self.env.ref("macavrac_base.email_template_shift_unsubscribed") + template_subscribed = self.env.ref("macavrac_base.email_template_shift_subscribed") + new_worker_id = self.env['beesdoo.shift.shift'].browse(vals.get('worker_id')) + for record in self: + old_worker_id = record.worker_id + if old_worker_id: + template_unsubscribed.send_mail(record.id) + if new_worker_id and old_worker_id != new_worker_id: + res = super(Task, record).write(vals) + template_subscribed.send_mail(record.id) + return super(Task, self).write(vals) + + class CooperativeStatus(models.Model): _inherit = 'cooperative.status'