如何通过服务器操作 Odoo 14 向多个申请人发送电子邮件
How to send email to multiple applicant via server action Odoo 14
我有一个电子邮件模板,我想使用服务器操作向多个申请人发送拒绝工作的电子邮件,并在 Odoo 14 中发送电子邮件后存档申请人。
我怎样才能 link 此服务器操作到电子邮件模板并在发送电子邮件后存档申请人?
任何帮助将不胜感激。
这是我的代码。
**Email Template:**
<record id="email_template_custom" model="mail.template">
<field name="name">Job refusal: Send by email</field>
<field name="model_id" ref="hr_recruitment_custom.model_hr_applicant"/>
<field name="email_from">${object.user_id.email_formatted |safe}</field>
<field name="email_to">${object.email_from}</field>
<field name="subject">Applied Job: (Ref ${object.job_id.name})</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Dear ${object.partner_name}
<br/>
<br/>
We appreciate your interest in ${object.company_id.name} and the time you’ve invested in applying for the ${object.job_id.name} opening.
<br/>
<br/>
We ended up moving forward with another candidate, but we’d like to thank you for talking to our team and giving us the opportunity to learn about your skills and accomplishments.
<br/>
<br/>
We will be advertising more positions in the coming months.
We hope you’ll keep us in mind and we encourage you to apply again.
<br/>
<br/>
We wish you good luck with your job search and professional future endeavors.
<br/>
<br/>
Best,
${object.user_id.name}
</p>
</div>enter code here
</field>
</record>
**python file:**
def action_send_refusal_by_email(self):
ctx = {}
email_list = self.partner_id.mapped('email')
if email_list:
ctx['email_to'] = ','.join([email for email in email_list if email])
ctx['email_from'] = self.env.user.emoployee_id.email
ctx['send_email'] = True
ctx['partner_id'] = ''
template = self.env.ref('hr_recruitment_custom.email_template_custom')
template.with_context(ctx).send_mail(self.id, force_send=True, raise_exception=False)
**Server action:**
<record id="action_refuse_applicants" model="ir.actions.server">
<field name="name">Milti refuse Applicants</field>
<field name="model_id" ref="hr_recruitment_custom.email_template_custom"/>
<field name="binding_model_id" ref="hr_recruitment_custom.email_template_custom"/>
<field name="state">code</field>
<field name="code">records.action_send_refusal_by_email()</field></record>
修改您的服务器操作并添加替换 record_model,记录所属的实际模型
**Server action:**
<record id="action_refuse_applicants" model="ir.actions.server">
<field name="name">Multi refuse Applicants</field>
<field name="model_id" ref="hr_recruitment_custom.record_model"/>
<field name="binding_model_id" ref="hr_recruitment_custom.record_model"/>
<field name="state">code</field>
<field name="code">records.action_send_refusal_by_email()</field></record>
在python这边,你首先必须循环遍历自身,以避免单例错误。
def action_send_refusal_by_email(self):
for rec in self:
ctx = {}
#email_list = self.partner_id.mapped('email')
# if email_list:
ctx['email_to'] = rec.partner_id.email
ctx['email_from'] = self.env.user.employee_id.email
ctx['send_email'] = True
ctx['partner_id'] = rec.partner_id.id
template = self.env.ref('hr_recruitment_custom.email_template_custom')
template.with_context(ctx).send_mail(
rec.id, force_send=True, raise_exception=False)
rec.active = False
我有一个电子邮件模板,我想使用服务器操作向多个申请人发送拒绝工作的电子邮件,并在 Odoo 14 中发送电子邮件后存档申请人。 我怎样才能 link 此服务器操作到电子邮件模板并在发送电子邮件后存档申请人? 任何帮助将不胜感激。 这是我的代码。
**Email Template:**
<record id="email_template_custom" model="mail.template">
<field name="name">Job refusal: Send by email</field>
<field name="model_id" ref="hr_recruitment_custom.model_hr_applicant"/>
<field name="email_from">${object.user_id.email_formatted |safe}</field>
<field name="email_to">${object.email_from}</field>
<field name="subject">Applied Job: (Ref ${object.job_id.name})</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Dear ${object.partner_name}
<br/>
<br/>
We appreciate your interest in ${object.company_id.name} and the time you’ve invested in applying for the ${object.job_id.name} opening.
<br/>
<br/>
We ended up moving forward with another candidate, but we’d like to thank you for talking to our team and giving us the opportunity to learn about your skills and accomplishments.
<br/>
<br/>
We will be advertising more positions in the coming months.
We hope you’ll keep us in mind and we encourage you to apply again.
<br/>
<br/>
We wish you good luck with your job search and professional future endeavors.
<br/>
<br/>
Best,
${object.user_id.name}
</p>
</div>enter code here
</field>
</record>
**python file:**
def action_send_refusal_by_email(self):
ctx = {}
email_list = self.partner_id.mapped('email')
if email_list:
ctx['email_to'] = ','.join([email for email in email_list if email])
ctx['email_from'] = self.env.user.emoployee_id.email
ctx['send_email'] = True
ctx['partner_id'] = ''
template = self.env.ref('hr_recruitment_custom.email_template_custom')
template.with_context(ctx).send_mail(self.id, force_send=True, raise_exception=False)
**Server action:**
<record id="action_refuse_applicants" model="ir.actions.server">
<field name="name">Milti refuse Applicants</field>
<field name="model_id" ref="hr_recruitment_custom.email_template_custom"/>
<field name="binding_model_id" ref="hr_recruitment_custom.email_template_custom"/>
<field name="state">code</field>
<field name="code">records.action_send_refusal_by_email()</field></record>
修改您的服务器操作并添加替换 record_model,记录所属的实际模型
**Server action:**
<record id="action_refuse_applicants" model="ir.actions.server">
<field name="name">Multi refuse Applicants</field>
<field name="model_id" ref="hr_recruitment_custom.record_model"/>
<field name="binding_model_id" ref="hr_recruitment_custom.record_model"/>
<field name="state">code</field>
<field name="code">records.action_send_refusal_by_email()</field></record>
在python这边,你首先必须循环遍历自身,以避免单例错误。
def action_send_refusal_by_email(self):
for rec in self:
ctx = {}
#email_list = self.partner_id.mapped('email')
# if email_list:
ctx['email_to'] = rec.partner_id.email
ctx['email_from'] = self.env.user.employee_id.email
ctx['send_email'] = True
ctx['partner_id'] = rec.partner_id.id
template = self.env.ref('hr_recruitment_custom.email_template_custom')
template.with_context(ctx).send_mail(
rec.id, force_send=True, raise_exception=False)
rec.active = False