تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1918 أدوات العرض

I have create a template to send payslip email to employee , it woeks when sending one by one but I want to send it to all employee in one shot here is my function:

class sendemail(models.Model):
_inherit = 'hr.payslip'
_description = 'to send email to employee'

def sendemail(self):
template_id=self.env.ref('salary_reports.payslip_email').id
self.env['mail.template'].browse(template_id).send_mail(self.id, force_send=True)

noupdate="1">
id="payslip_email" model="mail.template">
name="name">employee: Send by email
name="model_id" ref="hr_payroll_community.model_hr_payslip"/>
name="email_from">mgstar091@gmail.com
name="email_to">${object.employee_id.work_email}
name="subject">قسيمة مرتب
name="body_html" type="html">
style="margin: 0px; padding: 0px;">

style="margin: 0px; padding: 0px; font-size: 13px;">
${object.employee_id.name}/ السيد



نحسل إليكم مرتب شهر
${object.date_to}




تقبل تحياتي




name="report_template" ref="your_report_id"/>
name="report_name">nothing



it gives me this error 

ValueError: : "Expected singleton: hr.payslip(11, 13)" while evaluating
'records.sendemail()


الصورة الرمزية
إهمال
أفضل إجابة

Hi Mokhtar,

You need to just take a loop as you are use the records . try with this code. 


    def sendemail(self):
template_id=self.env.ref('salary_reports.payslip_email').id
for rec in self:
self.env['mail.template'].browse(template_id).send_mail(rec.id, force_send=True)



Hope It will help you.
الصورة الرمزية
إهمال
الكاتب أفضل إجابة

thank you sir, it works 

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أغسطس 24
4862
0
يناير 22
465
3
نوفمبر 21
3466
4
ديسمبر 24
17573
1
أكتوبر 21
9203