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

Is it possible to get default recipients when sending mail (Actually , only Administrator is shown) ?


def action_send(self):
        mail_template = self.env.ref('hr_test.my_email_template')
        mail_template.send_mail(self.id, force_send=True)

        partners = []
        if self.applicant_id and self.applicant_id.user_id:
            partners.append(self.applicant_id.user_id.partner_id.id)
        partners = partners + [user.partner_id.id for user in
                               self.env.ref('hr_training.training_officer').users if
                               user.partner_id.id not in partners]
        for rec in self:
            if rec.applicant_id and rec.applicant_id.parent_id:
                parent = rec.applicant_id.parent_id
                if parent.user_id and parent.user_id.partner_id.id not in partners:
                    partners.append(parent.user_id.partner_id.id)

        for partner in partners:
            mail_template.send_mail(self.id, force_send=True,
            raise_exception=True,
            email_values={'email_to': partner})

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

Before call send_mail method, email_to email values list of usee email ID. JOIN IN STRING WITH COMMA in python code and assign to email values and after send_mail method call.

Example,

https://www.odoo.com/forum/help-1/question/how-to-set-email-to-in-email-template-dynamically-129618

Ảnh đại diện
Huỷ bỏ
Tác giả

@Prakash , I try this , but I got error ( 'email_to': ','.join(partner)

TypeError: can only join an iterable)

email_values = {

'email_to': ','.join(partner)

}

mail_template.send_mail(self.id, force_send=True,

raise_exception=True, email_values=email_values)

Email address field assign to email_to. If single email ID, directly assign object name dot field name. Example, parter.email make sure email id is printing successfully. If multiple id in that case list of email id using JOIN as STRING WITH COMMA.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
2521
3
thg 2 25
3827
0
thg 5 24
46
1
thg 4 24
3522
4
thg 9 23
5068