I have a function that sends mass mail when called, it works in odoo 13 but when porting to odoo 12, the function gives an error
AtributeError: 'hr.payslip' object has no attribute 'message_post_with_template'
This is the model and function where the error is coming from.
class HREmailPayslip(models.TransientModel):
_name = 'hr.payslip.email.wizard'
_description = 'Payslip email Wizard'
message = fields.Text()
payslip_ids = fields.Many2many('hr.payslip')
def action_do_email_send(self):
context = dict(self._context or {})
payslip_ids = self.env['hr.payslip'].browse(context.get('active_ids'))
template_id = self .env.ref('hr_payslip_email.email_template_send_payslip')
# force_send=False: odoo will put it in queue (default)
for p in payslip_ids.filtered(lambda r: r.state == 'done'):
# mail = template_id.send_mail(p.id, force_send=False)
p.message_post_with_template(template_id=template_id.id)
return {'type': 'ir.actions.act_window_close'}
In odoo 13 the message_post_with_template function works correctly but in odoo 12 it says the model does not have that function, so I checked the hr.payslip model for 13 to check if it has that function and it does not but somehow it still works but for odoo 12 not so. What could be wrong and how do I achieve this in odoo 12?
So I discovered in odoo 12 hr.payslip does not inherit mail.thread mixin class, so I had to inherit it in my inherited hr.payslip class by
class HrPayslip(models.Model):
_name = 'hr.payslip'
# _inherit = 'hr.payslip'
_inherit = ['hr.payslip', 'mail.thread']