Hey, folks.
I have been trying to create send a notification through email whenever a new maintenance request is created with logistics_type: Inbound. I have gone through a few issues here. If I do something like: Action --> Duplicate: and save a new record, it's basically working and sending email while if I try to create a new maintenance record through "create" button it's failing to render template with following error code:
Failed to render template <Template memory:7f7a88d4cf28> using values {'format_date': <function MailTemplate._render_template.<locals>.<lambda> at 0x7f7a81279730>, 'format_tz': <function MailTemplate._render_template.<locals>.<lambda> at 0x7f7a81279f28>, 'format_amount': <function MailTemplate._render_template.<locals>.<lambda> at 0x7f7a81279488>, 'user': res.users(2,), 'ctx': {'email_to': 'admin@rsaworks.com', 'safe': False}, 'object': None}
UndefinedError: 'None' has no attribute 'equipment_id'
my model:
class MaintenanceRequest(models.Model):
_inherit = 'maintenance.request'
@api.model
def create(self, vals):
res = super(MaintenanceRequest, self).create(vals)
vals = {}
if res.logistics_type == 'Inbound':
if res.message_partner_ids:
for follower in res.message_partner_ids:
vals.update({
'email_to': follower.email,
})
template_id = self.env.ref("ssi_maintenance.maintenance_email_notification_template").id
template = self.env['mail.template'].browse(template_id)
template.with_context(vals).send_mail(self.id, force_send = True)
return res
and here is my email template:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id='maintenance_email_notification_template' model='mail.template'>
<field name="name">Maintenance Request Created </field>
<field name="model_id" ref = "test_maintenance.model_maintenance_request"/>
<field name='email_from'>${object.user_id.login.email_formatted |safe}</field>
<field name='email_to'>${ctx['email_to']}</field>
<field name='subject'>Maintenace Request Created : ${object.name}</field>
<field name='body_html' type='html'>
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px">
<p>Hey new maintenace request has been created</p>
<br /> <br />
Here is your detail
<br /> <br />
Customer : ${object.equipment_id.customer_id.name} <br />
Equipment : ${object.equipment_id.name} <br />
Created By : ${object.employee_id.name} <br />
Request Date : ${object.request_date} <br />
Scheduled Date : ${object.schedule_date} <br />
Equipment / Rating : ${object.equipment_id.rating} <br />
Equipment / Rating Unit : ${object.equipment_id.rating_unit} <br />
<br /> <br />
This is automatic generated email, please donot reply. If you have any question please login to rsaw account or contact RSAW admin
</p>
</div>
</field>
<field name="report_template" ref="test_maintenance.test_maintenance_logistics_report"/>
<field name="report_name"> Maintenance Report </field>
</record>
</data>
</odoo>
I would highly appreciate if someone could give me any suggestion or help. Thank you in advance