Skip to Content
Menu
This question has been flagged
3 Replies
8980 Rodiniai

Hi,

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

Portretas
Atmesti
Autorius Best Answer

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,

}

Portretas
Atmesti
Best Answer

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.

Portretas
Atmesti
Best Answer

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

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
kov. 15
9225
2
rugp. 24
1405
0
vas. 24
1360
5
gruod. 19
2648
0
lapkr. 24
4302