facho/fe/fe.py (DianXMLExtensionAuthorizationProvider): nueva extension
FossilOrigin-Name: f8c2a2a2b1c844bffe8cde8c1ba8013ba196e198f4280395ad1f18f8204ca644
This commit is contained in:
parent
bd4f2b494e
commit
7ebf2a2fab
@ -213,6 +213,12 @@ class FachoXML:
|
|||||||
self.builder.set_attribute(elem, k, v)
|
self.builder.set_attribute(elem, k, v)
|
||||||
return elem
|
return elem
|
||||||
|
|
||||||
|
def set_attributes(self, xpath, **attrs):
|
||||||
|
xpath = self._normalize_xpath(xpath)
|
||||||
|
elem = self.get_element(xpath)
|
||||||
|
for k, v in attrs.items():
|
||||||
|
self.builder.set_attribute(elem, k, v)
|
||||||
|
|
||||||
def get_element(self, xpath):
|
def get_element(self, xpath):
|
||||||
xpath = self.fragment_prefix + self._normalize_xpath(xpath)
|
xpath = self.fragment_prefix + self._normalize_xpath(xpath)
|
||||||
return self.builder.xpath(self.root, xpath)
|
return self.builder.xpath(self.root, xpath)
|
||||||
|
@ -5,4 +5,5 @@ from .fe import DianXMLExtensionSoftwareSecurityCode
|
|||||||
from .fe import DianXMLExtensionCUFE
|
from .fe import DianXMLExtensionCUFE
|
||||||
from .fe import DianXMLExtensionInvoiceAuthorization
|
from .fe import DianXMLExtensionInvoiceAuthorization
|
||||||
from .fe import DianXMLExtensionSoftwareProvider
|
from .fe import DianXMLExtensionSoftwareProvider
|
||||||
|
from .fe import DianXMLExtensionAuthorizationProvider
|
||||||
from .fe import DianZIP
|
from .fe import DianZIP
|
||||||
|
@ -12,6 +12,12 @@ import hashlib
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from .data.dian import codelist
|
from .data.dian import codelist
|
||||||
|
|
||||||
|
SCHEME_AGENCY_ATTRS = {
|
||||||
|
'schemeAgencyName': 'CO, DIAN (Direccion de Impuestos y Aduanas Nacionales)',
|
||||||
|
'schemeAgencyID': '195'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NAMESPACES = {
|
NAMESPACES = {
|
||||||
'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1',
|
'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1',
|
||||||
'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
|
'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
|
||||||
@ -123,8 +129,10 @@ class DianXMLExtensionSoftwareProvider(FachoXMLExtension):
|
|||||||
|
|
||||||
def build(self, fexml):
|
def build(self, fexml):
|
||||||
software_provider = fexml.fragment('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareProvider')
|
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:ProviderID', self.nit,
|
||||||
software_provider.set_element('/sts:SoftwareProvider/sts:SoftwareID', self.id_software)
|
**SCHEME_AGENCY_ATTRS)
|
||||||
|
software_provider.set_element('/sts:SoftwareProvider/sts:SoftwareID', self.id_software,
|
||||||
|
**SCHEME_AGENCY_ATTRS)
|
||||||
return '', []
|
return '', []
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +150,7 @@ class DianXMLExtensionSoftwareSecurityCode(FachoXMLExtension):
|
|||||||
m = hashlib.sha384()
|
m = hashlib.sha384()
|
||||||
m.update(code.encode('utf-8'))
|
m.update(code.encode('utf-8'))
|
||||||
fexml.set_element(dian_path, m.hexdigest())
|
fexml.set_element(dian_path, m.hexdigest())
|
||||||
|
fexml.set_attributes(dian_path, **SCHEME_AGENCY_ATTRS)
|
||||||
return '', []
|
return '', []
|
||||||
|
|
||||||
|
|
||||||
@ -234,6 +243,19 @@ class DianXMLExtensionSigner(FachoXMLExtension):
|
|||||||
return '', []
|
return '', []
|
||||||
|
|
||||||
|
|
||||||
|
class DianXMLExtensionAuthorizationProvider(FachoXMLExtension):
|
||||||
|
# RESOLUCION 0004: pagina 176
|
||||||
|
|
||||||
|
def build(self, fexml):
|
||||||
|
dian_path = '/fe:Invoice/ext:UBLExtensions/ext:ExtensionContent/sts:DianExtensions/sts:AuthorizationProvider/sts:AuthorizationProviderID'
|
||||||
|
fexml.set_element(dian_path, '800197268')
|
||||||
|
|
||||||
|
attrs = {'schemeID': '4', 'schemeName': '31'}
|
||||||
|
attrs.update(SCHEME_AGENCY_ATTRS)
|
||||||
|
fexml.set_attributes(dian_path, **attrs)
|
||||||
|
return '', []
|
||||||
|
|
||||||
|
|
||||||
class DianXMLExtensionInvoiceAuthorization(FachoXMLExtension):
|
class DianXMLExtensionInvoiceAuthorization(FachoXMLExtension):
|
||||||
# RESOLUCION 0004: pagina 106
|
# RESOLUCION 0004: pagina 106
|
||||||
|
|
||||||
|
@ -228,7 +228,8 @@ class DIANInvoiceXML(fe.FeXML):
|
|||||||
invoice.invoice_supplier.address.street)
|
invoice.invoice_supplier.address.street)
|
||||||
|
|
||||||
fexml.set_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID',
|
fexml.set_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID',
|
||||||
invoice.invoice_supplier.ident)
|
invoice.invoice_supplier.ident,
|
||||||
|
**fe.SCHEME_AGENCY_ATTRS)
|
||||||
|
|
||||||
fexml.set_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:TaxLevelCode',
|
fexml.set_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:TaxLevelCode',
|
||||||
invoice.invoice_supplier.responsability_code)
|
invoice.invoice_supplier.responsability_code)
|
||||||
@ -251,7 +252,8 @@ class DIANInvoiceXML(fe.FeXML):
|
|||||||
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PhysicalLocation/cac:Address/cac:AddressLine/cbc:Line',
|
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PhysicalLocation/cac:Address/cac:AddressLine/cbc:Line',
|
||||||
invoice.invoice_customer.address.street)
|
invoice.invoice_customer.address.street)
|
||||||
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID',
|
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID',
|
||||||
invoice.invoice_customer.ident)
|
invoice.invoice_customer.ident,
|
||||||
|
**fe.SCHEME_AGENCY_ATTRS)
|
||||||
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:TaxLevelCode',
|
fexml.set_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:TaxLevelCode',
|
||||||
invoice.invoice_customer.responsability_code)
|
invoice.invoice_customer.responsability_code)
|
||||||
fexml.find_or_create_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme')
|
fexml.find_or_create_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme')
|
||||||
|
@ -78,3 +78,16 @@ def test_dian_extension_software_provider():
|
|||||||
|
|
||||||
give_nit = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareProvider/sts:ProviderID')
|
give_nit = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareProvider/sts:ProviderID')
|
||||||
assert nit == give_nit
|
assert nit == give_nit
|
||||||
|
|
||||||
|
def test_dian_extension_authorization_provider():
|
||||||
|
auth_provider_extension = fe.DianXMLExtensionAuthorizationProvider()
|
||||||
|
xml = fe.FeXML('Invoice',
|
||||||
|
'http://www.dian.gov.co/contratos/facturaelectronica/v1')
|
||||||
|
xml.add_extension(auth_provider_extension)
|
||||||
|
dian_nit = xml.get_element_text('/fe:Invoice/ext:UBLExtensions/ext:ExtensionContent/sts:DianExtensions/sts:AuthorizationProvider/sts:AuthorizationProviderID')
|
||||||
|
assert dian_nit == '800197268'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user