Browse Source

[ADD] b_shift : attendance sheet automatic emails

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
8b09b7a877
  1. 14
      beesdoo_shift/data/cron.xml
  2. 96
      beesdoo_shift/data/mail_template.xml
  3. 23
      beesdoo_shift/models/attendance_sheet.py

14
beesdoo_shift/data/cron.xml

@ -32,6 +32,7 @@
<field name="model">beesdoo.shift.sheet</field>
<field name="function">_generate_attendance_sheet</field>
<field name="args">()</field>
<field name="active" eval="False" />
</record>
<record id="ir_cron_compute_shift_counter" model="ir.cron">
@ -46,6 +47,19 @@
<field name="active" eval="False" />
</record>
<record id="ir_cron_check_non_validated_sheet" model="ir.cron">
<field name="name">Check for non-validated sheets</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="True" />
<field name="nextcall" eval="(datetime.now() + timedelta(days=1)).replace(hour=1,minute=0,second=0)" />
<field name="model">beesdoo.shift.sheet</field>
<field name="function">_cron_non_validated_sheets</field>
<field name="args">()</field>
<field name="active" eval="False" />
</record>
<record id="ir_cron_send_weekly_emails" model="ir.cron">
<field name="name">Send weekly shift summary</field>
<field name="interval_number">7</field>

96
beesdoo_shift/data/mail_template.xml

@ -1,8 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="1">
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="1">
<record id="email_template_non_attendance" model="mail.template">
<field name="name">Shift Non-attendance</field>
<field name="subject">Non-attendance to your last shift.</field>
<field name="partner_to">${object.replaced_id.id or object.worker_id.id|safe}</field>
<field name="model_id" ref="model_beesdoo_shift_shift"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.worker_id.lang}</field>
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
% if object.replaced_id:
<p>Hello ${object.replaced_id.name},</p>
<p>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')}).
<br/><br/> You were supposed to replace ${object.worker_id.name}. <br/><br/>
% endif
% if object.worker_id:
<p>Hello ${object.worker_id.name},</p>
<p>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')}).
<br/><br/>
% 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
<br/><br/>Your status have been updated to "${object.worker_id.state}".
<br/><br/>If you have any question regarding this non-attendance, feel free to contact us.
</p>
</br>
<p>Sustainably yours,</p>
<p>${object.worker_id.company_id.name}.</p>
% 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}<br/>
% 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}<br/>
% 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 ''}<br/>
% endif
% if object.worker_id.company_id.phone:
Phone:&nbsp; ${object.worker_id.company_id.phone}
% endif
% if object.worker_id.company_id.website:
<div>
Web :&nbsp;<a href="${object.worker_id.company_id.website}">${object.worker_id.company_id.website}</a>
</div>
%endif
% if object.worker_id.company_id.logo_url:
<div>
<img src=${object.worker_id.company_id.logo_url}>
</div>
%endif
</div>
]]></field>
</record>
<record id="email_template_non_validated_sheet" model="mail.template">
<field name="name">Non-validated sheet</field>
<field name="subject">[${object.day}] Non-validated sheet ${object.time_slot}</field>
<field name="model_id" ref="model_beesdoo_shift_sheet"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p>${object.day}
<br/><br/>The attendance sheet for ${object.time_slot} is not validated.
<br/><br/>Please, do it as soon as possible so as to update workers' status.
</p>
</div>
]]></field>
</record>
<record id="email_template_shift_summary" model="mail.template">
<field name="name">Shift Summary</field>
<field name="subject">Your next shift (${format_tz(object.start_time,object.worker_id.tz or 'Europe/Brussels','%d.%m.%Y - %H:%M')})</field>

23
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)
Loading…
Cancel
Save