From e237d1b45f7776ba65e1602d0aeda6cef0076608 Mon Sep 17 00:00:00 2001 From: Rodia Date: Fri, 27 Dec 2024 00:10:03 -0500 Subject: [PATCH] Fix: Se descomenta test AttachedDocument --- facho/fe/fe.py | 14 +++++++++----- tests/test_attached_document.py | 14 +++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/facho/fe/fe.py b/facho/fe/fe.py index a703606..d57ca04 100644 --- a/facho/fe/fe.py +++ b/facho/fe/fe.py @@ -57,6 +57,7 @@ Bogota = tz.gettz('America/Bogota') NAMESPACES = { + 'atd': 'urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2', 'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1', 'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2', 'cbc': 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2', @@ -106,17 +107,20 @@ class FeXML(FachoXML): def tostring(self, **kw): # MACHETE(bit4bit) la DIAN espera que la etiqueta raiz no este en un namespace + urn_oasis = { + 'AttachedDocument': 'urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2', + 'Invoice': 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2', + 'CreditNote': 'urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2', + } + root_namespace = self.root_namespace() root_localname = self.root_localname() xmlns_name = {v: k for k, v in NAMESPACES.items()}[root_namespace] - if root_localname == 'Invoice': - urn_oasis = 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2' - if root_localname == 'CreditNote': - urn_oasis = 'urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2' + return super().tostring(**kw)\ .replace(xmlns_name + ':', '')\ .replace('xmlns:'+xmlns_name, 'xmlns')\ - .replace(root_namespace, urn_oasis) + .replace(root_namespace, urn_oasis[root_localname]) class DianXMLExtensionCUDFE(FachoXMLExtension): diff --git a/tests/test_attached_document.py b/tests/test_attached_document.py index 9ed7c2d..d4fe299 100644 --- a/tests/test_attached_document.py +++ b/tests/test_attached_document.py @@ -4,13 +4,13 @@ # this repository contains the full copyright notices and license terms. # from datetime import datetime -# import pytest -# from facho.fe import form_xml +import pytest +from facho.fe import form_xml -# import helpers +import helpers -# def test_xml_with_required_elements(): -# doc = form_xml.AttachedDocument(id='123') -# xml = doc.toFachoXML() -# assert xml.get_element_text('/atd:AttachedDocument/cbc:ID') == '123' +def test_xml_with_required_elements(): + doc = form_xml.AttachedDocument(id='123') + xml = doc.toFachoXML() + assert xml.get_element_text('/atd:AttachedDocument/cbc:ID') == '123'