facho/cli.py: nuevo comando generate-invoice, el permite crear imprimir una factura xml desde un script
FossilOrigin-Name: ee656a60b05a0efb5c1f4e3ea517e28e01d7cd6b95fc5074c9f7cbf70b16c1d6
This commit is contained in:
parent
a369585f73
commit
95b79407a8
37
facho/cli.py
37
facho/cli.py
@ -53,14 +53,49 @@ def SendTestSetAsync(private_key, public_key, password, filename, zipfile):
|
|||||||
|
|
||||||
client = dian.DianSignatureClient(private_key, public_key, password=password)
|
client = dian.DianSignatureClient(private_key, public_key, password=password)
|
||||||
resp = client.request(dian.SendTestSetAsync(
|
resp = client.request(dian.SendTestSetAsync(
|
||||||
filename, zipfile.read().encode('utf-8')
|
filename, open(zipfile, 'r').read().encode('utf-8')
|
||||||
))
|
))
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option('--private-key', type=click.Path(exists=True))
|
||||||
|
@click.option('--passphrase')
|
||||||
|
@click.argument('scriptname', type=click.Path(exists=True), required=True)
|
||||||
|
def generate_invoice(private_key, passphrase, scriptname):
|
||||||
|
"""
|
||||||
|
imprime xml en pantalla.
|
||||||
|
SCRIPTNAME espera
|
||||||
|
def invoice() -> form.Invoice
|
||||||
|
def extensions(form.Invoice): -> List[facho.FachoXMLExtension]
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location('invoice', scriptname)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
|
||||||
|
import facho.fe.form as form
|
||||||
|
from facho import fe
|
||||||
|
|
||||||
|
invoice = module.invoice()
|
||||||
|
xml = form.DIANInvoiceXML(invoice)
|
||||||
|
|
||||||
|
extensions = module.extensions(invoice)
|
||||||
|
for extension in extensions:
|
||||||
|
xml.add_extension(extension)
|
||||||
|
|
||||||
|
if private_key:
|
||||||
|
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase)
|
||||||
|
xml.add_extension(signer)
|
||||||
|
xml.attach_extensions()
|
||||||
|
print(str(xml))
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def main():
|
def main():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
main.add_command(consultaResolucionesFacturacion)
|
main.add_command(consultaResolucionesFacturacion)
|
||||||
main.add_command(SendTestSetAsync)
|
main.add_command(SendTestSetAsync)
|
||||||
|
main.add_command(generate_invoice)
|
||||||
|
@ -6,6 +6,12 @@ from lxml.etree import Element, SubElement, tostring
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class FachoXMLExtension:
|
||||||
|
|
||||||
|
def build(self, fachoxml):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class LXMLBuilder:
|
class LXMLBuilder:
|
||||||
"""
|
"""
|
||||||
extrae la manipulacion de XML
|
extrae la manipulacion de XML
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# This file is part of facho. The COPYRIGHT file at the top level of
|
# This file is part of facho. The COPYRIGHT file at the top level of
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
|
|
||||||
from ..facho import FachoXML
|
from ..facho import FachoXML, FachoXMLExtension
|
||||||
import xmlsig
|
import xmlsig
|
||||||
import xades
|
import xades
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -40,7 +40,7 @@ class FeXML(FachoXML):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DianXMLExtensionSoftwareSecurityCode:
|
class DianXMLExtensionSoftwareSecurityCode(FachoXMLExtension):
|
||||||
# RESOLUCION 0001: pagina 535
|
# RESOLUCION 0001: pagina 535
|
||||||
|
|
||||||
def __init__(self, id_software: str, pin: str, invoice_ident: str):
|
def __init__(self, id_software: str, pin: str, invoice_ident: str):
|
||||||
@ -56,7 +56,8 @@ class DianXMLExtensionSoftwareSecurityCode:
|
|||||||
return dian_path, m.hexdigest()
|
return dian_path, m.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
class DianXMLExtensionSigner:
|
class DianXMLExtensionSigner(FachoXMLExtension):
|
||||||
|
# RESOLUCION 0001: pagina 516
|
||||||
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'
|
||||||
|
|
||||||
|
4
setup.py
4
setup.py
@ -45,6 +45,10 @@ setup(
|
|||||||
license="GNU General Public License v3",
|
license="GNU General Public License v3",
|
||||||
long_description=readme + '\n\n' + history,
|
long_description=readme + '\n\n' + history,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
package_data = {
|
||||||
|
# If any package contains *.txt or *.rst files, include them:
|
||||||
|
'': ['*.gc']
|
||||||
|
},
|
||||||
keywords='facho',
|
keywords='facho',
|
||||||
name='facho',
|
name='facho',
|
||||||
packages=find_packages(exclude=("tests",)),
|
packages=find_packages(exclude=("tests",)),
|
||||||
|
Loading…
Reference in New Issue
Block a user