Skip to Content
Menu
This question has been flagged
3 Replies
21558 Views

This method in custom model alert

here action have current object and mail depends on it.

def send_alert_mail(self, action):
           for record in self:
            alrt_mail=[]
            if record.template_id:
                mail_id = self.env['mail.template']
                current_obj = action.values()             #record.template_id is selected template obj.

                        values = mail_id.generate_email(record.template_id.id,current_obj[0])

                for u in record.alrt_users_ids:
                    if u.email:

                        alrt_mail.append(u.res_usr_id.partner_id.id)
                if alrt_mail:
                    values['partner_ids'] = [(6,0,[alrt_mail])]
                    values['email_from'] = record.act_user_id.login
                    mail_mail_obj = self.env['mail.message']
                    msg_id = mail_mail_obj.create(values)
            return True


result = method(recs, *args, **kwargs)
  File "/home/pchouksey1/workspace/dexciss/simple/simple_10/repo1010/alert_management/model/alert_management.py", line 350, in create
    action._process(action._filter_post(record))
  File "/home/pchouksey1/workspace/dexciss/simple/simple_10/repo1010/alert_management/model/alert_management.py", line 207, in _process
    self.send_mail(records, action_done)
  File "/home/pchouksey1/workspace/dexciss/simple/simple_10/repo1010/alert_management/model/alert_management.py", line 229, in send_mail
    values = mail_id.generate_email(record.template_id.id,current_obj[0])
  File "/home/pchouksey1/workspace/dexciss/simple/simple_10/core10/addons/mail/models/mail_template.py", line 496, in generate_email
    if template.lang:
AttributeError: 'bool' object has no attribute 'lang'


how to resolve error or there is any solution for send mail using template in odoo10

Avatar
Discard
Best Answer

template = self.env.ref('module.template_xml_id, False)

template.send_mail(record_id,force_send=True)

Avatar
Discard
Best Answer

Hi,

Please see this sample to send the mail from template.

su_id = self.env['res.partner'].browse(SUPERUSER_ID)
template_id = self.env['ir.model.data'].get_object_reference('birth_day_notification',
'birthday_notification')[1]
template_browse = self.env['mail.template'].browse(template_id)
email_to = self.env['hr.employee'].browse(emp_id).work_email
if template_browse:
values = template_browse.generate_email(emp_id, fields=None)
values['email_to'] = email_to
values['email_from'] = su_id.email
values['res_id'] = False
if not values['email_to'] and not values['email_from']:
 pass
 mail_mail_obj = self.env['mail.mail']
 msg_id = mail_mail_obj.create(values)
if msg_id:
mail_mail_obj.send(msg_id)
 return True

Thanks

Avatar
Discard

Hello @Niyas,

Can you say me what i replace on position of (SUPERUSER_ID) and .get_object_reference( ' ? ' , ' ? ' )[1] which fields i can put on this position ?

Related Posts Replies Views Activity
1
Dec 23
7872
0
Dec 21
1873
1
Sep 21
9188
2
Sep 24
117
1
Feb 24
921