I want to send an email to customer when a field selection is changed or equal to specific state.
so I have added the field in python: "laundry_status_order"
laundry_status_order = fields.Selection([('0','In Progress'), ('1', 'Ready To Deliver'), ('2', 'Delivered')], default='0', track_visibility='onchange')
and I have create a new function with onchange api:
@api.onchange('laundry_status_order')
@api.multi
def send_mail_template(self):
# # # Now let us find the e-mail template
if self.laundry_status_order=='1':
template = self.env.ref('okto_send_mail_ecolav.email_template_ecolav_landry_ready2')
self.env['mail.template'].browse(template.id).send_mail(self.id,force_send=True)
This function work perfectely when I call it from a button, but when I change the field "laundry_status_order", this error is displayed: (
File "C:\Users\hedia\Workspace\Odoo10\odoo\addons\okto_send_mail_ecolav\models\pos_order.py", line 25, in send_mail_template self.env['mail.template'].browse(template.id).send_mail(self.id,force_send=True) File "C:\Users\hedia\Workspace\Odoo10\odoo\addons\mail\models\mail_template.py", line 534, in send_mail values = self.generate_email(res_id) File "C:\Users\hedia\Workspace\Odoo10\odoo\addons\mail\models\mail_template.py", line 448, in generate_email res_ids_to_templates = self.get_email_template(res_ids) File "C:\Users\hedia\Workspace\Odoo10\odoo\addons\mail\models\mail_template.py", line 383, in get_email_template results = dict.fromkeys(res_ids, False) TypeError: 'NewId' object is not iterable