Skip to Content
Menu
This question has been flagged
2 Replies
3614 Views

I developed a Cron in order to, when a task has a date_deadline equal to today, the responsable user of this task will received an email.

The function is still basic, because it's on testing.


class ProjectTasks(models.Model):
    _inherit = 'project.task'

    @api.multi
    def send_email(self):
        print('Executing CRON')

        today = date.today()     
        
        tasks = self.env['project.task'].search([('date_deadline','=',today)])

        body = 'Reminder, your task %s  is going to expire today' % (tasks.name)
        subject = 'Reminder Task Expire Today'
        email_from = self.env['ir.mail_server'].search([('id','=',1)])
        email_to = tasks.user_id.email
        values = {
            'res_id' : 1,
            'email_from' : email_from.smtp_user,
            'email_to' : email_to,
            'auto_delete' : False,
            'model' : 'project.task',
            'body' : body,
            'subject' : subject,
            }

        send_mail = self.env['mail.mail'].sudo().create(values)
        send_mail.send()


        

And my XML is:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="ir_send_mail_task" model="ir.cron">
            <field name="name">Recordatorio Vencimiento Tarea</field>
            <field name="active">True</field>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="numbercall">-1</field>
            <field name="model_id" ref="model_project_task"/>
            <field name="state">code</field>
            <field name="code">model.send_email()</field>
        </record>
    </data>
</odoo>


So... what am I missing here? I'm receiving the subject, but not the body.


Avatar
Discard
Best Answer

please change key:  body to body_html

Avatar
Discard
Best Answer
Try to change your body tag.

values = { 'res_id' : 1, 'email_from' : email_from.smtp_user, 'email_to' : email_to, 'auto_delete' : False, 'model' : 'project.task', 'body_html' : body, 'subject' : subject, }

Regard:

MUHAMMAD IMRAN

Avatar
Discard
Related Posts Replies Views Activity
3
Nov 22
7144
2
Apr 20
13951
1
May 19
4797
0
May 19
2129
0
May 20
2879