nuevas rutinas para almacenar xml.
facho/fe/form_xml.py(DIANWrite): escribe xml a archivo. facho/fe/form_xml.py(DIANWriteSigned): escribe xml firmado a archivo. FossilOrigin-Name: fbadde1c5c263033ccaa60c9fb69113829bc405adef684bc3d6497d56f1b95c3
This commit is contained in:
parent
f0533dee5e
commit
ee622f5fb6
10
facho/cli.py
10
facho/cli.py
@ -247,7 +247,7 @@ def generate_invoice(private_key, passphrase, scriptname, generate=False, ssl=Tr
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
import facho.fe.form as form
|
||||
from facho.fe.form_xml import DIANInvoiceXML
|
||||
from facho.fe.form_xml import DIANInvoiceXML, DIANWriteSigned,DIANWrite
|
||||
from facho import fe
|
||||
|
||||
invoice = module.invoice()
|
||||
@ -264,14 +264,10 @@ def generate_invoice(private_key, passphrase, scriptname, generate=False, ssl=Tr
|
||||
for extension in extensions:
|
||||
xml.add_extension(extension)
|
||||
|
||||
xmlstring = xml.tostringMACHETE(xml_declaration=True, encoding='UTF-8')
|
||||
if sign:
|
||||
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
||||
with open(output, 'w') as f:
|
||||
f.write(signer.sign_xml_string(xmlstring.encode('utf-8')))
|
||||
DIANWriteSigned(xml, output, private_key, passphrase, use_cache_policy)
|
||||
else:
|
||||
with open(output, 'w') as f:
|
||||
f.write(xmlstring)
|
||||
DIANWrite(xml, output)
|
||||
|
||||
|
||||
@click.command()
|
||||
|
@ -69,8 +69,7 @@ class FeXML(FachoXML):
|
||||
self._cn = root.rstrip('/')
|
||||
#self.find_or_create_element(self._cn)
|
||||
|
||||
# MACHETE se elimina xml namespace fe
|
||||
def tostringMACHETE(self, **kw):
|
||||
def tostring(self, **kw):
|
||||
return super().tostring(**kw)\
|
||||
.replace("fe:", "")\
|
||||
.replace("xmlns:fe", "xmlns")
|
||||
|
@ -1,6 +1,7 @@
|
||||
from . import fe
|
||||
from .form import *
|
||||
|
||||
|
||||
class DIANInvoiceXML(fe.FeXML):
|
||||
"""
|
||||
DianInvoiceXML mapea objeto form.Invoice a XML segun
|
||||
@ -389,3 +390,16 @@ class DIANInvoiceXML(fe.FeXML):
|
||||
fexml.set_payment_mean(invoice)
|
||||
|
||||
return fexml
|
||||
|
||||
|
||||
def DIANWrite(xml, filename):
|
||||
document = xml.tostring(xml_declaration=True, encoding='UTF-8')
|
||||
with open(filename, 'w') as f:
|
||||
f.write(document)
|
||||
|
||||
|
||||
def DIANWriteSigned(xml, filename, private_key, passphrase, use_cache_policy=False):
|
||||
document = xml.tostring(xml_declaration=True, encoding='UTF-8')
|
||||
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
||||
with open(filename, 'w') as f:
|
||||
f.write(signer.sign_xml_string(document))
|
||||
|
Loading…
Reference in New Issue
Block a user