feat(WIP): Modificacion para emision de Nomina de Ajuste
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| # This file is part of facho.  The COPYRIGHT file at the top level of | ||||
| # this repository contains the full copyright notices and license terms. | ||||
|  | ||||
| from lxml.builder import E | ||||
| from ..facho import FachoXML, FachoXMLExtension, LXMLBuilder | ||||
| import uuid | ||||
| import xmlsig | ||||
| @@ -32,24 +33,25 @@ POLICY_NAME = u'Política de firma para facturas electrónicas de la República | ||||
|  | ||||
|  | ||||
| NAMESPACES = { | ||||
|     'atd': 'urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2', | ||||
|     'no': 'dian:gov:co:facturaelectronica:NominaIndividual', | ||||
|     'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1', | ||||
|      #'atd': 'urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2', | ||||
|      #'no': 'dian:gov:co:facturaelectronica:NominaIndividual', | ||||
|     'noa': 'dian:gov:co:facturaelectronica:NominaIndividualDeAjuste', | ||||
|      # 'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1', | ||||
|     'xs': 'http://www.w3.org/2001/XMLSchema-instance',     | ||||
|     'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2', | ||||
|     'cbc': 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2', | ||||
|     'cdt': 'urn:DocumentInformation:names:specification:ubl:colombia:schema:xsd:DocumentInformationAggregateComponents-1', | ||||
|     'clm54217': 'urn:un:unece:uncefact:codelist:specification:54217:2001', | ||||
|     'clmIANAMIMEMediaType': 'urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003', | ||||
|      # 'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2', | ||||
|      #'cbc': 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2', | ||||
|      # 'cdt': 'urn:DocumentInformation:names:specification:ubl:colombia:schema:xsd:DocumentInformationAggregateComponents-1', | ||||
|      # 'clm54217': 'urn:un:unece:uncefact:codelist:specification:54217:2001', | ||||
|      # 'clmIANAMIMEMediaType': 'urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003',`` | ||||
|     'ext': 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2', | ||||
|     'qdt': 'urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2', | ||||
|     'sts': 'dian:gov:co:facturaelectronica:Structures-2-1', | ||||
|     'udt': 'urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2', | ||||
|     'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | ||||
|     'xades': 'http://uri.etsi.org/01903/v1.3.2#', | ||||
|     'xades141': 'http://uri.etsi.org/01903/v1.4.1#',     | ||||
|     'ds': 'http://www.w3.org/2000/09/xmldsig#', | ||||
|     'sig': 'http://www.w3.org/2000/09/xmldsig#', | ||||
|      # 'qdt': 'urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2', | ||||
|      # 'sts': 'dian:gov:co:facturaelectronica:Structures-2-1', | ||||
|      # 'udt': 'urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2', | ||||
|      'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | ||||
|      'xades': 'http://uri.etsi.org/01903/v1.3.2#', | ||||
|      'xades141': 'http://uri.etsi.org/01903/v1.4.1#',     | ||||
|      'ds': 'http://www.w3.org/2000/09/xmldsig#', | ||||
|      #'sig': 'http://www.w3.org/2000/09/xmldsig#', | ||||
| } | ||||
|  | ||||
| def fe_from_string(document: str) -> FachoXML: | ||||
| @@ -77,7 +79,6 @@ def mock_xades_policy(): | ||||
| class FeXML(FachoXML): | ||||
|  | ||||
|     def __init__(self, root, namespace): | ||||
|  | ||||
|         super().__init__("{%s}%s" % (namespace, root), | ||||
|                          nsmap=NAMESPACES) | ||||
|  | ||||
| @@ -88,8 +89,8 @@ class FeXML(FachoXML): | ||||
|     def tostring(self, **kw): | ||||
|         # MACHETE(bit4bit) la DIAN espera que la etiqueta raiz no este en un namespace | ||||
|         return super().tostring(**kw)\ | ||||
|             .replace("fe:", "")\ | ||||
|             .replace("xmlns:no", "xmlns")\ | ||||
|             .replace("noa:", "")\ | ||||
|             .replace("xmlns:noa", "xmlns")\ | ||||
|             .replace("change", "xsi:schemaLocation") | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -250,7 +250,7 @@ class InformacionGeneral: | ||||
|                                 # NIE202 | ||||
|                                 # TABLA 5.5.2 | ||||
|                                 # TODO(bit4bit) solo NominaIndividual | ||||
|                                 TipoXML = '102', | ||||
|                                 TipoXML = '103', | ||||
|                                 # NIE024 | ||||
|                                 CUNE = None, | ||||
|                                 # NIE025 | ||||
| @@ -313,11 +313,30 @@ class DIANNominaXML: | ||||
|         self.informacion_general_version = None | ||||
|  | ||||
|         self.tag_document = tag_document | ||||
|         self.fexml = fe.FeXML(tag_document, 'http://www.dian.gov.co/contratos/facturaelectronica/v1') | ||||
|         self.fexml = fe.FeXML(tag_document, "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste") | ||||
|  | ||||
|         if schemaLocation is not None: | ||||
|             self.fexml.root.set("SchemaLocation", "")             | ||||
|             self.fexml.root.set( | ||||
|                 "SchemaLocation", | ||||
|                 "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd" | ||||
|             ) | ||||
|             self.fexml.root.set("change", schemaLocation) | ||||
|         else: | ||||
|             schemaLocation = "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd" | ||||
|             self.fexml.root.set( | ||||
|                 "SchemaLocation", "") | ||||
|             self.fexml.root.set( | ||||
|                 "change", schemaLocation) | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         # self.fexml.root.set( | ||||
|         #    "SchemaLocation", | ||||
|         #    "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd" | ||||
|         #) | ||||
|         # self.fexml.root.set("change", schemaLocation) | ||||
|  | ||||
|  | ||||
|         # layout, la dian requiere que los elementos | ||||
|         # esten ordenados segun el anexo tecnico | ||||
| @@ -538,14 +557,11 @@ class DIANNominaXML: | ||||
| class DIANNominaIndividual(DIANNominaXML): | ||||
|  | ||||
|     def __init__(self): | ||||
|         schema = "dian:gov:co:facturaelectronica:NominaIndividual NominaIndividualElectronicaXSD.xsd" | ||||
|  | ||||
|         super().__init__('NominaIndividual', schemaLocation=schema) | ||||
|         self.informacion_general_version = 'V1.0: Documento Soporte de Pago de Nómina Electrónica' | ||||
|  | ||||
| # TODO(bit4bit) confirmar que no tienen en comun con NominaIndividual | ||||
| class DIANNominaIndividualDeAjuste(DIANNominaXML): | ||||
|  | ||||
|     class Reemplazar(DIANNominaXML): | ||||
|         @dataclass | ||||
|         class Predecesor: | ||||
| @@ -554,6 +570,7 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML): | ||||
|             fecha_generacion: str | ||||
|  | ||||
|             def apply(self, fragment): | ||||
|                 fragment.set_element('./TipoNota', '1') | ||||
|                 fragment.set_element('./Reemplazar/ReemplazandoPredecesor', None, | ||||
|                                      # NIAE090 | ||||
|                                      NumeroPred = self.numero, | ||||
| @@ -566,7 +583,7 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML): | ||||
|         def __init__(self): | ||||
|             super().__init__('NominaIndividualDeAjuste', './Reemplazar') | ||||
|             # NIAE214 | ||||
|             self.root_fragment.set_element('./TipoNota', '1') | ||||
|             # self.root_fragment.set_element('./TipoNota', '1') | ||||
|  | ||||
|         def asignar_predecesor(self, predecesor): | ||||
|             if not isinstance(predecesor, self.Predecesor): | ||||
| @@ -583,6 +600,7 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML): | ||||
|             fecha_generacion: str | ||||
|  | ||||
|             def apply(self, fragment): | ||||
|                 fragment.set_element('./TipoNota', '2') | ||||
|                 fragment.set_element('./Eliminar/EliminandoPredecesor', None, | ||||
|                                      # NIAE090 | ||||
|                                      NumeroPred = self.numero, | ||||
| @@ -593,16 +611,17 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML): | ||||
|                                      ) | ||||
|  | ||||
|         def __init__(self): | ||||
|             schema = "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd" | ||||
|             super().__init__('NominaIndividualDeAjuste', './Eliminar') | ||||
|  | ||||
|             self.root_fragment.set_element('./TipoNota', '2') | ||||
|             # self.root_fragment.set_element('./TipoNota', '2') | ||||
|             self.informacion_general_version = "V1.0: Nota de Ajuste de Documento Soporte de Pago de Nómina Electrónica" | ||||
|  | ||||
|         def asignar_predecesor(self, predecesor): | ||||
|             if not isinstance(predecesor, self.Predecesor): | ||||
|                 raise ValueError("se espera tipo Eliminar.Predecesor") | ||||
|             predecesor.apply(self.fexml) | ||||
|              | ||||
|     def __init__(self): | ||||
|         super().__init__('NominaIndividualDeAjuste') | ||||
|  | ||||
|     def __init__(self): | ||||
|         schema = "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd" | ||||
|         super().__init__('NominaIndividualDeAjuste') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user