Browse Source

[ADD] b_shift : weekly summary email

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
47b1eff4ab
  1. 1
      beesdoo_shift/__openerp__.py
  2. 15
      beesdoo_shift/data/cron.xml
  3. 58
      beesdoo_shift/data/mail_template.xml
  4. 1836
      beesdoo_shift/i18n/fr.po
  5. 1837
      beesdoo_shift/i18n/fr_BE.po
  6. 33
      beesdoo_shift/models/task.py

1
beesdoo_shift/__openerp__.py

@ -21,6 +21,7 @@
"data/stage.xml",
"data/system_parameter.xml",
"data/cron.xml",
"data/mail_template.xml",
"security/group.xml",
"security/ir.model.access.csv",
"views/task_template.xml",

15
beesdoo_shift/data/cron.xml

@ -35,5 +35,20 @@
<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>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="True" />
<field name="nextcall"
eval="str(datetime.utcnow() + timedelta((6-datetime.utcnow().weekday()) % 7 ))"
/>
<field name="model">beesdoo.shift.shift</field>
<field name="function">_cron_send_weekly_emails</field>
<field name="args">()</field>
<field name="active" eval="False" />
</record>
</data>
</odoo>

58
beesdoo_shift/data/mail_template.xml

@ -0,0 +1,58 @@
<?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_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>
<field name="email_from">${object.worker_id.company_id.email}</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; ">
<p>Hello ${object.worker_id.name},</p>
<p>You are awaited the ${format_tz(object.start_time,object.worker_id.tz or 'Europe/Brussels','%d.%m.%Y')}
for the shift starting at ${format_tz(object.start_time,object.worker_id.tz or 'Europe/Brussels','%H:%M')}.
<br/><br/>Please contact us at ${object.worker_id.company_id.email} if you have any trouble attending the shift.
</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>
</data>
</odoo>

1836
beesdoo_shift/i18n/fr.po
File diff suppressed because it is too large
View File

1837
beesdoo_shift/i18n/fr_BE.po
File diff suppressed because it is too large
View File

33
beesdoo_shift/models/task.py

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api, _
from openerp.exceptions import UserError, ValidationError
import json
from datetime import datetime, timedelta
from openerp import _, api, fields, models
from openerp.exceptions import UserError, ValidationError
class TaskStage(models.Model):
_name = 'beesdoo.shift.stage'
@ -233,3 +236,29 @@ class Task(models.Model):
raise UserError(_("The worker has not a proper working mode define, please check the worker is subscribed"))
status.sudo()._change_counter(data)
self._set_revert_info(data, status)
@api.model
def _cron_send_weekly_emails(self):
"""
Send a summary email for all workers
if they have a shift planned during the week.
"""
tasks = self.env["beesdoo.shift.shift"]
shift_summary_mail_template = self.env.ref(
"beesdoo_shift.email_template_shift_summary", False
)
start_time = datetime.now() + timedelta(days=1)
end_time = datetime.now() + timedelta(days=7)
confirmed_tasks = tasks.search(
[
("start_time", ">", start_time.strftime("%Y-%m-%d 00:00:01")),
("start_time", "<", end_time.strftime("%Y-%m-%d 23:59:59")),
("worker_id", "!=", False),
("stage_id", "=", self.env.ref("beesdoo_shift.open").id),
]
)
for rec in confirmed_tasks:
shift_summary_mail_template.send_mail(rec.id, True)
Loading…
Cancel
Save