cli permite generar NominaIndividual

FossilOrigin-Name: c30edea460eb16340183c373ed448e3719e2277550882db2d2daafe7bd4bca7e
This commit is contained in:
bit4bit
2021-11-13 18:26:21 +00:00
parent aa3e14de95
commit 903b1bad64
6 changed files with 157 additions and 13 deletions

View File

@@ -301,14 +301,17 @@ class DianXMLExtensionSigner:
self._passphrase = passphrase.encode('utf-8')
return self
def _element_extension_content(self, fachoxml):
return fachoxml.builder.xpath(fachoxml.root, './ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent')
def sign_xml_string(self, document):
xml = LXMLBuilder.from_string(document)
signature = self.sign_xml_element(xml)
fachoxml = FachoXML(xml,nsmap=NAMESPACES)
#DIAN 1.7.-2020: FAB01
extcontent = fachoxml.builder.xpath(fachoxml.root, './ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent')
extcontent = self._element_extension_content(fachoxml)
fachoxml.append_element(extcontent, signature)
return fachoxml.tostring(xml_declaration=True, encoding='UTF-8')
@@ -372,7 +375,7 @@ class DianXMLExtensionSigner:
def build(self, fachoxml):
signature = self.sign_xml_element(fachoxml.root)
extcontent = fachoxml.builder.xpath(fachoxml.root, './ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent')
extcontent = self._element_extension_content(fachoxml)
fachoxml.append_element(extcontent, signature)

View File

@@ -8,8 +8,12 @@ def DIANWrite(xml, filename):
f.write(document)
def DIANWriteSigned(xml, filename, private_key, passphrase, use_cache_policy=False):
def DIANWriteSigned(xml, filename, private_key, passphrase, use_cache_policy=False, dian_signer=None):
document = xml.tostring(xml_declaration=True, encoding='UTF-8').encode('utf-8')
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
if dian_signer is None:
dian_signer = fe.DianXMLExtensionSigner
signer = dian_signer(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
with open(filename, 'w') as f:
f.write(signer.sign_xml_string(document))

View File

@@ -177,11 +177,9 @@ class DianXMLExtensionSigner(fe.DianXMLExtensionSigner):
def __init__(self, pkcs12_path, passphrase=None, mockpolicy=False):
super().__init__(pkcs12_path, passphrase=passphrase, mockpolicy=mockpolicy)
def build(self, fachoxml):
signature = self.sign_xml_element(fachoxml.root)
xpath = fachoxml.xpath_from_root('/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
extcontent = fachoxml.get_element(xpath)
fachoxml.append_element(extcontent, signature)
def _element_extension_content(self, fachoxml):
return fachoxml.builder.xpath(fachoxml.root, './ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
class DIANNominaXML:
def __init__(self, tag_document):