forked from elmau/empresa-libre
Validar configuracion mínima para facturar
This commit is contained in:
parent
b997a4703c
commit
f1dff39e1b
|
@ -1192,25 +1192,46 @@ def get_bool(value):
|
||||||
|
|
||||||
class ImportFacturaLibre(object):
|
class ImportFacturaLibre(object):
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path, rfc):
|
||||||
|
self._rfc = rfc
|
||||||
self._con = None
|
self._con = None
|
||||||
self._cursor = None
|
self._cursor = None
|
||||||
self._is_connect = self._connect(path)
|
self._is_connect = self._connect(path)
|
||||||
self._clientes = []
|
self._clientes = []
|
||||||
self._clientes_rfc = []
|
self._clientes_rfc = []
|
||||||
|
self._error = ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def error(self):
|
||||||
|
return self._error
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connect(self):
|
def is_connect(self):
|
||||||
return self._is_connect
|
return self._is_connect
|
||||||
|
|
||||||
|
def _validate_rfc(self):
|
||||||
|
sql = "SELECT rfc FROM emisor LIMIT 1"
|
||||||
|
self._cursor.execute(sql)
|
||||||
|
obj = self._cursor.fetchone()
|
||||||
|
if obj is None:
|
||||||
|
self._error = 'No se encontró al emisor: {}'.format(self._rfc)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if obj['rfc'] != self._rfc:
|
||||||
|
self._error = 'Los datos no corresponden al emisor: {}'.format(self._rfc)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _connect(self, path):
|
def _connect(self, path):
|
||||||
try:
|
try:
|
||||||
self._con = sqlite3.connect(path)
|
self._con = sqlite3.connect(path)
|
||||||
self._con.row_factory = sqlite3.Row
|
self._con.row_factory = sqlite3.Row
|
||||||
self._cursor = self._con.cursor()
|
self._cursor = self._con.cursor()
|
||||||
return True
|
return self._validate_rfc()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(e)
|
log.error(e)
|
||||||
|
self._error = 'No se pudo conectar a la base de datos'
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -14,6 +14,9 @@ class StorageEngine(object):
|
||||||
def get_values(self, table, values=None):
|
def get_values(self, table, values=None):
|
||||||
return getattr(self, '_get_{}'.format(table))(values)
|
return getattr(self, '_get_{}'.format(table))(values)
|
||||||
|
|
||||||
|
def _get_validartimbrar(self, values):
|
||||||
|
return main.validar_timbrar()
|
||||||
|
|
||||||
def _get_preproductos(self, values):
|
def _get_preproductos(self, values):
|
||||||
return main.PreFacturasDetalle.facturar(values['id'])
|
return main.PreFacturasDetalle.facturar(values['id'])
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,40 @@ def upload_file(rfc, opt, file_obj):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def validar_timbrar():
|
||||||
|
try:
|
||||||
|
obj = Emisor.select()[0]
|
||||||
|
except IndexError:
|
||||||
|
msg = 'Es necesario agregar los datos del emisor'
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = Folios.select()[0]
|
||||||
|
except IndexError:
|
||||||
|
msg = 'Es necesaria al menos una serie de folios'
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
msg = 'Es necesario configurar un certificado de sellos'
|
||||||
|
try:
|
||||||
|
obj = Certificado.select()[0]
|
||||||
|
except IndexError:
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
if not obj.serie:
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
dias = obj.hasta - util.now()
|
||||||
|
if dias.days < 0:
|
||||||
|
msg = 'El certificado ha vencido, es necesario cargar uno nuevo'
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
msg = ''
|
||||||
|
if dias.days < 15:
|
||||||
|
msg = 'El certificado vence en: {} días.'.format(dias.days)
|
||||||
|
|
||||||
|
return {'ok': True, 'msg': msg}
|
||||||
|
|
||||||
|
|
||||||
class Configuracion(BaseModel):
|
class Configuracion(BaseModel):
|
||||||
clave = TextField(unique=True)
|
clave = TextField(unique=True)
|
||||||
valor = TextField(default='')
|
valor = TextField(default='')
|
||||||
|
@ -288,7 +322,11 @@ class Emisor(BaseModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_regimenes(cls):
|
def get_regimenes(cls):
|
||||||
obj = Emisor.select()[0]
|
try:
|
||||||
|
obj = Emisor.select()[0]
|
||||||
|
except IndexError:
|
||||||
|
return ()
|
||||||
|
|
||||||
rows = [{'id': row.key, 'value': row.name} for row in obj.regimenes]
|
rows = [{'id': row.key, 'value': row.name} for row in obj.regimenes]
|
||||||
return tuple(rows)
|
return tuple(rows)
|
||||||
|
|
||||||
|
@ -2699,9 +2737,9 @@ def _importar_factura_libre(archivo):
|
||||||
conectar(args)
|
conectar(args)
|
||||||
|
|
||||||
log.info('Importando datos...')
|
log.info('Importando datos...')
|
||||||
app = util.ImportFacturaLibre(archivo)
|
app = util.ImportFacturaLibre(archivo, rfc)
|
||||||
if not app.is_connect:
|
if not app.is_connect:
|
||||||
log.error('\tNo se pudo conectar a la base de datos')
|
log.error('\t{}'.format(app.error))
|
||||||
return
|
return
|
||||||
|
|
||||||
data = app.import_data()
|
data = app.import_data()
|
||||||
|
|
|
@ -392,9 +392,9 @@ function cmd_subir_certificado_click(){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var rfc = $$('form_cert').getValues()['cert_rfc']
|
var serie = $$('form_cert').getValues()['cert_serie']
|
||||||
|
|
||||||
if(rfc){
|
if(serie){
|
||||||
msg = 'Ya existe un certificado guardado<BR><BR>¿Deseas reemplazarlo?'
|
msg = 'Ya existe un certificado guardado<BR><BR>¿Deseas reemplazarlo?'
|
||||||
webix.confirm({
|
webix.confirm({
|
||||||
title: 'Certificado Existente',
|
title: 'Certificado Existente',
|
||||||
|
|
|
@ -95,6 +95,19 @@ function default_config(){
|
||||||
get_regimen_fiscal()
|
get_regimen_fiscal()
|
||||||
table_pt.clear()
|
table_pt.clear()
|
||||||
table_totals.clear()
|
table_totals.clear()
|
||||||
|
|
||||||
|
webix.ajax().sync().get('/values/validartimbrar', function(text, data){
|
||||||
|
var values = data.json()
|
||||||
|
if(!values.ok){
|
||||||
|
msg_error(values.msg)
|
||||||
|
$$('cmd_timbrar').disable()
|
||||||
|
}else{
|
||||||
|
if(values.msg){
|
||||||
|
msg_error(values.msg)
|
||||||
|
}
|
||||||
|
$$('cmd_timbrar').enable()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue