adiciona NIE071,NIE072,NIE073
FossilOrigin-Name: a04d79d7ce56391301a0babd48c413be10dfd628764b91471746041ca9175458
This commit is contained in:
		| @@ -123,8 +123,7 @@ class LXMLBuilder: | |||||||
|  |  | ||||||
|         for el in elem.getiterator(): |         for el in elem.getiterator(): | ||||||
|             is_optional = el.get('facho_optional', 'False') == 'True' |             is_optional = el.get('facho_optional', 'False') == 'True' | ||||||
|             if is_optional and el.getchildren() == []: |             if is_optional and el.getchildren() == [] and el.keys() == ['facho_optional']: | ||||||
|                 print(tostring(el)) |  | ||||||
|                 el.getparent().remove(el) |                 el.getparent().remove(el) | ||||||
|  |  | ||||||
|         return tostring(elem, **attrs).decode('utf-8') |         return tostring(elem, **attrs).decode('utf-8') | ||||||
| @@ -308,8 +307,12 @@ class FachoXML: | |||||||
|         xpath = self._path_xpath_for(xpath) |         xpath = self._path_xpath_for(xpath) | ||||||
|         elem = self.get_element(xpath) |         elem = self.get_element(xpath) | ||||||
|  |  | ||||||
|  |         if elem is None: | ||||||
|  |             raise ValueError("xpath %s not found" % (xpath)) | ||||||
|  |  | ||||||
|         for k, v in attrs.items(): |         for k, v in attrs.items(): | ||||||
|             self.builder.set_attribute(elem, k, v) |             if v is not None or str(v) != 'None': | ||||||
|  |                 self.builder.set_attribute(elem, k, str(v)) | ||||||
|         return self |         return self | ||||||
|  |  | ||||||
|     def get_element_attribute(self, xpath, attribute): |     def get_element_attribute(self, xpath, attribute): | ||||||
|   | |||||||
| @@ -255,3 +255,28 @@ def test_facho_xml_placeholder_set_element_to_optional_with_append(): | |||||||
|     xml.set_element('./B', '2') |     xml.set_element('./B', '2') | ||||||
|     xml.set_element('./B', '3', append_=True) |     xml.set_element('./B', '3', append_=True) | ||||||
|     assert xml.tostring() == '<root><A/><B>2</B><B>3</B><C/></root>' |     assert xml.tostring() == '<root><A/><B>2</B><B>3</B><C/></root>' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def test_facho_xml_set_attributes(): | ||||||
|  |     xml = facho.FachoXML('root') | ||||||
|  |     xml.find_or_create_element('./A') | ||||||
|  |  | ||||||
|  |     xml.set_attributes('./A', | ||||||
|  |                        value1 = '1', | ||||||
|  |                        value2 = '2' | ||||||
|  |                        ) | ||||||
|  |     assert xml.get_element_attribute('/root/A', 'value1') == '1' | ||||||
|  |     assert xml.get_element_attribute('/root/A', 'value2') == '2' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def test_facho_xml_set_attributes_not_set_optional(): | ||||||
|  |     xml = facho.FachoXML('root') | ||||||
|  |     xml.find_or_create_element('./A') | ||||||
|  |  | ||||||
|  |     xml.set_attributes('./A', | ||||||
|  |                        value1 = None, | ||||||
|  |                        value2 = '2' | ||||||
|  |                        ) | ||||||
|  |     with pytest.raises(KeyError): | ||||||
|  |         xml.get_element_attribute('/root/A', 'value1') | ||||||
|  |     assert xml.get_element_attribute('/root/A', 'value2') == '2' | ||||||
|   | |||||||
| @@ -20,3 +20,31 @@ def test_adicionar_devengado_Basico(): | |||||||
|     xml = nomina.toFachoXML() |     xml = nomina.toFachoXML() | ||||||
|     assert xml.get_element_attribute('/fe:NominaIndividual/Devengados/Basico', 'DiasTrabajados') == '30' |     assert xml.get_element_attribute('/fe:NominaIndividual/Devengados/Basico', 'DiasTrabajados') == '30' | ||||||
|     assert xml.get_element_attribute('/fe:NominaIndividual/Devengados/Basico', 'SueldoTrabajado') == '1000000.0' |     assert xml.get_element_attribute('/fe:NominaIndividual/Devengados/Basico', 'SueldoTrabajado') == '1000000.0' | ||||||
|  |  | ||||||
|  | def test_adicionar_devengado_transporte(): | ||||||
|  |     nomina = fe.nomina.DIANNominaIndividual() | ||||||
|  |  | ||||||
|  |     nomina.adicionar_devengado(fe.nomina.DevengadoTransporte( | ||||||
|  |         auxilio_transporte = fe.nomina.Amount(2_000_000) | ||||||
|  |     )) | ||||||
|  |  | ||||||
|  |     xml = nomina.toFachoXML() | ||||||
|  |     assert xml.get_element_attribute('/fe:NominaIndividual/Devengados/Transporte', 'AuxilioTransporte') == '2000000.0' | ||||||
|  |  | ||||||
|  | def test_adicionar_devengado_transporte_muchos(): | ||||||
|  |     nomina = fe.nomina.DIANNominaIndividual() | ||||||
|  |  | ||||||
|  |     nomina.adicionar_devengado(fe.nomina.DevengadoTransporte( | ||||||
|  |         auxilio_transporte = fe.nomina.Amount(2_000_000) | ||||||
|  |     )) | ||||||
|  |  | ||||||
|  |     nomina.adicionar_devengado(fe.nomina.DevengadoTransporte( | ||||||
|  |         auxilio_transporte = fe.nomina.Amount(3_000_000) | ||||||
|  |     )) | ||||||
|  |  | ||||||
|  |     xml = nomina.toFachoXML() | ||||||
|  |     print(xml) | ||||||
|  |     assert str(xml) == """ | ||||||
|  | <NominaIndividual xmlns:facho="http://git.disroot.org/Etrivial/facho" xmlns="http://www.dian.gov.co/contratos/facturaelectronica/v1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cdt="urn:DocumentInformation:names:specification:ubl:colombia:schema:xsd:DocumentInformationAggregateComponents-1" xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001" xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sts="dian:gov:co:facturaelectronica:Structures-2-1" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:sig="http://www.w3.org/2000/09/xmldsig#"><Devengados><Basico/><Transporte facho_optional="True" AuxilioTransporte="2000000.0"/><Transporte facho_optional="True" AuxilioTransporte="3000000.0"/></Devengados></NominaIndividual> | ||||||
|  | """ | ||||||
|  |    | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user