diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 2cd43a5..2440e98 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -39,7 +39,7 @@ from .helper import CaseInsensitiveDict, NumLet, SendMail, TemplateInvoice, \ SeaFileAPI from settings import DEBUG, MV, log, template_lookup, COMPANIES, DB_SAT, \ PATH_XSLT, PATH_XSLTPROC, PATH_OPENSSL, PATH_TEMPLATES, PATH_MEDIA, PRE, \ - PATH_XMLSEC, TEMPLATE_CANCEL, DEFAULT_SAT_PRODUCTO, DECIMALES + PATH_XMLSEC, TEMPLATE_CANCEL, DEFAULT_SAT_PRODUCTO, DECIMALES, DIR_FACTURAS from settings import SEAFILE_SERVER @@ -1472,24 +1472,27 @@ def local_copy(files): if not MV: return - path_bk = _join(str(Path.home()), 'facturas') + path_bk = _join(str(Path.home()), DIR_FACTURAS) if not os.path.isdir(path_bk): msg = 'No existe la carpeta: facturas' log.error(msg) return - args = 'df -P ~/facturas | tail -1 | cut -d" " -f 1' + args = 'df -P {} | tail -1 | cut -d" " -f 1'.format(path_bk) try: result = _call(args) + log.info(result) + except: + pass # ~ if result != 'empresalibre\n': # ~ log.info(result) # ~ msg = 'Asegurate de que exista la carpeta para sincronizar' # ~ log.error(msg) # ~ return - except subprocess.CalledProcessError: - msg = 'No se pudo obtener la ruta para sincronizar' - log.error(msg) - return + # ~ except subprocess.CalledProcessError: + # ~ msg = 'No se pudo obtener la ruta para sincronizar' + # ~ log.error(msg) + # ~ return try: for obj, name, target in files: diff --git a/source/app/models/main.py b/source/app/models/main.py index 1fe885d..5be38d9 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -1967,6 +1967,7 @@ class Facturas(BaseModel): def get_xml(cls, id): obj = Facturas.get(Facturas.id==id) name = '{}{}_{}.xml'.format(obj.serie, obj.folio, obj.cliente.rfc) + cls._sync_xml(cls, obj) return obj.xml, name #~ Revisar @@ -2113,6 +2114,18 @@ class Facturas(BaseModel): util.sync_cfdi(auth, files) return + @util.run_in_thread + def _sync_xml(self, obj): + emisor = Emisor.select()[0] + auth = Emisor.get_auth() + name_xml = '{}{}_{}.xml'.format(obj.serie, obj.folio, obj.cliente.rfc) + target = emisor.rfc + '/' + str(obj.fecha)[:7].replace('-', '/') + files = ( + (obj.xml, name_xml, target), + ) + util.sync_cfdi(auth, files) + return + @util.run_in_thread def _actualizar_saldo_cliente(self, invoice): if invoice.tipo_comprobante == 'T': diff --git a/source/app/settings.py b/source/app/settings.py index db494d8..bc3bc44 100644 --- a/source/app/settings.py +++ b/source/app/settings.py @@ -115,3 +115,4 @@ IMPUESTOS = { 'CEDULAR': '000', } DEFAULT_SAT_PRODUCTO = '01010101' +DIR_FACTURAS = 'facturas' \ No newline at end of file