From 9a2e53e45c1f69bbf7325558471627338daf1237 Mon Sep 17 00:00:00 2001 From: Julien Van Roy Date: Thu, 15 Jun 2023 12:26:14 +0000 Subject: [PATCH] [FIX] account_edi_ubl_cii: no xml declaration with the send & print Issue: the xml declaration "" is lost when opening the send & print wizard with existing xml attachments. Explanation: When opening the send and print wizard, the PDF are generated and postprocessed by `_postprocess_pdf_report`. In the `_postprocess_pdf_report` override in `account_edi_ubl_cii`, the xml attachments are parsed through `tree = etree.fromstring(xml)`, then the base64 PDF is inserted, and the etree is converted to a bytes through `etree.tostring(cleanup_xml_node(tree))` and the resulting bytes is written back on the attachment, but the xml declaration disappeared. Solution: include the arguments `xml_declaration=True, encoding='UTF-8'` in the `tostring` function when converting the etree to a bytes. opw-3144519 closes odoo/odoo#125523 X-original-commit: ed9a1d83bd7d496a316e8da6a201ca3a14c99d19 Signed-off-by: Julien Van Roy Signed-off-by: Laurent Smet --- .../models/account_edi_xml_cii_facturx.py | 3 +-- addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py | 3 +-- addons/account_edi_ubl_cii/models/account_move_send.py | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py index 61899e0c3b6..ca9a3d988d6 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py @@ -236,8 +236,7 @@ class AccountEdiXmlCII(models.AbstractModel): vals = self._export_invoice_vals(invoice) errors = [constraint for constraint in self._export_invoice_constraints(invoice, vals).values() if constraint] xml_content = self.env['ir.qweb']._render('account_edi_ubl_cii.account_invoice_facturx_export_22', vals) - xml_content = b"\n" + etree.tostring(cleanup_xml_node(xml_content)) - return xml_content, set(errors) + return etree.tostring(cleanup_xml_node(xml_content), xml_declaration=True, encoding='UTF-8'), set(errors) # ------------------------------------------------------------------------- # IMPORT diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py index 164a34598fc..23104de23ca 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py @@ -478,8 +478,7 @@ class AccountEdiXmlUBL20(models.AbstractModel): vals = self._export_invoice_vals(invoice) errors = [constraint for constraint in self._export_invoice_constraints(invoice, vals).values() if constraint] xml_content = self.env['ir.qweb']._render(vals['main_template'], vals) - xml_content = b"\n" + etree.tostring(cleanup_xml_node(xml_content)) - return xml_content, set(errors) + return etree.tostring(cleanup_xml_node(xml_content), xml_declaration=True, encoding='UTF-8'), set(errors) # ------------------------------------------------------------------------- # IMPORT diff --git a/addons/account_edi_ubl_cii/models/account_move_send.py b/addons/account_edi_ubl_cii/models/account_move_send.py index f967b3f5080..2fedd367d7c 100644 --- a/addons/account_edi_ubl_cii/models/account_move_send.py +++ b/addons/account_edi_ubl_cii/models/account_move_send.py @@ -216,8 +216,9 @@ class AccountMoveSend(models.Model): anchor_index = tree.index(anchor_elements[0]) tree.insert(anchor_index, etree.fromstring(to_inject)) - invoice_data['ubl_cii_xml_attachment_values']['raw'] = b"\n" \ - + etree.tostring(cleanup_xml_node(tree)) + invoice_data['ubl_cii_xml_attachment_values']['raw'] = etree.tostring( + cleanup_xml_node(tree), xml_declaration=True, encoding='UTF-8' + ) def _link_invoice_documents(self, invoice, invoice_data): # EXTENDS 'account'