diff --git a/source/app/conf.py.example b/source/app/conf.py.example index 1f8e28d..70d42ef 100644 --- a/source/app/conf.py.example +++ b/source/app/conf.py.example @@ -1,10 +1,4 @@ #!/usr/bin/env python -from peewee import SqliteDatabase DEBUG = True -ID_SUPPORT = '' - -DATABASE = None -if DEBUG: - DATABASE = SqliteDatabase('empresalibre.sqlite') diff --git a/source/app/controllers/pac.py b/source/app/controllers/pac.py index 25b7fa4..d123861 100644 --- a/source/app/controllers/pac.py +++ b/source/app/controllers/pac.py @@ -443,21 +443,41 @@ class Finkok(object): return result def add_token(self, rfc, email): - """ + """Agrega un nuevo token al cliente para timbrado. Se requiere cuenta de reseller para usar este método + + Args: + rfc (str): El RFC del cliente, ya debe existir + email (str): El correo del cliente, funciona como USER al timbrar + + Returns: + dict + 'username': 'username', + 'status': True or False + 'name': 'name', + 'success': True or False + 'token': 'Token de timbrado', + 'message': None """ + auth = AUTH['RESELLER'] + method = 'util' client = Client( URL[method], transport=self._transport, plugins=self._plugins) args = { - 'username': AUTH['USER'], - 'password': AUTH['PASS'], + 'username': auth['USER'], + 'password': auth['PASS'], 'name': rfc, 'token_username': email, 'taxpayer_id': rfc, 'status': True, } - result = client.service.add_token(**args) + try: + result = client.service.add_token(**args) + except Fault as e: + self.error = str(e) + return '' + return result def get_date(self): @@ -477,17 +497,31 @@ class Finkok(object): return result.datetime def add_client(self, rfc, type_user=False): - """ + """Agrega un nuevo cliente para timbrado. Se requiere cuenta de reseller para usar este método - type_user: False == 'P' == Prepago or True == 'O' == On demand + + Args: + rfc (str): El RFC del nuevo cliente + + Kwargs: + type_user (bool): False == 'P' == Prepago or True == 'O' == On demand + + Returns: + dict + 'message': + 'Account Created successfully' + 'Account Already exists' + 'success': True or False """ + auth = AUTH['RESELLER'] + tu = {False: 'P', True: 'O'} method = 'client' client = Client( URL[method], transport=self._transport, plugins=self._plugins) args = { - 'reseller_username': AUTH['USER'], - 'reseller_password': AUTH['PASS'], + 'reseller_username': auth['USER'], + 'reseller_password': auth['PASS'], 'taxpayer_id': rfc, 'type_user': tu[type_user], 'added': datetime.datetime.now().isoformat()[:19], @@ -505,13 +539,15 @@ class Finkok(object): Se requiere cuenta de reseller para usar este método status = 'A' or 'S' """ + auth = AUTH['RESELLER'] + sv = {False: 'S', True: 'A'} method = 'client' client = Client( URL[method], transport=self._transport, plugins=self._plugins) args = { - 'reseller_username': AUTH['USER'], - 'reseller_password': AUTH['PASS'], + 'reseller_username': auth['USER'], + 'reseller_password': auth['PASS'], 'taxpayer_id': rfc, 'status': sv[status], } @@ -524,15 +560,35 @@ class Finkok(object): return result def get_client(self, rfc): - """ + """Regresa el estatus del cliente + . Se requiere cuenta de reseller para usar este método + + Args: + rfc (str): El RFC del emisor + + Returns: + dict + 'message': None, + 'users': { + 'ResellerUser': [ + { + 'status': 'A', + 'counter': 0, + 'taxpayer_id': '', + 'credit': 0 + } + ] + } or None si no existe """ + auth = AUTH['RESELLER'] + method = 'client' client = Client( URL[method], transport=self._transport, plugins=self._plugins) args = { - 'reseller_username': AUTH['USER'], - 'reseller_password': AUTH['PASS'], + 'reseller_username': auth['USER'], + 'reseller_password': auth['PASS'], 'taxpayer_id': rfc, } @@ -548,15 +604,30 @@ class Finkok(object): return result def assign_client(self, rfc, credit): - """ + """Agregar credito a un emisor + Se requiere cuenta de reseller para usar este método + + Args: + rfc (str): El RFC del emisor, debe existir + credit (int): Cantidad de folios a agregar + + Returns: + dict + 'success': True or False, + 'credit': nuevo credito despues de agregar or None + 'message': + 'Success, added {credit} of credit to {RFC}' + 'RFC no encontrado' """ + auth = AUTH['RESELLER'] + method = 'client' client = Client( URL[method], transport=self._transport, plugins=self._plugins) args = { - 'username': AUTH['USER'], - 'password': AUTH['PASS'], + 'username': auth['USER'], + 'password': auth['PASS'], 'taxpayer_id': rfc, 'credit': credit, } diff --git a/source/app/models/main.py b/source/app/models/main.py index bc4ae98..cb6e36c 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -818,7 +818,11 @@ class Productos(BaseModel): @classmethod def next_key(cls): - value = Productos.select(fn.Max(Productos.id)).scalar() + value = (Productos + .select(fn.Max(Productos.id)) + .group_by(Productos.id) + .order_by(Productos.id) + .scalar()) if value is None: value = 1 else: @@ -1198,6 +1202,8 @@ class Facturas(BaseModel): inicio = (Facturas .select(fn.Max(Facturas.folio)) .where(Facturas.serie==serie) + .group_by(Facturas.folio) + .order_by(Facturas.folio) .scalar()) if inicio is None: inicio = inicio_serie