Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
3 Respostas
8982 Visualizações

Hi,

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

Avatar
Cancelar
Autor Melhor resposta

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,

}

Avatar
Cancelar
Melhor resposta

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.

Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mar. 15
9225
2
ago. 24
1407
0
fev. 24
1360
5
dez. 19
2648
0
nov. 24
4302