forked from elmau/empresa-libre
Copia local en carpeta compartida
This commit is contained in:
parent
980bb710ce
commit
3a88d82957
|
@ -19,6 +19,7 @@ import uuid
|
|||
import zipfile
|
||||
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from smtplib import SMTPException, SMTPAuthenticationError
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
@ -35,7 +36,7 @@ from dateutil import parser
|
|||
|
||||
from .helper import CaseInsensitiveDict, NumLet, SendMail, TemplateInvoice, \
|
||||
SeaFileAPI
|
||||
from settings import DEBUG, log, template_lookup, COMPANIES, DB_SAT, \
|
||||
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
|
||||
|
||||
|
@ -1459,16 +1460,63 @@ def backup_dbs():
|
|||
return
|
||||
|
||||
|
||||
def _validar_directorios(path_bk, target):
|
||||
path = Path(_join(path_bk, target))
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return str(path)
|
||||
|
||||
|
||||
def local_copy(files):
|
||||
if not MV:
|
||||
return
|
||||
|
||||
path_bk = _join(str(Path.home()), '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'
|
||||
try:
|
||||
result = _call(args)
|
||||
if result != 'empresalibre':
|
||||
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
|
||||
|
||||
try:
|
||||
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)
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def sync_cfdi(auth, files):
|
||||
local_copy(files)
|
||||
|
||||
if DEBUG:
|
||||
return
|
||||
|
||||
if not auth['REPO']:
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -2163,17 +2163,15 @@ class Facturas(BaseModel):
|
|||
|
||||
@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
|
||||
|
||||
emisor = Emisor.select()[0]
|
||||
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('-', '/')
|
||||
target = emisor.rfc + '/' + str(obj.fecha)[:7].replace('-', '/')
|
||||
files = (
|
||||
(obj.xml, name_xml, target),
|
||||
(pdf, name_pdf, target),
|
||||
|
|
Loading…
Reference in New Issue