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)