facho/fe/fe.py (DianXMLExtensionSoftwareSecurityCode): nuevo extension para adicion de codigo de seguridad
FossilOrigin-Name: 947190c281ca816b6802654d91ca8480a4e7e3afac477997f8ccb2377d08f52a
This commit is contained in:
		| @@ -118,9 +118,12 @@ class FachoXML: | |||||||
|         # construir las extensiones o adicionar en caso de indicar |         # construir las extensiones o adicionar en caso de indicar | ||||||
|         for extension in self.extensions: |         for extension in self.extensions: | ||||||
|             xpath, elements = extension.build(self) |             xpath, elements = extension.build(self) | ||||||
|             for new_element in elements: |             if isinstance(elements, str): | ||||||
|                 elem = self.find_or_create_element('/'+ root_tag + xpath) |                 elem = self.set_element('/'+ root_tag + xpath, elements) | ||||||
|                 self.builder.append(elem, new_element) |             else: | ||||||
|  |                 for new_element in elements: | ||||||
|  |                     elem = self.find_or_create_element('/'+ root_tag + xpath) | ||||||
|  |                     self.builder.append(elem, new_element) | ||||||
|  |  | ||||||
|     def fragment(self, xpath, append=False): |     def fragment(self, xpath, append=False): | ||||||
|         parent = self.find_or_create_element(xpath, append=append) |         parent = self.find_or_create_element(xpath, append=append) | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| from .fe import FeXML | from .fe import FeXML | ||||||
| from .fe import NAMESPACES | from .fe import NAMESPACES | ||||||
| from .fe import DianXMLExtensionSigner | from .fe import DianXMLExtensionSigner | ||||||
|  | from .fe import DianXMLExtensionSoftwareSecurityCode | ||||||
| from .fe import DianZIP | from .fe import DianZIP | ||||||
|   | |||||||
| @@ -76,7 +76,21 @@ class ConsultaResolucionesFacturacionPeticion(SOAPService): | |||||||
|     def build_response(self, as_dict): |     def build_response(self, as_dict): | ||||||
|         return ConsultaResolucionesFacturacionRespuesta.fromdict(as_dict) |         return ConsultaResolucionesFacturacionRespuesta.fromdict(as_dict) | ||||||
|  |  | ||||||
|  | @dataclass | ||||||
|  | class SendBillAsync: | ||||||
|  |     fileName: str | ||||||
|  |     contentFile: str | ||||||
|  |  | ||||||
|  |     def get_wsdl(self): | ||||||
|  |         return 'https://colombia-dian-webservices-input-sbx.azurewebsites.net/WcfDianCustomerServices.svc?wsdl' | ||||||
|  |  | ||||||
|  |     def get_service(self): | ||||||
|  |         return 'SendBillAsync' | ||||||
|  |  | ||||||
|  |     def build_response(self, as_dict): | ||||||
|  |         return {} | ||||||
|  |  | ||||||
|  |      | ||||||
| class DianClient: | class DianClient: | ||||||
|  |  | ||||||
|     def __init__(self, user, password): |     def __init__(self, user, password): | ||||||
|   | |||||||
| @@ -39,7 +39,23 @@ class FeXML(FachoXML): | |||||||
|         #self.find_or_create_element(self._cn) |         #self.find_or_create_element(self._cn) | ||||||
|  |  | ||||||
|  |  | ||||||
|          |  | ||||||
|  | class DianXMLExtensionSoftwareSecurityCode: | ||||||
|  |     # RESOLUCION 0001: pagina 535 | ||||||
|  |      | ||||||
|  |     def __init__(self, id_software: str, pin: str, invoice_ident: str): | ||||||
|  |         self.id_software = id_software | ||||||
|  |         self.pin = pin | ||||||
|  |         self.invoice_ident = invoice_ident | ||||||
|  |  | ||||||
|  |     def build(self, fachoxml): | ||||||
|  |         dian_path = '/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareSecurityCode' | ||||||
|  |         code = str(self.id_software) + str(self.pin) + str(self.invoice_ident) | ||||||
|  |         m = hashlib.sha384() | ||||||
|  |         m.update(code.encode('utf-8')) | ||||||
|  |         return dian_path, m.hexdigest() | ||||||
|  |  | ||||||
|  |      | ||||||
| class DianXMLExtensionSigner: | class DianXMLExtensionSigner: | ||||||
|     POLICY_ID = 'https://facturaelectronica.dian.gov.co/politicadefirma/v2/politicadefirmav2.pdf' |     POLICY_ID = 'https://facturaelectronica.dian.gov.co/politicadefirma/v2/politicadefirmav2.pdf' | ||||||
|     POLICY_NAME = 'Dian' |     POLICY_NAME = 'Dian' | ||||||
|   | |||||||
| @@ -35,3 +35,13 @@ def test_xmlsigned_with_passphrase_build(): | |||||||
|      |      | ||||||
|     assert elem is not None |     assert elem is not None | ||||||
|     #assert elem.findall('ds:SignedInfo', fe.NAMESPACES) is not None |     #assert elem.findall('ds:SignedInfo', fe.NAMESPACES) is not None | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def test_dian_extension_software_security_code(): | ||||||
|  |     security_code = fe.DianXMLExtensionSoftwareSecurityCode('idsoftware', '1234', '1') | ||||||
|  |     xml = fe.FeXML('Invoice', | ||||||
|  |                    'http://www.dian.gov.co/contratos/facturaelectronica/v1') | ||||||
|  |     xml.add_extension(security_code) | ||||||
|  |     xml.attach_extensions() | ||||||
|  |     content = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareSecurityCode') | ||||||
|  |     assert content is not None | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user