Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
22776 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

template.send_mail(record_id,force_send=True)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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 ?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 23
9128
0
thg 12 21
2625
1
thg 9 21
10222
2
thg 9 24
1287
1
thg 2 24
2519