From 30fb9eec9f2ab9e24a29f0ef9e6aab000a82cab2 Mon Sep 17 00:00:00 2001
From: "bit4bit@riseup.net" <bit4bit@riseup.net>
Date: Thu, 11 Jun 2020 20:45:32 +0000
Subject: [PATCH] facho/fe/fe.py (DianXMLExtensionSoftwareProvider): nueva
 extension para SoftwareProvider

FossilOrigin-Name: 4a475ab0e79b851fcf5575d309f1d8c8c929488b37b9a1b77d2fa8e8fffea499
---
 facho/fe/__init__.py |  1 +
 facho/fe/fe.py       | 14 ++++++++++++++
 tests/test_fe.py     | 12 ++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/facho/fe/__init__.py b/facho/fe/__init__.py
index 9738869..4e8b758 100644
--- a/facho/fe/__init__.py
+++ b/facho/fe/__init__.py
@@ -4,4 +4,5 @@ from .fe import DianXMLExtensionSigner
 from .fe import DianXMLExtensionSoftwareSecurityCode
 from .fe import DianXMLExtensionCUFE
 from .fe import DianXMLExtensionInvoiceAuthorization
+from .fe import DianXMLExtensionSoftwareProvider
 from .fe import DianZIP
diff --git a/facho/fe/fe.py b/facho/fe/fe.py
index e6b9a4e..c12e2e6 100644
--- a/facho/fe/fe.py
+++ b/facho/fe/fe.py
@@ -113,6 +113,20 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
         h.update(cufe.encode('utf-8'))
         return h.hexdigest()
 
+
+class DianXMLExtensionSoftwareProvider(FachoXMLExtension):
+    # RESOLUCION 0004: pagina 108
+
+    def __init__(self, nit: str, id_software: str):
+        self.nit = nit
+        self.id_software = id_software
+
+    def build(self, fexml):
+        software_provider = fexml.fragment('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareProvider')
+        software_provider.set_element('/sts:SoftwareProvider/sts:ProviderID', self.nit)
+        software_provider.set_element('/sts:SoftwareProvider/sts:SoftwareID', self.id_software)
+        return '', []
+
     
 class DianXMLExtensionSoftwareSecurityCode(FachoXMLExtension):
     # RESOLUCION 0001: pagina 535
diff --git a/tests/test_fe.py b/tests/test_fe.py
index 92d783e..5db990d 100644
--- a/tests/test_fe.py
+++ b/tests/test_fe.py
@@ -66,3 +66,15 @@ def test_dian_extension_invoice_authorization():
     xml.add_extension(inv_auth_ext)
     auth = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:InvoiceControl/sts:InvoiceAuthorization')
     assert auth == invoice_authorization
+
+def test_dian_extension_software_provider():
+    nit = '123456789'
+    id_software = 'ABCDASDF123'
+    software_provider_extension = fe.DianXMLExtensionSoftwareProvider(nit, id_software)
+    
+    xml = fe.FeXML('Invoice',
+                   'http://www.dian.gov.co/contratos/facturaelectronica/v1')
+    xml.add_extension(software_provider_extension)
+    
+    give_nit = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareProvider/sts:ProviderID')
+    assert nit == give_nit