Commit e065feaa by François C.

Send mail after shift missing (final part)

parent 193bcf2d
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
from . import models from . import models
...@@ -10,19 +10,21 @@ ...@@ -10,19 +10,21 @@
- Retrieve all shifts, counting for each of them only active registrations - Retrieve all shifts, counting for each of them only active registrations
""", """,
'author': "damien.moulard", 'author': "damien.moulard / fracolo",
'website': "https://lacagette-coop.fr", 'website': "https://lacagette-coop.fr",
# Categories can be used to filter modules in modules listing # Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list # for the full list
'category': 'Uncategorized', 'category': 'Uncategorized',
'version': '0.0.1', 'version': '0.0.2',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base'], 'depends': ['base', 'coop_shift'],
# always loaded # always loaded
'data': [ 'data': [
'data/ir_cron.xml',
'data/email_template_data.xml'
], ],
'installable': True, 'installable': True,
} }
<?xml version="1.0"?>
<odoo>
<record id="missing_shift_email" model="mail.template">
<field name="name">Missing Shift</field>
<field name="model_id" ref="lacagette_shifts.model_shift_registration"/>
<field name="email_from">${(object.partner_id.company_id.email or '')|safe}</field>
<field name="email_to" >${object.partner_id.email|safe}</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="reply_to">${object.company_id.email|safe}</field>
<field name="subject">Absence au service du ${format_tz(object.shift_id.date_begin_tz, tz='UTC+2', format='%d %B %Y de %Hh%M')} à ${format_tz(object.shift_id.date_end_tz, tz='UTC+2', format='%Hh%M')}</field>
<field name="body_html"><![CDATA[
Bonjour ${object.name},
<p>
Sauf erreur, tu n'étais pas présent.e à ton service du ${format_tz(object.shift_id.date_begin_tz, tz='UTC+2', format='%d %B %Y de %Hh%M')} à ${format_tz(object.shift_id.date_end_tz, tz='UTC+2', format='%Hh%M')} . Tu dois désormais rattraper le service que tu as manqué avant ton prochain service.
</p>
<p>
Nous comptions sur toi ! Dès que tu sais que tu vas être absent.e, pense à déplacer ton service le plus tôt possible et au moins 24h avant la date : connecte-toi à ton espace Membre, sélectionne le service que tu veux échanger et trouve une autre date.
</p>
<p>
Rends-toi sur ton espace membre et choisis un service de rattrapage sur le calendrier.
</p>
<p>
S'il s'agit d'une erreur et que tu étais là, signale-le via ce formulaire qui sera traité par le Bureau des membres.
</p>
<p>
Merci et à très vite à ${object.partner_id.company_id.name} !
</p>
<p>
L'équipe de la ${object.partner_id.company_id.name}.
</p>
]]></field>
</record>
</odoo>
<?xml version="1.0"?>
<!--
Copyright (C) 2021 - Today Cooperatic
Author : fracolo
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record forcecreate="True" id="cron_missing_shift_email" model="ir.cron">
<field name="name">Missing Shift Email</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 20:00:00')"/>
<field name="doall" eval="False"/>
<field name="model" eval="'shift.registration'"/>
<field name="function" eval="'send_shift_missing_emails'"/>
<field name="args" eval="'()'"/>
<field name="active" eval="False"/>
<field name="priority">2</field>
</record>
</odoo>
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import lacagette_shifts from . import lacagette_shifts
from . import lacagette_shift_registrations
\ No newline at end of file
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
import datetime
class ShiftRegistration(models.Model):
_inherit = 'shift.registration'
@api.multi
def send_shift_missing_email(self):
mail_template = self.env.ref('lacagette_shifts.missing_shift_email')
if not mail_template:
return False
for reg_target in self:
mail_template.send_mail(reg_target.id)
return True
@api.model
def send_shift_missing_emails(self):
shift_env = self.env['shift.registration']
# search
now = datetime.datetime.now()
yesterday = now - datetime.timedelta(hours=24)
reg_targets = shift_env.search([
('state', '=', 'open'),
('date_begin', '>=', yesterday.strftime("%Y-%m-%d %H:%M:%S")),
('date_begin', '<', now.strftime("%Y-%m-%d %H:%M:%S"))
])
reg_targets.send_shift_missing_email()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment