This commit is contained in:
Mauricio Baeza 2018-09-05 23:47:55 -05:00
parent 3dd73c1467
commit dd0585853a
2 changed files with 47 additions and 0 deletions

View File

@ -2509,6 +2509,26 @@ def local_copy(files):
return
def sync_files(files, auth={}):
if not MV:
return
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
for obj, name, target in files:
path = _validar_directorios(path_bk, target)
path_file = _join(path, name)
m = 'wb'
if name.endswith('xml'):
m = 'w'
save_file(path_file, obj, m)
return
def sync_cfdi(auth, files):
local_copy(files)

View File

@ -5508,6 +5508,8 @@ class CfdiPagos(BaseModel):
'id': obj.id,
'row': row,
}
if result['ok']:
self._sync(self, obj.id)
return result
def _get_related(self, values):
@ -5533,6 +5535,14 @@ class CfdiPagos(BaseModel):
obj = CfdiPagos.get(CfdiPagos.id==id)
folio = str(obj.folio).zfill(6)
name = '{}{}_{}.xml'.format(obj.serie, folio, obj.socio.rfc)
emisor = Emisor.select()[0]
target = emisor.rfc + '/' + str(obj.fecha)[:7].replace('-', '/')
files = (
(obj.xml, name, target),
)
cls._sync_files(cls, files)
return obj.xml, name
def _get_not_in_xml(self, invoice, emisor):
@ -5575,14 +5585,31 @@ class CfdiPagos(BaseModel):
if obj.uuid is None:
return b'', name
target = emisor.rfc + '/' + str(obj.fecha)[:7].replace('-', '/')
values = cls._get_not_in_xml(cls, obj, emisor)
data = util.get_data_from_xml(obj, values)
obj = SATFormaPago.get(SATFormaPago.key==data['pays']['FormaDePagoP'])
data['pays']['formadepago'] = '{} ({})'.format(obj.name, obj.key)
doc = util.to_pdf(data, emisor.rfc)
files = (
(doc, name, target),
)
cls._sync_files(cls, files)
return doc, name
@util.run_in_thread
def _sync(self, id):
CfdiPagos.get_file_xml(id)
CfdiPagos.get_file_pdf(id)
return
@util.run_in_thread
def _sync_files(self, files):
util.sync_files(files)
return
@classmethod
def get_values(cls, values):
opt = values.pop('opt')