From b6f31f0975466f9bc9a77f2ae66eb17351279d7d Mon Sep 17 00:00:00 2001 From: Elouan Le Bars Date: Wed, 4 Dec 2019 18:04:51 +0100 Subject: [PATCH] [ADD] b_shift : attendance sheet automatic emails --- beesdoo_shift/data/cron.xml | 14 ++++ beesdoo_shift/data/mail_template.xml | 86 ++++++++++++++++++++++++ beesdoo_shift/models/attendance_sheet.py | 23 +++++++ 3 files changed, 123 insertions(+) diff --git a/beesdoo_shift/data/cron.xml b/beesdoo_shift/data/cron.xml index dd9e908..06416a6 100644 --- a/beesdoo_shift/data/cron.xml +++ b/beesdoo_shift/data/cron.xml @@ -32,6 +32,7 @@ beesdoo.shift.sheet _generate_attendance_sheet () + @@ -46,6 +47,19 @@ + + Check for non-validated sheets + 1 + days + -1 + + + beesdoo.shift.sheet + _cron_non_validated_sheets + () + + + Send weekly shift summary 7 diff --git a/beesdoo_shift/data/mail_template.xml b/beesdoo_shift/data/mail_template.xml index 5e5e7fa..e9711e9 100644 --- a/beesdoo_shift/data/mail_template.xml +++ b/beesdoo_shift/data/mail_template.xml @@ -3,6 +3,92 @@ + + Shift Non-attendance + Non-attendance to your last shift. + ${object.replaced_id.id or object.worker_id.id|safe} + + + ${object.worker_id.lang} + + + % if object.replaced_id: +

Hello ${object.replaced_id.name},

+ +

You have been recorded as non-attended during your last shift (${format_tz(object.start_time,object.replaced_id.tz or 'Europe/Brussels','%d.%m.%Y - %H:%M')}). +

You were supposed to replace ${object.worker_id.name}.

+ % endif + + % if object.worker_id: +

Hello ${object.worker_id.name},

+ +

You have been recorded as non-attended during your last shift (${format_tz(object.start_time,object.worker_id.tz or 'Europe/Brussels','%d.%m.%Y - %H:%M')}). +

+ % endif + + % if object.state == 'absent_0': + Super-cooperator assigned you 0 compensation, so you won't have any additionnal shift to do. + % endif + % if object.state == 'absent_1': + Super-cooperator assigned you 1 compensation, so you have to attend another shift. + % endif + % if object.state == 'absent_2': + Super-cooperator assigned you 2 compensations, so you have to attend 2 anothers shifts. + % endif + +

Your status have been updated to "${object.worker_id.state}". +

If you have any question regarding this non-attendance, feel free to contact us. +

+
+

Sustainably yours,

+

${object.worker_id.company_id.name}.

+ + % if object.worker_id.company_id.street: + ${object.worker_id.company_id.street} + % endif + % if object.worker_id.company_id.street2: + ${object.worker_id.company_id.street2}
+ % endif + % if object.worker_id.company_id.city or object.worker_id.company_id.zip: + ${object.worker_id.company_id.zip} ${object.worker_id.company_id.city}
+ % endif + % if object.worker_id.company_id.country_id: + ${object.worker_id.company_id.state_id and ('%s, ' % object.worker_id.company_id.state_id.name) or ''} ${object.worker_id.company_id.country_id.name or ''}
+ % endif + % if object.worker_id.company_id.phone: + Phone:  ${object.worker_id.company_id.phone} + % endif + + % if object.worker_id.company_id.website: + + %endif + % if object.worker_id.company_id.logo_url: +
+ +
+ %endif + + ]]>
+
+ + Non-validated sheet + [${object.day}] Non-validated sheet ${object.time_slot} + + + + +

${object.day} +

The attendance sheet for ${object.time_slot} is not validated. +

Please, do it as soon as possible so as to update workers' status. +

+ + + ]]>
+
Shift Summary Your next shift (${format_tz(object.start_time,object.worker_id.tz or 'Europe/Brussels','%d.%m.%Y - %H:%M')}) diff --git a/beesdoo_shift/models/attendance_sheet.py b/beesdoo_shift/models/attendance_sheet.py index 43b74c1..a3d79a2 100644 --- a/beesdoo_shift/models/attendance_sheet.py +++ b/beesdoo_shift/models/attendance_sheet.py @@ -481,6 +481,12 @@ class AttendanceSheet(models.Model): actual_shift.stage_id = actual_stage actual_shift.replaced_id = expected_shift.replacement_worker_id + if expected_shift.stage in ["absent_1", "absent_2"]: + mail_template = self.env.ref( + "beesdoo_shift.email_template_non_attendance", False + ) + mail_template.send_mail(expected_shift.task_id.id, True) + # Added shifts status update for added_shift in self.added_shift_ids: actual_stage = self.env.ref( @@ -589,3 +595,20 @@ class AttendanceSheet(models.Model): sheet = sheets.create( {"start_time": start_time, "end_time": end_time} ) + + @api.model + def _cron_non_validated_sheets(self): + sheets = self.env["beesdoo.shift.sheet"] + non_validated_sheets = sheets.search( + [ + ("day", "=", date.today() - timedelta(days=1)), + ("state", "=", "not_validated"), + ] + ) + + if non_validated_sheets: + mail_template = self.env.ref( + "beesdoo_shift.email_template_non_validated_sheet", False + ) + for rec in non_validated_sheets: + mail_template.send_mail(rec.id, True)