Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2306 Lượt xem

Right now in order to send the ledger to partner, we need to download the pdf report and then attach it to the email. 

But How can I achieve this directly from the partner ledger screen in reporting. I can add a button "Send Email" but Im not familiar with what actions and methods I should use in order to achieve this result. 


One way can be I just use my custom email server and send it , but I see tha odoo has got email templates we can use in order to send emails, attaching the necessary pdf file. 

Is that way possible for pdf report (partner ledger) . 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

First, you need to define the button in the XML

<button name="action_send_report" class="oe_highlight"

string="Send Mail"

type="object"

help="To send part ledger"/>

Next, we need to define the py for getting the attachments,
Function for sending attachments in the mail

def action_send_report(self):
"""Send partner ledger report as mail"""
report = {
'docs': self,
}
record = self.env['ir.actions.report'].sudo()._render_qweb_pdf(
'module_name.record_id_of_ir_actions_reort', self.id,
data=report)
ir_values = {
'name': 'Partner Ledger',
'type': 'binary',
'datas': base64.b64encode(record[0]),
'store_fname': base64.b64encode(record[0]),
'mimetype': 'application/pdf',
'res_model': 'your.model',
}
report_attachment = self.env['ir.attachment'].sudo().create(ir_values)
email_values = {
'email_to': self.manager_id.work_email,
'subject': "Partner Ledger",
'attachment_ids': [report_attachment.id]
}
mail = self.env['mail.mail'].sudo().create(email_values)
mail.send()

Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 23
2742
0
thg 8 20
2118
3
thg 5 16
3941
1
thg 5 15
5471
1
thg 3 15
4294