This question has been flagged

I am creating a custom module that will auto checkout employees who forgot to checkout the end of the day and will send an email to the same.

I created a function for auto checkout and email, Created a job cron and email template. I have configured mail servers as they are working fine.

Employees are getting checked out but Mail is not getting sent.

I'm getting these errors while running cron job.


2019-09-11 11: 52: 05,515 16973 WARNING auto_checkout odoo.models: mail.mail.create () with unknown fields:., @, A, c, g, h, i, l, m, n, o, p, r, s, t, u 2019-09-11 11: 52: 06,766 16973 INFO auto_checkout odoo.addons.mail.models.mail_mail: Sent batch 1 emails via mail server ID #False

Here is my code

`` Python

class hr_attendace (models.Model): 
       _inherit = ['hr.attendance']

       def check_for_incomplete_attendances (self): 
           not_checkout self.env = ['hr.attendance']. search ([('check_out', '=', False)])

          for rec in not_checkout:

              date_time = (datetime.now () + timedelta (days = 0)) strftime ('% Y-% m-% d 18:29:59')

              rec.check_out = date_time

              email_template = self.env.ref ('custom_attendance_2.email_template')

              if email_template:

                 email_template.send_mail (rec.employee_id.work_email, force_send = True)

`` `

`` `Xml

<odoo>

 <data nupdate = "1">

  <record id = "ir_cron_module_auto_checkout" model = "ir.cron">

   <field name = "name"> Auto Checkout </ field>

   <field eval = "True" name = "auto_checkout" />

   <field name = "interval_number"> 1 </ field>

   <field name = "nextcall" eval = "(DateTime.now () + timedelta (days = 0)). Strftime ('% Y -% m-% d 18:29:59')" />

   <field name = "interval_type"> days </ field>

   <field name = "numbercall"> - 1 </ field>

   <field eval = "True" name = "doall" />

   <field name = "model_id" ref = "hr_attendance.model_hr_attendance" />

   <field name = "state"> code </ field>

   <field name = "code">

    model.check_for_incomplete_attendances ()

   </ field>

  </ record>

 </ data>

</ odoo>

```xml

<odoo>

 <data>

  <record id = "email_template" model = "mail.template">

   <field name = "name"> Attendance Reminder Email </ field>

   <field name = "model_id" ref = "hr_attendance.model_hr_attendance" />

   <field name = "auto_delete" eval = "False" />

   <field name = "email_from"> shringarg@trinesis.com </ field>

   <field name = "email_to"> $ {object.work_email} </ field>

   <field name = "subject"> Waiting Reminder $ {object.name} </ field>

   <field name = "body_html">

    <! [CDATA [Hello $ {object.name}, This is reminder that you did not sign out today. <br/> Best regards ... <br/>]]>

   </ field>

  </ record>

 </ data>

</ odoo>

```




Avatar
Discard
Best Answer

problem is below code-

email_template.send_mail (rec.employee_id.work_email, force_send = True)

send_email first parameter always be record's database ID. From and to email can be set from template.

If you change your line email_template.send_mail (rec.id, force_send = True), then email will trigger. make sure your email template is right.



Avatar
Discard