diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py
index 9d0bfb9..7e16b57 100644
--- a/source/app/controllers/util.py
+++ b/source/app/controllers/util.py
@@ -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):
diff --git a/source/app/models/db.py b/source/app/models/db.py
index c53fdfc..b7db743 100644
--- a/source/app/models/db.py
+++ b/source/app/models/db.py
@@ -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'])
diff --git a/source/app/models/main.py b/source/app/models/main.py
index c0825e8..c37721a 100644
--- a/source/app/models/main.py
+++ b/source/app/models/main.py
@@ -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()
diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js
index 130e675..a89afa3 100644
--- a/source/static/js/controller/admin.js
+++ b/source/static/js/controller/admin.js
@@ -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
¿Deseas reemplazarlo?'
webix.confirm({
title: 'Certificado Existente',
diff --git a/source/static/js/controller/invoices.js b/source/static/js/controller/invoices.js
index 9bf0193..f486f06 100644
--- a/source/static/js/controller/invoices.js
+++ b/source/static/js/controller/invoices.js
@@ -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()
+ }
+ })
}