跳至内容
菜单
此问题已终结
3 回复
8770 查看

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

形象
丢弃
相关帖文 回复 查看 活动
1
3月 15
9057
2
8月 24
1159
0
2月 24
1146
5
12月 19
2648
0
11月 24
4083