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):
|
||||
|
||||
def __init__(self, path):
|
||||
def __init__(self, path, rfc):
|
||||
self._rfc = rfc
|
||||
self._con = None
|
||||
self._cursor = None
|
||||
self._is_connect = self._connect(path)
|
||||
self._clientes = []
|
||||
self._clientes_rfc = []
|
||||
self._error = ''
|
||||
|
||||
@property
|
||||
def error(self):
|
||||
return self._error
|
||||
|
||||
@property
|
||||
def is_connect(self):
|
||||
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):
|
||||
try:
|
||||
self._con = sqlite3.connect(path)
|
||||
self._con.row_factory = sqlite3.Row
|
||||
self._cursor = self._con.cursor()
|
||||
return True
|
||||
return self._validate_rfc()
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
self._error = 'No se pudo conectar a la base de datos'
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
|
|
|
@ -14,6 +14,9 @@ class StorageEngine(object):
|
|||
def get_values(self, table, values=None):
|
||||
return getattr(self, '_get_{}'.format(table))(values)
|
||||
|
||||
def _get_validartimbrar(self, values):
|
||||
return main.validar_timbrar()
|
||||
|
||||
def _get_preproductos(self, values):
|
||||
return main.PreFacturasDetalle.facturar(values['id'])
|
||||
|
||||
|
|
|
@ -67,6 +67,40 @@ def upload_file(rfc, opt, file_obj):
|
|||
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):
|
||||
clave = TextField(unique=True)
|
||||
valor = TextField(default='')
|
||||
|
@ -288,7 +322,11 @@ class Emisor(BaseModel):
|
|||
|
||||
@classmethod
|
||||
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]
|
||||
return tuple(rows)
|
||||
|
||||
|
@ -2699,9 +2737,9 @@ def _importar_factura_libre(archivo):
|
|||
conectar(args)
|
||||
|
||||
log.info('Importando datos...')
|
||||
app = util.ImportFacturaLibre(archivo)
|
||||
app = util.ImportFacturaLibre(archivo, rfc)
|
||||
if not app.is_connect:
|
||||
log.error('\tNo se pudo conectar a la base de datos')
|
||||
log.error('\t{}'.format(app.error))
|
||||
return
|
||||
|
||||
data = app.import_data()
|
||||
|
|
|
@ -392,9 +392,9 @@ function cmd_subir_certificado_click(){
|
|||
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?'
|
||||
webix.confirm({
|
||||
title: 'Certificado Existente',
|
||||
|
|
|
@ -95,6 +95,19 @@ function default_config(){
|
|||
get_regimen_fiscal()
|
||||
table_pt.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