Commit 54208bec by François C.

Implements new way of sending shift reminder

parent a3e3560c
After module updates, before activated new cron
===============================================
Run the following SQL command :
UPDATE shift_registration
SET reminder_mail_sent = true
WHERE id IN
(SELECT registration_id FROM shift_mail_registration WHERE mail_sent = true AND write_date <= now() AND write_date > now() - '14 days'::interval);
* then Unactivate previous cron
activate new cron task
...@@ -28,4 +28,21 @@ ...@@ -28,4 +28,21 @@
</p> </p>
]]></field> ]]></field>
</record> </record>
<record id="custom_shift_email_reminder" model="mail.template">
<field name="name">Mail rappel service</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">Rappel du service ${object.shift_id.name}</field>
<field name="body_html"><![CDATA[
Bonjour ${object.name},
Texte en rapport avec le magasin.
]]></field>
</record>
</odoo> </odoo>
...@@ -19,4 +19,20 @@ ...@@ -19,4 +19,20 @@
<field name="active" eval="False"/> <field name="active" eval="False"/>
<field name="priority">2</field> <field name="priority">2</field>
</record> </record>
<record forcecreate="True" id="cron_shift_reminder_email" model="ir.cron">
<field name="name">LaCagette Shift Email Reminder</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_reminder_emails'"/>
<field name="args" eval="'()'"/>
<field name="active" eval="False"/>
<field name="priority">2</field>
</record>
</odoo> </odoo>
...@@ -6,6 +6,8 @@ import datetime ...@@ -6,6 +6,8 @@ import datetime
class ShiftRegistration(models.Model): class ShiftRegistration(models.Model):
_inherit = 'shift.registration' _inherit = 'shift.registration'
reminder_mail_sent = fields.Boolean("Reminder mail has been sent", default= False)
@api.multi @api.multi
def send_shift_missing_email(self): def send_shift_missing_email(self):
mail_template = self.env.ref('lacagette_shifts.missing_shift_email') mail_template = self.env.ref('lacagette_shifts.missing_shift_email')
...@@ -17,6 +19,15 @@ class ShiftRegistration(models.Model): ...@@ -17,6 +19,15 @@ class ShiftRegistration(models.Model):
return True return True
@api.multi
def send_shift_reminder_email(self):
mail_template = self.env.ref('lacagette_shifts.custom_shift_email_reminder')
if not mail_template:
return False
for reg_target in self:
mail_template.send_mail(reg_target.id)
self.write({'reminder_mail_sent': True})
return True
@api.model @api.model
def send_shift_missing_emails(self): def send_shift_missing_emails(self):
...@@ -30,3 +41,18 @@ class ShiftRegistration(models.Model): ...@@ -30,3 +41,18 @@ class ShiftRegistration(models.Model):
('date_begin', '<', now.strftime("%Y-%m-%d %H:%M:%S")) ('date_begin', '<', now.strftime("%Y-%m-%d %H:%M:%S"))
]) ])
reg_targets.send_shift_missing_email() reg_targets.send_shift_missing_email()
@api.model
def send_shift_reminder_emails(self):
shift_env = self.env['shift.registration']
# Find out the candidate shifts (between tomorrow and after tomorrow
# TODO : The time window could be changed, using odoo parameters
now = datetime.datetime.now()
tomorrow = now + datetime.timedelta(hours=24)
after_tomorrow = tomorrow + datetime.timedelta(hours=24)
reg_targets = shift_env.search([
('state', '=', 'open'),
('reminder_mail_sent', '=', False),
('date_begin', '>=', tomorrow.strftime("%Y-%m-%d %H:%M:%S")),
('date_begin', '<', after_tomorrow.strftime("%Y-%m-%d %H:%M:%S"))])
reg_targets.send_shift_reminder_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