Fix - Issue #161
This commit is contained in:
parent
3c5c597b81
commit
f90539df82
|
@ -1,470 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import datetime
|
||||
from xml.etree import ElementTree as ET
|
||||
from xml.dom.minidom import parseString
|
||||
|
||||
from logbook import Logger
|
||||
|
||||
#~ from settings import DEBUG
|
||||
|
||||
|
||||
log = Logger('XML')
|
||||
CFDI_ACTUAL = 'cfdi33'
|
||||
NOMINA_ACTUAL = 'nomina12'
|
||||
|
||||
SAT = {
|
||||
'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'cfdi32': {
|
||||
'version': '3.2',
|
||||
'prefix': 'cfdi',
|
||||
'xmlns': 'http://www.sat.gob.mx/cfd/3',
|
||||
'schema': 'http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd',
|
||||
},
|
||||
'cfdi33': {
|
||||
'version': '3.3',
|
||||
'prefix': 'cfdi',
|
||||
'xmlns': 'http://www.sat.gob.mx/cfd/3',
|
||||
'schema': 'http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd',
|
||||
},
|
||||
'nomina11': {
|
||||
'version': '1.1',
|
||||
'prefix': 'nomina',
|
||||
'xmlns': 'http://www.sat.gob.mx/nomina',
|
||||
'schema': 'http://www.sat.gob.mx/nomina http://www.sat.gob.mx/sitio_internet/cfd/nomina/nomina11.xsd',
|
||||
},
|
||||
'nomina': {
|
||||
'version': '1.2',
|
||||
'prefix': 'nomina12',
|
||||
'xmlns': 'http://www.sat.gob.mx/nomina12',
|
||||
'schema': 'http://www.sat.gob.mx/nomina12 http://www.sat.gob.mx/sitio_internet/cfd/nomina/nomina12.xsd',
|
||||
},
|
||||
'locales': {
|
||||
'version': '1.0',
|
||||
'prefix': 'implocal',
|
||||
'xmlns': 'http://www.sat.gob.mx/implocal',
|
||||
'schema': ' http://www.sat.gob.mx/implocal http://www.sat.gob.mx/sitio_internet/cfd/implocal/implocal.xsd',
|
||||
},
|
||||
'donativo': {
|
||||
'version': '1.1',
|
||||
'prefix': 'donat',
|
||||
'xmlns': 'http://www.sat.gob.mx/donat',
|
||||
'schema': ' http://www.sat.gob.mx/donat http://www.sat.gob.mx/sitio_internet/cfd/donat/donat11.xsd',
|
||||
'leyenda': 'Este comprobante ampara un donativo, el cual será destinado por la donataria a los fines propios de su objeto social. En el caso de que los bienes donados hayan sido deducidos previamente para los efectos del impuesto sobre la renta, este donativo no es deducible. La reproducción no autorizada de este comprobante constituye un delito en los términos de las disposiciones fiscales.',
|
||||
},
|
||||
'ine': {
|
||||
'version': '1.1',
|
||||
'prefix': 'ine',
|
||||
'xmlns': 'http://www.sat.gob.mx/ine',
|
||||
'schema': ' http://www.sat.gob.mx/ine http://www.sat.gob.mx/sitio_internet/cfd/ine/ine11.xsd',
|
||||
},
|
||||
'edu': {
|
||||
'version': '1.0',
|
||||
'prefix': 'iedu',
|
||||
'xmlns': 'http://www.sat.gob.mx/iedu',
|
||||
'schema': ' http://www.sat.gob.mx/iedu http://www.sat.gob.mx/sitio_internet/cfd/ine/iedu.xsd',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class CFDI(object):
|
||||
|
||||
def __init__(self, version=CFDI_ACTUAL):
|
||||
self._sat_cfdi = SAT[version]
|
||||
self._xsi = SAT['xsi']
|
||||
self._pre = self._sat_cfdi['prefix']
|
||||
self._cfdi = None
|
||||
self._complemento = None
|
||||
self._impuestos_locales = False
|
||||
self._donativo = False
|
||||
self._ine = False
|
||||
<<<<<<< HEAD
|
||||
self._edu = False
|
||||
=======
|
||||
self._is_nomina = False
|
||||
>>>>>>> nomina
|
||||
self.error = ''
|
||||
|
||||
def _now(self):
|
||||
return datetime.datetime.now().isoformat()[:19]
|
||||
|
||||
def get_xml(self, datos):
|
||||
if not self._validate(datos):
|
||||
return ''
|
||||
|
||||
self._comprobante(datos['comprobante'])
|
||||
self._relacionados(datos['relacionados'])
|
||||
self._emisor(datos['emisor'])
|
||||
self._receptor(datos['receptor'])
|
||||
self._conceptos(datos['conceptos'])
|
||||
self._impuestos(datos['impuestos'])
|
||||
self._locales(datos['impuestos'])
|
||||
self._donatarias(datos['donativo'])
|
||||
self._complementos(datos['complementos'])
|
||||
|
||||
if 'nomina' in datos:
|
||||
self._nomina(datos['nomina'])
|
||||
|
||||
return self._to_pretty_xml(ET.tostring(self._cfdi, encoding='utf-8'))
|
||||
|
||||
def add_sello(self, sello):
|
||||
self._cfdi.attrib['Sello'] = sello
|
||||
return self._to_pretty_xml(ET.tostring(self._cfdi, encoding='utf-8'))
|
||||
|
||||
def _to_pretty_xml(self, source):
|
||||
tree = parseString(source)
|
||||
xml = tree.toprettyxml(encoding='utf-8').decode('utf-8')
|
||||
return xml
|
||||
|
||||
def _validate(self, datos):
|
||||
if datos['impuestos']:
|
||||
if datos['impuestos']['total_locales_trasladados'] or \
|
||||
datos['impuestos']['total_locales_retenciones']:
|
||||
self._impuestos_locales = True
|
||||
|
||||
if datos['donativo']:
|
||||
self._donativo = True
|
||||
|
||||
if datos['complementos']:
|
||||
if 'ine' in datos['complementos']:
|
||||
self._ine = True
|
||||
|
||||
self._edu = datos['edu']
|
||||
|
||||
if 'nomina' in datos:
|
||||
self._is_nomina = True
|
||||
return self._validate_nomina(datos)
|
||||
|
||||
return True
|
||||
|
||||
def _validate_nomina(self, datos):
|
||||
return True
|
||||
|
||||
def _comprobante(self, datos):
|
||||
attributes = {}
|
||||
attributes['xmlns:{}'.format(self._pre)] = self._sat_cfdi['xmlns']
|
||||
attributes['xmlns:xsi'] = self._xsi
|
||||
|
||||
schema_locales = ''
|
||||
if self._impuestos_locales:
|
||||
name = 'xmlns:{}'.format(SAT['locales']['prefix'])
|
||||
attributes[name] = SAT['locales']['xmlns']
|
||||
schema_locales = SAT['locales']['schema']
|
||||
|
||||
schema_donativo = ''
|
||||
if self._donativo:
|
||||
name = 'xmlns:{}'.format(SAT['donativo']['prefix'])
|
||||
attributes[name] = SAT['donativo']['xmlns']
|
||||
schema_donativo = SAT['donativo']['schema']
|
||||
|
||||
schema_ine = ''
|
||||
if self._ine:
|
||||
name = 'xmlns:{}'.format(SAT['ine']['prefix'])
|
||||
attributes[name] = SAT['ine']['xmlns']
|
||||
schema_ine = SAT['ine']['schema']
|
||||
|
||||
<<<<<<< HEAD
|
||||
schema_edu = ''
|
||||
if self._edu:
|
||||
name = 'xmlns:{}'.format(SAT['edu']['prefix'])
|
||||
attributes[name] = SAT['edu']['xmlns']
|
||||
schema_edu = SAT['edu']['schema']
|
||||
|
||||
attributes['xsi:schemaLocation'] = self._sat_cfdi['schema'] + \
|
||||
schema_locales + schema_donativo + schema_ine + schema_edu
|
||||
=======
|
||||
schema_nomina = ''
|
||||
if self._nomina:
|
||||
name = 'xmlns:{}'.format(SAT['nomina']['prefix'])
|
||||
attributes[name] = SAT['nomina']['xmlns']
|
||||
schema_nomina = SAT['nomina']['schema']
|
||||
|
||||
attributes['xsi:schemaLocation'] = self._sat_cfdi['schema'] + \
|
||||
schema_locales + schema_donativo + schema_ine + schema_nomina
|
||||
>>>>>>> nomina
|
||||
attributes.update(datos)
|
||||
|
||||
if not 'Version' in attributes:
|
||||
attributes['Version'] = self._sat_cfdi['version']
|
||||
if not 'Fecha' in attributes:
|
||||
attributes['Fecha'] = self._now()
|
||||
|
||||
self._cfdi = ET.Element('{}:Comprobante'.format(self._pre), attributes)
|
||||
return
|
||||
|
||||
def _relacionados(self, datos):
|
||||
if not datos or not datos['tipo'] or not datos['cfdis']:
|
||||
return
|
||||
|
||||
node_name = '{}:CfdiRelacionados'.format(self._pre)
|
||||
value = {'TipoRelacion': datos['tipo']}
|
||||
node = ET.SubElement(self._cfdi, node_name, value)
|
||||
for uuid in datos['cfdis']:
|
||||
node_name = '{}:CfdiRelacionado'.format(self._pre)
|
||||
value = {'UUID': uuid}
|
||||
ET.SubElement(node, node_name, value)
|
||||
return
|
||||
|
||||
def _emisor(self, datos):
|
||||
node_name = '{}:Emisor'.format(self._pre)
|
||||
emisor = ET.SubElement(self._cfdi, node_name, datos)
|
||||
return
|
||||
|
||||
def _receptor(self, datos):
|
||||
node_name = '{}:Receptor'.format(self._pre)
|
||||
emisor = ET.SubElement(self._cfdi, node_name, datos)
|
||||
return
|
||||
|
||||
def _conceptos(self, datos):
|
||||
from xml.sax.saxutils import escape, unescape
|
||||
|
||||
conceptos = ET.SubElement(self._cfdi, '{}:Conceptos'.format(self._pre))
|
||||
for row in reversed(datos):
|
||||
# ~ print (row['Descripcion'])
|
||||
# ~ xml = escape(xml.encode('ascii', 'xmlcharrefreplace').decode('utf-8'), False)
|
||||
# ~ row['Descripcion'] = escape(row['Descripcion'].replace('\n', ' '), False)
|
||||
# ~ row['Descripcion'] = row['Descripcion'].replace('\n', '
')
|
||||
# ~ print (row['Descripcion'])
|
||||
|
||||
complemento = {}
|
||||
if 'complemento' in row:
|
||||
complemento = row.pop('complemento')
|
||||
cuenta_predial = row.pop('CuentaPredial', '')
|
||||
pedimento = row.pop('Pedimento', '')
|
||||
student = row.pop('student', '')
|
||||
|
||||
taxes = {}
|
||||
if 'impuestos' in row:
|
||||
taxes = row.pop('impuestos')
|
||||
node_name = '{}:Concepto'.format(self._pre)
|
||||
concepto = ET.SubElement(conceptos, node_name, row)
|
||||
|
||||
if taxes:
|
||||
node_name = '{}:Impuestos'.format(self._pre)
|
||||
impuestos = ET.SubElement(concepto, node_name)
|
||||
if 'traslados' in taxes and taxes['traslados']:
|
||||
node_name = '{}:Traslados'.format(self._pre)
|
||||
traslados = ET.SubElement(impuestos, node_name)
|
||||
for traslado in taxes['traslados']:
|
||||
ET.SubElement(
|
||||
traslados, '{}:Traslado'.format(self._pre), traslado)
|
||||
if 'retenciones' in taxes and taxes['retenciones']:
|
||||
node_name = '{}:Retenciones'.format(self._pre)
|
||||
retenciones = ET.SubElement(impuestos, node_name)
|
||||
for retencion in taxes['retenciones']:
|
||||
ET.SubElement(
|
||||
retenciones, '{}:Retencion'.format(self._pre), retencion)
|
||||
|
||||
if pedimento:
|
||||
attributes = {'NumeroPedimento': pedimento}
|
||||
node_name = '{}:InformacionAduanera'.format(self._pre)
|
||||
ET.SubElement(concepto, node_name, attributes)
|
||||
|
||||
if cuenta_predial:
|
||||
attributes = {'Numero': cuenta_predial}
|
||||
node_name = '{}:CuentaPredial'.format(self._pre)
|
||||
ET.SubElement(concepto, node_name, attributes)
|
||||
|
||||
if student:
|
||||
node_name = '{}:ComplementoConcepto'.format(self._pre)
|
||||
complemento = ET.SubElement(concepto, node_name)
|
||||
ET.SubElement(complemento, 'iedu:instEducativas', student)
|
||||
return
|
||||
|
||||
def _impuestos(self, datos):
|
||||
if self._is_nomina:
|
||||
return
|
||||
|
||||
if not datos:
|
||||
node_name = '{}:Impuestos'.format(self._pre)
|
||||
ET.SubElement(self._cfdi, node_name)
|
||||
return
|
||||
|
||||
attributes = {}
|
||||
fields = ('TotalImpuestosTrasladados', 'TotalImpuestosRetenidos')
|
||||
for field in fields:
|
||||
if field in datos:
|
||||
attributes[field] = datos[field]
|
||||
node_name = '{}:Impuestos'.format(self._pre)
|
||||
impuestos = ET.SubElement(self._cfdi, node_name, attributes)
|
||||
|
||||
if 'retenciones' in datos and datos['retenciones']:
|
||||
retenciones = ET.SubElement(impuestos, '{}:Retenciones'.format(self._pre))
|
||||
for row in datos['retenciones']:
|
||||
ET.SubElement(retenciones, '{}:Retencion'.format(self._pre), row)
|
||||
|
||||
if 'traslados' in datos and datos['traslados']:
|
||||
traslados = ET.SubElement(impuestos, '{}:Traslados'.format(self._pre))
|
||||
for row in datos['traslados']:
|
||||
ET.SubElement(traslados, '{}:Traslado'.format(self._pre), row)
|
||||
return
|
||||
|
||||
def _nomina(self, datos):
|
||||
pre = SAT['nomina']['prefix']
|
||||
|
||||
if self._complemento is None:
|
||||
self._complemento = ET.SubElement(
|
||||
self._cfdi, '{}:Complemento'.format(self._pre))
|
||||
|
||||
emisor = datos.pop('emisor', None)
|
||||
receptor = datos.pop('receptor', None)
|
||||
percepciones = datos.pop('percepciones', None)
|
||||
deducciones = datos.pop('deducciones', None)
|
||||
otros_pagos = datos.pop('otros_pagos', ())
|
||||
incapacidades = datos.pop('incapacidades', ())
|
||||
|
||||
nomina = ET.SubElement(
|
||||
self._complemento, '{}:Nomina'.format(pre), datos['nomina'])
|
||||
|
||||
if emisor:
|
||||
ET.SubElement(nomina, '{}:Emisor'.format(pre), emisor)
|
||||
|
||||
if receptor:
|
||||
node = ET.SubElement(nomina, '{}:Receptor'.format(pre), receptor)
|
||||
|
||||
if percepciones:
|
||||
details = percepciones.pop('details', None)
|
||||
hours_extra = percepciones.pop('hours_extra', None)
|
||||
separacion = percepciones.pop('separacion', None)
|
||||
if details:
|
||||
node = ET.SubElement(nomina, '{}:Percepciones'.format(pre), percepciones)
|
||||
for row in details:
|
||||
nodep = ET.SubElement(node, '{}:Percepcion'.format(pre), row)
|
||||
if row['TipoPercepcion'] == '019' and hours_extra:
|
||||
for he in hours_extra:
|
||||
ET.SubElement(nodep, '{}:HorasExtra'.format(pre), he)
|
||||
hours_extra = None
|
||||
if separacion:
|
||||
ET.SubElement(node, '{}:SeparacionIndemnizacion'.format(pre), separacion)
|
||||
|
||||
if deducciones:
|
||||
details = deducciones.pop('details', None)
|
||||
if details:
|
||||
deducciones = ET.SubElement(nomina, '{}:Deducciones'.format(pre), deducciones)
|
||||
for row in details:
|
||||
ET.SubElement(deducciones, '{}:Deduccion'.format(pre), row)
|
||||
|
||||
if otros_pagos:
|
||||
node = ET.SubElement(nomina, '{}:OtrosPagos'.format(pre))
|
||||
for row in otros_pagos:
|
||||
subsidio = row.pop('subsidio', None)
|
||||
subnode = ET.SubElement(node, '{}:OtroPago'.format(pre), row)
|
||||
if subsidio:
|
||||
ET.SubElement(subnode, '{}:SubsidioAlEmpleo'.format(pre), subsidio)
|
||||
|
||||
if incapacidades:
|
||||
node = ET.SubElement(nomina, '{}:Incapacidades'.format(pre))
|
||||
for row in incapacidades:
|
||||
ET.SubElement(node, '{}:Incapacidad'.format(pre), row)
|
||||
return
|
||||
|
||||
def _locales(self, datos):
|
||||
if not self._impuestos_locales:
|
||||
return
|
||||
|
||||
if self._complemento is None:
|
||||
self._complemento = ET.SubElement(
|
||||
self._cfdi, '{}:Complemento'.format(self._pre))
|
||||
|
||||
attributes = {}
|
||||
attributes['version'] = SAT['locales']['version']
|
||||
if not datos['total_locales_trasladados']:
|
||||
datos['total_locales_trasladados'] = '0.00'
|
||||
attributes['TotaldeTraslados'] = datos['total_locales_trasladados']
|
||||
if not datos['total_locales_retenciones']:
|
||||
datos['total_locales_retenciones'] = '0.00'
|
||||
attributes['TotaldeRetenciones'] = datos['total_locales_retenciones']
|
||||
|
||||
node = ET.SubElement(
|
||||
self._complemento, 'implocal:ImpuestosLocales', attributes)
|
||||
|
||||
for retencion in datos['locales_retenciones']:
|
||||
ET.SubElement(node, 'implocal:RetencionesLocales', retencion)
|
||||
for traslado in datos['locales_trasladados']:
|
||||
ET.SubElement(node, 'implocal:TrasladosLocales', traslado)
|
||||
return
|
||||
|
||||
def _donatarias(self, datos):
|
||||
if not datos:
|
||||
return
|
||||
|
||||
if self._complemento is None:
|
||||
self._complemento = ET.SubElement(
|
||||
self._cfdi, '{}:Complemento'.format(self._pre))
|
||||
|
||||
attributes = {}
|
||||
attributes['version'] = SAT['donativo']['version']
|
||||
attributes['leyenda'] = SAT['donativo']['leyenda']
|
||||
attributes.update(datos)
|
||||
|
||||
node = ET.SubElement(self._complemento, 'donat:Donatarias', attributes)
|
||||
|
||||
return
|
||||
|
||||
def _complementos(self, datos):
|
||||
if not datos:
|
||||
return
|
||||
|
||||
if self._complemento is None:
|
||||
self._complemento = ET.SubElement(
|
||||
self._cfdi, '{}:Complemento'.format(self._pre))
|
||||
|
||||
if 'ine' in datos:
|
||||
atributos = {'Version': SAT['ine']['version']}
|
||||
atributos.update(datos['ine'])
|
||||
ET.SubElement(self._complemento, 'ine:INE', atributos)
|
||||
|
||||
if 'ce' in datos:
|
||||
pre = 'cce11'
|
||||
datos = datos.pop('ce')
|
||||
emisor = datos.pop('emisor')
|
||||
propietario = datos.pop('propietario')
|
||||
receptor = datos.pop('receptor')
|
||||
destinatario = datos.pop('destinatario')
|
||||
conceptos = datos.pop('conceptos')
|
||||
|
||||
attributes = {}
|
||||
attributes['xmlns:{}'.format(pre)] = \
|
||||
'http://www.sat.gob.mx/ComercioExterior11'
|
||||
attributes['xsi:schemaLocation'] = \
|
||||
'http://www.sat.gob.mx/ComercioExterior11 ' \
|
||||
'http://www.sat.gob.mx/sitio_internet/cfd/ComercioExterior11/ComercioExterior11.xsd'
|
||||
attributes.update(datos)
|
||||
ce = ET.SubElement(
|
||||
complemento, '{}:ComercioExterior'.format(pre), attributes)
|
||||
|
||||
attributes = {}
|
||||
if 'Curp' in emisor:
|
||||
attributes = {'Curp': emisor.pop('Curp')}
|
||||
node = ET.SubElement(ce, '{}:Emisor'.format(pre), attributes)
|
||||
ET.SubElement(node, '{}:Domicilio'.format(pre), emisor)
|
||||
|
||||
if propietario:
|
||||
ET.SubElement(ce, '{}:Propietario'.format(pre), propietario)
|
||||
|
||||
attributes = {}
|
||||
if 'NumRegIdTrib' in receptor:
|
||||
attributes = {'NumRegIdTrib': receptor.pop('NumRegIdTrib')}
|
||||
node = ET.SubElement(ce, '{}:Receptor'.format(pre), attributes)
|
||||
ET.SubElement(node, '{}:Domicilio'.format(pre), receptor)
|
||||
|
||||
attributes = {}
|
||||
if 'NumRegIdTrib' in destinatario:
|
||||
attributes = {'NumRegIdTrib': destinatario.pop('NumRegIdTrib')}
|
||||
if 'Nombre' in destinatario:
|
||||
attributes.update({'Nombre': destinatario.pop('Nombre')})
|
||||
node = ET.SubElement(ce, '{}:Destinatario'.format(pre), attributes)
|
||||
ET.SubElement(node, '{}:Domicilio'.format(pre), destinatario)
|
||||
|
||||
node = ET.SubElement(ce, '{}:Mercancias'.format(pre))
|
||||
fields = ('Marca', 'Modelo', 'SubModelo', 'NumeroSerie')
|
||||
for row in conceptos:
|
||||
detalle = {}
|
||||
for f in fields:
|
||||
if f in row:
|
||||
detalle[f] = row.pop(f)
|
||||
concepto = ET.SubElement(node, '{}:Mercancia'.format(pre), row)
|
||||
if detalle:
|
||||
ET.SubElement(
|
||||
concepto, '{}:DescripcionesEspecificas'.format(pre), detalle)
|
||||
return
|
|
@ -1,82 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import falcon
|
||||
from falcon_multipart.middleware import MultipartMiddleware
|
||||
from beaker.middleware import SessionMiddleware
|
||||
|
||||
from middleware import (
|
||||
AuthMiddleware,
|
||||
JSONTranslator,
|
||||
ConnectionMiddleware,
|
||||
static,
|
||||
handle_404
|
||||
)
|
||||
from models.db import StorageEngine
|
||||
from controllers.main import (AppEmpresas,
|
||||
AppLogin, AppLogout, AppAdmin, AppEmisor, AppConfig,
|
||||
AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios,
|
||||
AppDocumentos, AppFiles, AppPreInvoices, AppCuentasBanco,
|
||||
<<<<<<< HEAD
|
||||
AppMovimientosBanco, AppTickets, AppStudents
|
||||
=======
|
||||
AppMovimientosBanco, AppTickets, AppEmployees, AppNomina
|
||||
>>>>>>> nomina
|
||||
)
|
||||
|
||||
|
||||
from settings import DEBUG, MV, PATH_SESSIONS
|
||||
|
||||
|
||||
db = StorageEngine()
|
||||
|
||||
api = falcon.API(middleware=[
|
||||
AuthMiddleware(),
|
||||
JSONTranslator(),
|
||||
ConnectionMiddleware(),
|
||||
MultipartMiddleware(),
|
||||
])
|
||||
api.req_options.auto_parse_form_urlencoded = True
|
||||
api.add_sink(handle_404, '')
|
||||
|
||||
api.add_route('/empresas', AppEmpresas(db))
|
||||
api.add_route('/', AppLogin(db))
|
||||
api.add_route('/logout', AppLogout(db))
|
||||
api.add_route('/admin', AppAdmin(db))
|
||||
api.add_route('/emisor', AppEmisor(db))
|
||||
api.add_route('/folios', AppFolios(db))
|
||||
api.add_route('/main', AppMain(db))
|
||||
api.add_route('/values/{table}', AppValues(db))
|
||||
api.add_route('/files/{table}', AppFiles(db))
|
||||
api.add_route('/config', AppConfig(db))
|
||||
api.add_route('/doc/{type_doc}/{id_doc}', AppDocumentos(db))
|
||||
api.add_route('/partners', AppPartners(db))
|
||||
api.add_route('/products', AppProducts(db))
|
||||
api.add_route('/invoices', AppInvoices(db))
|
||||
api.add_route('/preinvoices', AppPreInvoices(db))
|
||||
api.add_route('/tickets', AppTickets(db))
|
||||
api.add_route('/cuentasbanco', AppCuentasBanco(db))
|
||||
api.add_route('/movbanco', AppMovimientosBanco(db))
|
||||
<<<<<<< HEAD
|
||||
api.add_route('/students', AppStudents(db))
|
||||
=======
|
||||
api.add_route('/employees', AppEmployees(db))
|
||||
api.add_route('/nomina', AppNomina(db))
|
||||
>>>>>>> nomina
|
||||
|
||||
|
||||
# ~ Activa si usas waitress y NO estas usando servidor web
|
||||
# ~ api.add_sink(static, '/static')
|
||||
|
||||
session_options = {
|
||||
'session.type': 'file',
|
||||
'session.cookie_expires': True,
|
||||
'session.httponly': True,
|
||||
'session.secure': True,
|
||||
'session.data_dir': PATH_SESSIONS['data'],
|
||||
'session.lock_dir': PATH_SESSIONS['lock'],
|
||||
}
|
||||
if DEBUG or MV:
|
||||
session_options['session.secure'] = False
|
||||
|
||||
app = SessionMiddleware(api, session_options)
|
||||
|
|
@ -1,398 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from . import main
|
||||
|
||||
|
||||
class StorageEngine(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def authenticate(self, args):
|
||||
return main.authenticate(args)
|
||||
|
||||
def get_employees(self, values):
|
||||
return main.Empleados.get_by(values)
|
||||
|
||||
def get_nomina(self, values):
|
||||
return main.CfdiNomina.get_by(values)
|
||||
|
||||
def nomina(self, values):
|
||||
opt = values.pop('opt')
|
||||
if opt == 'cancel':
|
||||
return main.CfdiNomina.cancel(int(values['id']))
|
||||
|
||||
def empresa_agregar(self, values):
|
||||
return main.empresa_agregar(values['alta_rfc'], False)
|
||||
|
||||
def empresa_borrar(self, values):
|
||||
return main.empresa_borrar(values['rfc'])
|
||||
|
||||
def _get_empresas(self, values):
|
||||
return main.get_empresas()
|
||||
|
||||
def get_values(self, table, values=None, session=None):
|
||||
if table in ('allusuarios', 'usuarioupdate'):
|
||||
return getattr(self, '_get_{}'.format(table))(values, session)
|
||||
return getattr(self, '_get_{}'.format(table))(values)
|
||||
|
||||
def _get_schoolgroups(self, values):
|
||||
return main.Grupos.get_by(values)
|
||||
|
||||
def _get_nivedusat(self, values):
|
||||
return main.SATNivelesEducativos.get_by()
|
||||
|
||||
def _get_niveduall(self, values):
|
||||
return main.NivelesEducativos.get_all()
|
||||
|
||||
def _get_titlelogin(self, values):
|
||||
return main.get_title_app(2)
|
||||
|
||||
def _get_canopenpre(self, values):
|
||||
return main.PreFacturasDetalle.can_open(values['id'])
|
||||
|
||||
def _get_importinvoice(self, values):
|
||||
return main.import_invoice()
|
||||
|
||||
def _get_main(self, values):
|
||||
return main.config_main()
|
||||
|
||||
def _get_configtimbrar(self, values):
|
||||
return main.config_timbrar()
|
||||
|
||||
def _get_invoicenotes(self, values):
|
||||
return main.Facturas.get_notes(values['id'])
|
||||
|
||||
def save_invoice_notes(self, values):
|
||||
return main.Facturas.save_notes(values)
|
||||
|
||||
def _get_configticket(self, values):
|
||||
return main.config_ticket()
|
||||
|
||||
def _get_saldocuenta(self, values):
|
||||
return main.CuentasBanco.get_saldo(values['id'])
|
||||
|
||||
def _get_validartimbrar(self, values):
|
||||
return main.validar_timbrar()
|
||||
|
||||
def _get_preproductos(self, values):
|
||||
return main.PreFacturasDetalle.facturar(values['id'])
|
||||
|
||||
def upload_file(self, session, table, file_obj):
|
||||
if not 'rfc' in session:
|
||||
return {'status': 'error'}
|
||||
return main.upload_file(session['rfc'], table, file_obj)
|
||||
|
||||
def get_config(self, values):
|
||||
return main.Configuracion.get_(values)
|
||||
|
||||
def add_config(self, values):
|
||||
return main.Configuracion.add(values)
|
||||
|
||||
def add_cert(self, file_obj):
|
||||
return main.Certificado.add(file_obj)
|
||||
|
||||
def validate_cert(self, values, session):
|
||||
return main.Certificado.validate(values, session)
|
||||
|
||||
def validate_email(self, values):
|
||||
return main.test_correo(values)
|
||||
|
||||
def send_email(self, values, session):
|
||||
return main.Facturas.send(values['id'], session['rfc'])
|
||||
|
||||
def enviar_prefac(self, values):
|
||||
return main.PreFacturas.enviar(values['id'])
|
||||
|
||||
def _get_cancelinvoice(self, values):
|
||||
return main.Facturas.cancel(values['id'])
|
||||
|
||||
def _get_statussat(self, values):
|
||||
return main.Facturas.get_status_sat(values['id'])
|
||||
|
||||
def _get_filteryears(self, values):
|
||||
years1 = main.Facturas.filter_years()
|
||||
years2 = main.PreFacturas.filter_years()
|
||||
return [years1, years2]
|
||||
|
||||
def _get_filteryearsticket(self, values):
|
||||
return main.Tickets.filter_years()
|
||||
|
||||
def _get_filteryearsnomina(self, values):
|
||||
return main.CfdiNomina.filter_years()
|
||||
|
||||
def _get_cuentayears(self, values):
|
||||
return main.CuentasBanco.get_years()
|
||||
|
||||
def _get_cert(self, values):
|
||||
return main.Certificado.get_data()
|
||||
|
||||
def _get_cp(self, values):
|
||||
return main.get_cp(values['cp'])
|
||||
|
||||
def _get_formapago(self, values):
|
||||
return main.SATFormaPago.get_activos(values)
|
||||
|
||||
def _get_tiporelacion(self, values):
|
||||
return main.SATTipoRelacion.get_activos(values)
|
||||
|
||||
def _get_condicionespago(self, values):
|
||||
return main.CondicionesPago.get_()
|
||||
|
||||
def _get_categorias(self, values):
|
||||
return main.Categorias.get_all()
|
||||
|
||||
def _get_newkey(self, values):
|
||||
return main.Productos.next_key()
|
||||
|
||||
def _get_unidades(self, values):
|
||||
return main.SATUnidades.get_activos()
|
||||
|
||||
def add_moneda(self, values):
|
||||
return main.SATMonedas.add(values)
|
||||
|
||||
def add_unidad(self, values):
|
||||
return main.SATUnidades.add(values)
|
||||
|
||||
def add_impuesto(self, values):
|
||||
return main.SATImpuestos.add(values)
|
||||
|
||||
def add_usuario(self, values):
|
||||
return main.Usuarios.add(values)
|
||||
|
||||
def edit_usuario(self, values):
|
||||
return main.Usuarios.edit(values)
|
||||
|
||||
def _get_taxes(self, values):
|
||||
return main.SATImpuestos.get_activos()
|
||||
|
||||
def _get_alltaxes(self, values):
|
||||
return main.SATImpuestos.get_()
|
||||
|
||||
def _get_allcurrencies(self, values):
|
||||
return main.SATMonedas.get_()
|
||||
|
||||
def _get_allbancos(self, values):
|
||||
return main.SATBancos.get_()
|
||||
|
||||
def _get_allunidades(self, values):
|
||||
return main.SATUnidades.get_()
|
||||
|
||||
def _get_allformasdepago(self, values):
|
||||
return main.SATFormaPago.get_()
|
||||
|
||||
def _get_allusoscfdi(self, values):
|
||||
return main.SATUsoCfdi.get_all()
|
||||
|
||||
def _get_allusuarios(self, values, session):
|
||||
return main.Usuarios.get_(session['userobj'])
|
||||
|
||||
def _get_usuarioupdate(self, values, session):
|
||||
return main.Usuarios.actualizar(values, session['userobj'])
|
||||
|
||||
def _get_taxupdate(self, values):
|
||||
return main.SATImpuestos.actualizar(values)
|
||||
|
||||
def _get_currencyupdate(self, values):
|
||||
return main.SATMonedas.actualizar(values)
|
||||
|
||||
def _get_bancoupdate(self, values):
|
||||
return main.SATBancos.actualizar(values)
|
||||
|
||||
def _get_unidadupdate(self, values):
|
||||
return main.SATUnidades.actualizar(values)
|
||||
|
||||
def _get_formasdepagoupdate(self, values):
|
||||
return main.SATFormaPago.actualizar(values)
|
||||
|
||||
def _get_usocfdiupdate(self, values):
|
||||
return main.SATUsoCfdi.actualizar(values)
|
||||
|
||||
def _get_emisorcuentasbanco(self, values):
|
||||
return main.CuentasBanco.emisor()
|
||||
|
||||
def _get_satkey(self, values):
|
||||
return main.get_sat_key(values['key'])
|
||||
|
||||
def _get_satmonedas(self, values):
|
||||
return main.get_sat_monedas(values['key'])
|
||||
|
||||
def _get_satunidades(self, values):
|
||||
return main.get_sat_unidades(values['key'])
|
||||
|
||||
def _get_satproductos(self, values):
|
||||
return main.get_sat_productos(values['key'])
|
||||
|
||||
def _get_series(self, values):
|
||||
return main.Folios.get_all()
|
||||
|
||||
def _get_monedas(self, values):
|
||||
return main.SATMonedas.get_activos()
|
||||
|
||||
def _get_monedasid(self, values):
|
||||
return main.SATMonedas.get_activos_by_id()
|
||||
|
||||
def _get_bancosid(self, values):
|
||||
return main.SATBancos.get_activos_by_id()
|
||||
|
||||
def _get_regimenes(self, values):
|
||||
return main.Emisor.get_regimenes()
|
||||
|
||||
def _get_usocfdi(self, values):
|
||||
return main.SATUsoCfdi.get_activos()
|
||||
|
||||
def _get_ebancomov(self, values):
|
||||
return main.MovimientosBanco.con(values['id'])
|
||||
|
||||
def delete(self, table, id):
|
||||
if table == 'partner':
|
||||
return main.Socios.remove(id)
|
||||
if table == 'product':
|
||||
return main.Productos.remove(id)
|
||||
if table == 'invoice':
|
||||
return main.Facturas.remove(id)
|
||||
if table == 'folios':
|
||||
return main.Folios.remove(id)
|
||||
if table == 'preinvoice':
|
||||
return main.PreFacturas.remove(id)
|
||||
if table == 'satimpuesto':
|
||||
return main.SATImpuestos.remove(id)
|
||||
if table == 'satunit':
|
||||
return main.SATUnidades.remove(id)
|
||||
if table == 'cuentasbanco':
|
||||
return main.CuentasBanco.remove(id)
|
||||
if table == 'movbanco':
|
||||
return main.MovimientosBanco.remove(id)
|
||||
if table == 'usuario':
|
||||
return main.Usuarios.remove(id)
|
||||
if table == 'config':
|
||||
return main.Configuracion.remove(id)
|
||||
<<<<<<< HEAD
|
||||
if table == 'nivedu':
|
||||
return main.NivelesEducativos.remove(id)
|
||||
if table == 'students':
|
||||
return main.Alumnos.remove(id)
|
||||
=======
|
||||
if table == 'employee':
|
||||
return main.Empleados.remove(id)
|
||||
if table == 'nomina':
|
||||
return main.CfdiNomina.remove(id)
|
||||
>>>>>>> nomina
|
||||
return False
|
||||
|
||||
def _get_client(self, values):
|
||||
return main.Socios.get_by_client(values)
|
||||
|
||||
def _get_student(self, values):
|
||||
return main.Alumnos.get_by_name(values)
|
||||
|
||||
def _get_product(self, values):
|
||||
return main.Productos.get_by(values)
|
||||
|
||||
def _get_productokey(self, values):
|
||||
return main.Productos.get_by_key(values)
|
||||
|
||||
def get_partners(self, values):
|
||||
return main.Socios.get_(values)
|
||||
|
||||
def partner(self, values):
|
||||
id = int(values.pop('id', '0'))
|
||||
if id:
|
||||
return main.Socios.actualizar(values, id)
|
||||
return main.Socios.add(values)
|
||||
|
||||
def get_products(self, values):
|
||||
return main.Productos.get_(values)
|
||||
|
||||
def products(self, values):
|
||||
id = int(values.pop('id', '0'))
|
||||
if id:
|
||||
return main.Productos.actualizar(values, id)
|
||||
|
||||
opt = values.get('opt', '')
|
||||
if opt:
|
||||
return main.Productos.opt(values)
|
||||
|
||||
return main.Productos.add(values)
|
||||
|
||||
def invoice(self, values, user):
|
||||
id = int(values.pop('id', '0'))
|
||||
if id:
|
||||
return main.Facturas.actualizar(values, id)
|
||||
|
||||
return main.Facturas.add(values, user)
|
||||
|
||||
def preinvoice(self, values):
|
||||
id = int(values.pop('id', '0'))
|
||||
#~ if id:
|
||||
#~ return main.PreFacturas.actualizar(values, id)
|
||||
return main.PreFacturas.add(values)
|
||||
|
||||
def get_students(self, values):
|
||||
return main.Alumnos.get_by(values)
|
||||
|
||||
def students(self, values):
|
||||
opt = values.pop('opt')
|
||||
if opt == 'add':
|
||||
return main.Alumnos.add(values['values'])
|
||||
if opt == 'edit':
|
||||
return main.Alumnos.actualizar(values['values'])
|
||||
|
||||
def tickets(self, values, user):
|
||||
opt = values.pop('opt')
|
||||
if opt == 'add':
|
||||
return main.Tickets.add(values, user)
|
||||
if opt == 'cancel':
|
||||
return main.Tickets.cancel(values)
|
||||
if opt == 'invoice':
|
||||
return main.Tickets.invoice(values, user)
|
||||
if opt == 'print':
|
||||
return main.Tickets.printer(values)
|
||||
|
||||
def get_tickets(self, values):
|
||||
return main.Tickets.get_by(values)
|
||||
|
||||
def get_invoices(self, values):
|
||||
return main.Facturas.get_(values)
|
||||
|
||||
def get_preinvoices(self, values):
|
||||
return main.PreFacturas.get_(values)
|
||||
|
||||
def _get_timbrar(self, values):
|
||||
return main.Facturas.timbrar(int(values['id']))
|
||||
|
||||
def _get_anticipoegreso(self, values):
|
||||
return main.Facturas.anticipo_egreso(int(values['id']))
|
||||
|
||||
def get_emisor(self, rfc):
|
||||
return main.Emisor.get_(rfc)
|
||||
|
||||
def emisor(self, values):
|
||||
return main.Emisor.add(values)
|
||||
|
||||
def cuentasbanco(self, values):
|
||||
return main.CuentasBanco.add(values)
|
||||
|
||||
def add_movbanco(self, values):
|
||||
return main.MovimientosBanco.add(values)
|
||||
|
||||
def get_cuentasbanco(self, values):
|
||||
return main.CuentasBanco.get_(values)
|
||||
|
||||
def get_folios(self):
|
||||
return main.Folios.get_()
|
||||
|
||||
def add_folios(self, values):
|
||||
return main.Folios.add(values)
|
||||
|
||||
def add_nivel_educativo(self, values):
|
||||
return main.NivelesEducativos.add(values)
|
||||
|
||||
def get_doc(self, type_doc, id, rfc):
|
||||
return main.get_doc(type_doc, id, rfc)
|
||||
|
||||
def get_movimientosbanco(self, values):
|
||||
return main.MovimientosBanco.get_(values)
|
||||
|
||||
def importar_bdfl(self):
|
||||
return main.importar_bdfl()
|
|
@ -1713,7 +1713,7 @@ class MovimientosBanco(BaseModel):
|
|||
.select()
|
||||
.where(
|
||||
(MovimientosBanco.cuenta==cuenta) &
|
||||
(MovimientosBanco.fecha<fecha) &
|
||||
(MovimientosBanco.fecha<=fecha) &
|
||||
(MovimientosBanco.cancelado==False))[-1]
|
||||
)
|
||||
return round(float(query.saldo), DECIMALES)
|
||||
|
@ -1850,6 +1850,7 @@ class MovimientosBanco(BaseModel):
|
|||
MovimientosBanco.deposito,
|
||||
MovimientosBanco.saldo)
|
||||
.where(filtros)
|
||||
.order_by(MovimientosBanco.id)
|
||||
.dicts()
|
||||
)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue