facho/fe/fe.py (DianZIP): creado zip nombrando segun DIAN
FossilOrigin-Name: 6df54d31796b2c119bd6b1bfe5f30fafa7adf0521907012509104f4b1e267d7e
This commit is contained in:
@@ -191,3 +191,6 @@ class FachoXML:
|
||||
|
||||
def tostring(self):
|
||||
return self.builder.tostring(self.root)
|
||||
|
||||
def __str__(self):
|
||||
return self.tostring()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .fe import DianXMLExtensionSigner
|
||||
from .fe import FeXML
|
||||
from .fe import NAMESPACES
|
||||
from .fe import DianZIP
|
||||
|
||||
@@ -6,8 +6,10 @@ import xmlsig
|
||||
import xades
|
||||
from datetime import datetime
|
||||
import OpenSSL
|
||||
|
||||
import zipfile
|
||||
import warnings
|
||||
import hashlib
|
||||
from contextlib import contextmanager
|
||||
|
||||
NAMESPACES = {
|
||||
'fe': 'http://www.dian.gov.co/contratos/facturaelectronica/v1',
|
||||
@@ -124,3 +126,29 @@ class DianXMLExtensionSigner:
|
||||
return (dian_path, [signature])
|
||||
|
||||
|
||||
|
||||
class DianZIP:
|
||||
|
||||
# RESOLUCION 0001: pagina 540
|
||||
MAX_FILES = 50
|
||||
|
||||
def __init__(self, file_like):
|
||||
self.zipfile = zipfile.ZipFile(file_like, mode='w')
|
||||
self.num_files = 0
|
||||
|
||||
def add_invoice_xml(self, name, xml_data):
|
||||
self.num_files += 1
|
||||
# TODO cual es la norma para los nombres de archivos?
|
||||
m = hashlib.sha256()
|
||||
m.update(name.encode('utf-8'))
|
||||
filename = m.hexdigest() + '.xml'
|
||||
with self.zipfile.open(filename, 'w') as fp:
|
||||
fp.write(xml_data.encode('utf-8'))
|
||||
|
||||
return filename
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
return self.zipfile.close()
|
||||
|
||||
@@ -128,7 +128,8 @@ class Invoice(DataValidator):
|
||||
self.invoice_customer = None
|
||||
self.invoice_supplier = None
|
||||
self.invoice_lines = []
|
||||
|
||||
self.errors = []
|
||||
|
||||
def set_period(self, startdate, enddate):
|
||||
self.invoice_period_start = startdate
|
||||
self.invoice_period_end = enddate
|
||||
@@ -151,7 +152,11 @@ class Invoice(DataValidator):
|
||||
def validate(self):
|
||||
errors_customer = [('customer.%s' % (field), err) for field, err in self.invoice_customer.validate()]
|
||||
errors_supplier = [('supplier.%s' % (field), err) for field, err in self.invoice_customer.validate()]
|
||||
return errors_customer + errors_supplier
|
||||
self.errors = errors_customer + errors_supplier
|
||||
|
||||
def valid(self):
|
||||
self.validate()
|
||||
return not self.errors
|
||||
|
||||
def _calculate_legal_monetary_total(self):
|
||||
for invline in self.invoice_lines:
|
||||
|
||||
Reference in New Issue
Block a user