Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
8756 มุมมอง

Hi,

How to attach 2 reports (Payslip and Payslip details) in email?

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Got my solution:

@api.multi

def send_payslip(self):

self.ensure_one()

ir_model_data = self.env['ir.model.data']

try:

template_id = ir_model_data.get_object_reference('send_email_payslips', 'email_template_hr_payslips')[1]

except ValueError:

template_id = False

try:

compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]

except ValueError:

compose_form_id = False

print 'user', self.employee_id.user_id

user = self.env['res.users'].browse(self.employee_id.user_id.id)

print 'partner_id', user.partner_id.id

self.env['report'].sudo().get_pdf([self.id], 'hr_payroll.report_payslipdetails')

self.env['report'].sudo().get_pdf([self.id], 'hr_payroll.report_payslip')

payslip_det = self.env['ir.attachment'].search(

[('res_model', '=', 'hr.payslip'), ('res_id', '=', self.id),('name','=','Payslip Detailed.pdf')])

payslip_sum = self.env['ir.attachment'].search(

[('res_model', '=', 'hr.payslip'), ('res_id', '=', self.id), ('name', '=', 'Payslip.pdf')])

ctx = dict()

ctx.update({

'default_model': 'hr.payslip',

'default_res_id': self.ids[0],

'default_use_template': bool(template_id),

'default_template_id': template_id,

'default_composition_mode': 'comment',

'default_partner_id': user.partner_id.id,

'default_attachment_ids': [payslip_sum.id, payslip_det.id, ]

})

return {

'type': 'ir.actions.act_window',

'view_type': 'form',

'view_mode': 'form',

'res_model': 'mail.compose.message',

'views': [(compose_form_id, 'form')],

'view_id': compose_form_id,

'target': 'new',

'context': ctx,

}

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

By default you can attached only one attachment based on configuration, if any external attachment you want to add in email then you should customize your process.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

By default in odoo you can attach an report in email by configuring it in the Email Template.

In developer mode,

Head to Settings > Email Template and open your desired template.

In Advanced Tab,  you will find two fields for optional report and filename.

For example, Go to the Sale Order Template and you will be able to see an report and filename asssigned here.


Thank You

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
9044
2
ส.ค. 24
1143
0
ก.พ. 24
1136
Pie chart in PDF report แก้ไขแล้ว
5
ธ.ค. 19
2648
0
พ.ย. 24
4074