From d58e0c43c779bdc431d4993512292477d6692317 Mon Sep 17 00:00:00 2001 From: "Ali Alfie (alal)" Date: Mon, 4 Sep 2023 09:56:53 +0200 Subject: [PATCH] [FIX] l10n_es_edi_facturae: change signature template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the signature in the export by: - Changing the signature template to remove unnecessary transforms. - Replacing SigningCertificateV2 with the correct tag. According to https://www.facturae.gob.es/formato/Paginas/politicas-firma-electronica.aspx the signature follows the XAdES ETSI TS 101 903 format which contains the tag SigningCertificate instead. - Correcting the way the signature node was removed in the _get_uri_function. closes odoo/odoo#137321 X-original-commit: e4d92f37da41e7e5efaeb82b4adfff669083fb23 Signed-off-by: William André (wan) --- .../data/signature_templates.xml | 8 ++------ .../tests/data/expected_in_invoice_document.xml | 10 +++------- .../tests/data/expected_refund_document.xml | 10 +++------- .../tests/data/expected_signed_document.xml | 12 ++++-------- .../tests/data/expected_tax_withholding.xml | 8 ++------ addons/l10n_es_edi_facturae/xml_utils.py | 11 ++++++++--- 6 files changed, 22 insertions(+), 37 deletions(-) diff --git a/addons/l10n_es_edi_facturae/data/signature_templates.xml b/addons/l10n_es_edi_facturae/data/signature_templates.xml index f6181637a19..755482782d3 100644 --- a/addons/l10n_es_edi_facturae/data/signature_templates.xml +++ b/addons/l10n_es_edi_facturae/data/signature_templates.xml @@ -7,11 +7,7 @@ - - - not(ancestor-or-self::ds:Signature) - @@ -42,7 +38,7 @@ - + @@ -53,7 +49,7 @@ - + diff --git a/addons/l10n_es_edi_facturae/tests/data/expected_in_invoice_document.xml b/addons/l10n_es_edi_facturae/tests/data/expected_in_invoice_document.xml index 00f358df4bc..913ef0c5a64 100644 --- a/addons/l10n_es_edi_facturae/tests/data/expected_in_invoice_document.xml +++ b/addons/l10n_es_edi_facturae/tests/data/expected_in_invoice_document.xml @@ -254,18 +254,14 @@ - - - not(ancestor-or-self::ds:Signature) - ___ignore___ - UQH7ea0mtLoqLN/aM5mWssQ38fOK1bxnWT4fKQBYiSI= + SpcFoWamxWQCsYjqZ/lsru5Ia4MaKBVgXiUWgKKBh2s= @@ -310,7 +306,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 2023-01-01T00:00:00 - + @@ -321,7 +317,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 548631688851000697209704649636588277530075594025 - + diff --git a/addons/l10n_es_edi_facturae/tests/data/expected_refund_document.xml b/addons/l10n_es_edi_facturae/tests/data/expected_refund_document.xml index d21a859ca21..3d88d2b60d0 100644 --- a/addons/l10n_es_edi_facturae/tests/data/expected_refund_document.xml +++ b/addons/l10n_es_edi_facturae/tests/data/expected_refund_document.xml @@ -161,18 +161,14 @@ - - - not(ancestor-or-self::ds:Signature) - ___ignore___ - UQH7ea0mtLoqLN/aM5mWssQ38fOK1bxnWT4fKQBYiSI= + SpcFoWamxWQCsYjqZ/lsru5Ia4MaKBVgXiUWgKKBh2s= @@ -217,7 +213,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 2023-01-01T00:00:00 - + @@ -228,7 +224,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 548631688851000697209704649636588277530075594025 - + diff --git a/addons/l10n_es_edi_facturae/tests/data/expected_signed_document.xml b/addons/l10n_es_edi_facturae/tests/data/expected_signed_document.xml index 1388ca20a93..8a075747d3e 100644 --- a/addons/l10n_es_edi_facturae/tests/data/expected_signed_document.xml +++ b/addons/l10n_es_edi_facturae/tests/data/expected_signed_document.xml @@ -254,18 +254,14 @@ - - - not(ancestor-or-self::ds:Signature) - - ___ignore___ + ZLrDCYSAq93Xpv9PLeS4CSBh4htTOx5j4f7zH0K8ddI= - UQH7ea0mtLoqLN/aM5mWssQ38fOK1bxnWT4fKQBYiSI= + SpcFoWamxWQCsYjqZ/lsru5Ia4MaKBVgXiUWgKKBh2s= @@ -310,7 +306,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 2023-01-01T00:00:00 - + @@ -321,7 +317,7 @@ aWAYAMCL4KhvISclysD+5juDLpGCLHPtKxBXTQ== 548631688851000697209704649636588277530075594025 - + diff --git a/addons/l10n_es_edi_facturae/tests/data/expected_tax_withholding.xml b/addons/l10n_es_edi_facturae/tests/data/expected_tax_withholding.xml index ecd8f153e96..e25b4a89902 100644 --- a/addons/l10n_es_edi_facturae/tests/data/expected_tax_withholding.xml +++ b/addons/l10n_es_edi_facturae/tests/data/expected_tax_withholding.xml @@ -249,10 +249,6 @@ - - - ___ignore___ - ___ignore___ @@ -283,7 +279,7 @@ ___ignore___ - + @@ -294,7 +290,7 @@ ___ignore___ - + diff --git a/addons/l10n_es_edi_facturae/xml_utils.py b/addons/l10n_es_edi_facturae/xml_utils.py index 4400f70cb32..ba16120e3b0 100644 --- a/addons/l10n_es_edi_facturae/xml_utils.py +++ b/addons/l10n_es_edi_facturae/xml_utils.py @@ -33,11 +33,16 @@ def _get_uri(uri, reference, base_uri=""): https://www.w3.org/TR/xmldsig-core/#sec-EnvelopedSignature Returns an UTF-8 encoded bytes string. """ - node = deepcopy(reference.getroottree()) + node = deepcopy(reference.getroottree().getroot()) if uri == base_uri: # Base URI: whole document, without signature (default is empty URI) - for signature in node.xpath('/ds:Signature', namespaces=NS_MAP): - node = signature.getparent() + for signature in node.xpath('ds:Signature', namespaces=NS_MAP): + if signature.tail: + # move the tail to the previous node or to the parent + if (previous := signature.getprevious()) is not None: + previous.tail = "".join([previous.tail or "", signature.tail or ""]) + else: + signature.getparent().text = "".join([signature.getparent().text or "", signature.tail or ""]) node.remove(signature) return _canonicalize_node(node)