Sincronizar XML localmente

This commit is contained in:
Mauricio Baeza 2017-12-17 22:55:32 -06:00
parent 493f78fda5
commit 9e150a103e
3 changed files with 24 additions and 7 deletions

View File

@ -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:

View File

@ -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':

View File

@ -115,3 +115,4 @@ IMPUESTOS = {
'CEDULAR': '000',
}
DEFAULT_SAT_PRODUCTO = '01010101'
DIR_FACTURAS = 'facturas'