forked from elmau/empresa-libre
Fix #251
This commit is contained in:
parent
3dd73c1467
commit
dd0585853a
|
@ -2509,6 +2509,26 @@ def local_copy(files):
|
||||||
return
|
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):
|
def sync_cfdi(auth, files):
|
||||||
local_copy(files)
|
local_copy(files)
|
||||||
|
|
||||||
|
|
|
@ -5508,6 +5508,8 @@ class CfdiPagos(BaseModel):
|
||||||
'id': obj.id,
|
'id': obj.id,
|
||||||
'row': row,
|
'row': row,
|
||||||
}
|
}
|
||||||
|
if result['ok']:
|
||||||
|
self._sync(self, obj.id)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_related(self, values):
|
def _get_related(self, values):
|
||||||
|
@ -5533,6 +5535,14 @@ class CfdiPagos(BaseModel):
|
||||||
obj = CfdiPagos.get(CfdiPagos.id==id)
|
obj = CfdiPagos.get(CfdiPagos.id==id)
|
||||||
folio = str(obj.folio).zfill(6)
|
folio = str(obj.folio).zfill(6)
|
||||||
name = '{}{}_{}.xml'.format(obj.serie, folio, obj.socio.rfc)
|
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
|
return obj.xml, name
|
||||||
|
|
||||||
def _get_not_in_xml(self, invoice, emisor):
|
def _get_not_in_xml(self, invoice, emisor):
|
||||||
|
@ -5575,14 +5585,31 @@ class CfdiPagos(BaseModel):
|
||||||
if obj.uuid is None:
|
if obj.uuid is None:
|
||||||
return b'', name
|
return b'', name
|
||||||
|
|
||||||
|
target = emisor.rfc + '/' + str(obj.fecha)[:7].replace('-', '/')
|
||||||
values = cls._get_not_in_xml(cls, obj, emisor)
|
values = cls._get_not_in_xml(cls, obj, emisor)
|
||||||
data = util.get_data_from_xml(obj, values)
|
data = util.get_data_from_xml(obj, values)
|
||||||
obj = SATFormaPago.get(SATFormaPago.key==data['pays']['FormaDePagoP'])
|
obj = SATFormaPago.get(SATFormaPago.key==data['pays']['FormaDePagoP'])
|
||||||
data['pays']['formadepago'] = '{} ({})'.format(obj.name, obj.key)
|
data['pays']['formadepago'] = '{} ({})'.format(obj.name, obj.key)
|
||||||
doc = util.to_pdf(data, emisor.rfc)
|
doc = util.to_pdf(data, emisor.rfc)
|
||||||
|
|
||||||
|
files = (
|
||||||
|
(doc, name, target),
|
||||||
|
)
|
||||||
|
cls._sync_files(cls, files)
|
||||||
|
|
||||||
return doc, name
|
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
|
@classmethod
|
||||||
def get_values(cls, values):
|
def get_values(cls, values):
|
||||||
opt = values.pop('opt')
|
opt = values.pop('opt')
|
||||||
|
|
Loading…
Reference in New Issue