Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
8987 Widoki

Hi,

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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,

}

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 15
9225
2
sie 24
1408
0
lut 24
1360
5
gru 19
2648
0
lis 24
4303