I am creating a custom module where I want to get all the selected employee in the Payroll and send them a default email. For that I am doing this
To show the action button
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="action_email_payslip" model="ir.actions.server">
<field name="name">Email</field>
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="multi" eval="False"/>
<field name="model_id" ref="hr_payroll.model_hr_payslip"/>
<field name="binding_model_id" ref="hr_payroll.model_hr_payslip"/>
<field name="state">code</field>
<field name="code">
action = records.action_send_email()
</field>
</record>
</data>
</odoo>In the model my code is like this
from odoo import models, fields, api, _ class EmailPayslip(models.Model):
_inherit = 'hr.payslip' @api.multi
def action_send_email(self):
self.ensure_one()
template = self.env.ref( 'email_payslip.email_template_payslip', False, )
selected_employess = []
not_selected_employees = [] for payslip in self:
try:
lang = payslip.employee_id.user_id.lang
template.with_context(lang=lang).send_mail(
self.env.user.id, force_send=True, raise_exception=True
)
selected_employess.append(payslip.name)
except Exception as e:
not_selected_employees.append(payslip.name) print(selected_employess)But its showing error like
ValueError: Expected singleton: %s" % record
Can someone tell me what I a doing wrong here and how to fix this? Any help and suggestions will be really appreciable.
@Nihas Raphy sorry for not using the comment feature. I have no karma available to make comment to your answer.
I have tried to use self.ensure_one() but that also doesn't work. Also for the template please check my updated question.
Please post the whole traceback error.