|
8 | 8 | class IrActionsReport(models.Model):
|
9 | 9 | _inherit = "ir.actions.report"
|
10 | 10 |
|
| 11 | + def postprocess_pdf_report(self, record, buffer): |
| 12 | + if self.is_ubl_xml_to_embed_in_invoice(): |
| 13 | + buffer = record.add_xml_in_pdf_buffer(buffer) |
| 14 | + return super().postprocess_pdf_report(record, buffer) |
| 15 | + |
11 | 16 | @api.multi
|
12 | 17 | def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None):
|
13 | 18 | """We go through that method when the PDF is generated for the 1st
|
14 | 19 | time and also when it is read from the attachment.
|
15 |
| - This method is specific to QWeb""" |
16 |
| - invoice_reports = self._get_invoice_reports_ubl() |
17 |
| - if ( |
18 |
| - len(self) == 1 and |
19 |
| - self.report_name in invoice_reports and |
20 |
| - res_ids and |
21 |
| - len(res_ids) == 1 and |
22 |
| - not self._context.get('no_embedded_ubl_xml')): |
23 |
| - invoice = self.env['account.invoice'].browse(res_ids[0]) |
24 |
| - if ( |
25 |
| - invoice.type in ('out_invoice', 'out_refund') and |
26 |
| - invoice.company_id.xml_format_in_pdf_invoice == 'ubl'): |
27 |
| - pdf_content = invoice.with_context( |
28 |
| - no_embedded_pdf=True).embed_ubl_xml_in_pdf( |
29 |
| - pdf_content=pdf_content) |
30 |
| - return super()._post_pdf( |
| 20 | + """ |
| 21 | + pdf_content = super()._post_pdf( |
31 | 22 | save_in_attachment, pdf_content=pdf_content, res_ids=res_ids)
|
| 23 | + if res_ids and len(res_ids) == 1: |
| 24 | + if self.is_ubl_xml_to_embed_in_invoice(): |
| 25 | + invoice = self.env['account.invoice'].browse(res_ids) |
| 26 | + if invoice.is_ubl_sale_invoice_posted(): |
| 27 | + pdf_content = invoice.embed_ubl_xml_in_pdf(pdf_content) |
| 28 | + return pdf_content |
| 29 | + |
| 30 | + def is_ubl_xml_to_embed_in_invoice(self): |
| 31 | + return (self.model == 'account.invoice' |
| 32 | + and not self.env.context.get('no_embedded_ubl_xml') |
| 33 | + and self.report_name in self._get_invoice_reports_ubl()) |
32 | 34 |
|
33 | 35 | @classmethod
|
34 | 36 | def _get_invoice_reports_ubl(cls):
|
|
0 commit comments