Sincronizar facturas
This commit is contained in:
parent
b973fecaf3
commit
858eafd6ab
|
@ -806,12 +806,19 @@ class SeaFileAPI(object):
|
|||
return False
|
||||
|
||||
upload_link = self._get_upload_link(repo_id)
|
||||
if isinstance(path_file, tuple):
|
||||
obj_file = path_file[0]
|
||||
filename = path_file[1]
|
||||
else:
|
||||
obj_file = self._open(path_file)
|
||||
_, filename = self._info_path(path_file)
|
||||
|
||||
data = {
|
||||
'filename': path_file,
|
||||
# ~ 'filename': filename,
|
||||
'parent_dir': relative_path,
|
||||
'relative_path': '',
|
||||
}
|
||||
files = {'file': self._open(path_file)}
|
||||
files = {'file': (filename, obj_file)}
|
||||
|
||||
resp = requests.post(
|
||||
upload_link, data=data, files=files, headers=self._headers)
|
||||
|
@ -892,9 +899,15 @@ class SeaFileAPI(object):
|
|||
return False
|
||||
|
||||
update_link = self._get_update_link(repo_id)
|
||||
_, filename = self._info_path(path_file)
|
||||
if isinstance(path_file, tuple):
|
||||
obj_file = path_file[0]
|
||||
filename = path_file[1]
|
||||
else:
|
||||
obj_file = self._open(path_file)
|
||||
_, filename = self._info_path(path_file)
|
||||
|
||||
files = {
|
||||
'file': (filename, self._open(path_file)),
|
||||
'file': (filename, obj_file),
|
||||
'filename': (None, filename),
|
||||
'target_file': (None, '{}{}'.format(target_file, filename))
|
||||
}
|
||||
|
|
|
@ -1470,6 +1470,19 @@ def backup_dbs():
|
|||
return
|
||||
|
||||
|
||||
def sync_cfdi(auth, files):
|
||||
if DEBUG:
|
||||
return
|
||||
|
||||
seafile = SeaFileAPI(SEAFILE_SERVER['URL'], auth['USER'], auth['PASS'])
|
||||
if seafile.is_connect:
|
||||
for f in files:
|
||||
seafile.update_file(
|
||||
f, auth['REPO'], 'Facturas/{}/'.format(f[2]), auth['PASS'])
|
||||
|
||||
return
|
||||
|
||||
|
||||
class ImportFacturaLibre(object):
|
||||
|
||||
def __init__(self, path, rfc):
|
||||
|
|
|
@ -458,6 +458,7 @@ class Emisor(BaseModel):
|
|||
'RFC': obj.rfc,
|
||||
'USER': obj.correo_timbrado,
|
||||
'PASS': obj.token_timbrado,
|
||||
'REPO': obj.token_soporte,
|
||||
}
|
||||
return data
|
||||
except:
|
||||
|
@ -2090,6 +2091,10 @@ class Facturas(BaseModel):
|
|||
def _send(self, id, rfc):
|
||||
return Facturas.send(id, rfc)
|
||||
|
||||
@util.run_in_thread
|
||||
def _sync(self, id, auth):
|
||||
return Facturas.sync(id, auth)
|
||||
|
||||
@util.run_in_thread
|
||||
def _actualizar_saldo_cliente(self, invoice):
|
||||
if invoice.tipo_comprobante == 'T':
|
||||
|
@ -2152,6 +2157,26 @@ class Facturas(BaseModel):
|
|||
msg = 'Factura enviada correctamente'
|
||||
return {'ok': True, 'msg': msg}
|
||||
|
||||
@classmethod
|
||||
def sync(cls, id, auth):
|
||||
if not auth['REPO']:
|
||||
return
|
||||
|
||||
obj = Facturas.get(Facturas.id==id)
|
||||
if obj.uuid is None:
|
||||
msg = 'La factura no esta timbrada'
|
||||
return
|
||||
|
||||
pdf, name_pdf = cls.get_pdf(id, auth['RFC'])
|
||||
name_xml = '{}{}_{}.xml'.format(obj.serie, obj.folio, obj.cliente.rfc)
|
||||
target = str(obj.fecha)[:7].replace('-', '/')
|
||||
files = (
|
||||
(obj.xml, name_xml, target),
|
||||
(pdf, name_pdf, target),
|
||||
)
|
||||
util.sync_cfdi(auth, files)
|
||||
return
|
||||
|
||||
def _get_filter_folios(self, values):
|
||||
if not 'folio' in values:
|
||||
return ''
|
||||
|
@ -2735,6 +2760,7 @@ class Facturas(BaseModel):
|
|||
if obj.tipo_comprobante == 'I' and obj.tipo_relacion == '07':
|
||||
anticipo = True
|
||||
cls._actualizar_saldo_cliente(cls, obj)
|
||||
cls._sync(cls, id, auth)
|
||||
else:
|
||||
msg = result['error']
|
||||
obj.estatus = 'Error'
|
||||
|
|
Loading…
Reference in New Issue