Merge branch 'develop'

Ejecutar LibreOffice como otra instancia
This commit is contained in:
Mauricio Baeza 2018-03-09 00:23:46 -06:00
commit 2f797af8b2
4 changed files with 77 additions and 15 deletions

View File

@ -607,6 +607,10 @@ class LIBO(object):
PORT = '8100'
ARG = 'socket,host={},port={};urp;StarOffice.ComponentContext'.format(
HOST, PORT)
CMD = ['soffice',
'-env:SingleAppInstance=false',
'-env:UserInstallation=file:///tmp/LIBO_Process8100',
'--headless', '--norestore', '--nologo', '--accept={}'.format(ARG)]
def __init__(self):
self._app = None
@ -647,15 +651,12 @@ class LIBO(object):
if self.is_running:
return
c = 1
while c < 4:
c += 1
self.app = subprocess.Popen([
'soffice', '--headless', '--accept={}'.format(self.ARG)],
for i in range(3):
self.app = subprocess.Popen(self.CMD,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(5)
if self.is_running:
return
break
return
def _set_properties(self, properties):
@ -1109,7 +1110,7 @@ class LIBO(object):
def pdf(self, path, data, ods=False):
options = {'AsTemplate': True, 'Hidden': True}
log.info('Abrir plantilla...')
log.debug('Abrir plantilla...')
self._template = self._doc_open(path, options)
if self._template is None:
return b''
@ -1844,6 +1845,10 @@ def send_mail(data):
return {'ok': is_connect, 'msg': msg}
def exists(path):
return os.path.exists(path)
def get_path_info(path):
path, filename = os.path.split(path)
name, extension = os.path.splitext(filename)

View File

@ -372,7 +372,7 @@ class StorageEngine(object):
return main.PreFacturas.get_(values)
def _get_timbrar(self, values):
return main.Facturas.timbrar(int(values['id']))
return main.Facturas.timbrar(values)
def _get_anticipoegreso(self, values):
return main.Facturas.anticipo_egreso(int(values['id']))

View File

@ -24,6 +24,7 @@ from settings import log, DEBUG, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI,
FORMAT = '{0:.2f}'
FORMAT3 = '{0:.3f}'
FORMAT_TAX = '{0:.4f}'
RFC_PUBLICO = 'XAXX010101000'
database_proxy = Proxy()
@ -3090,6 +3091,7 @@ class Productos(BaseModel):
'descripcion': obj.descripcion,
'unidad': obj.unidad.name,
'valor_unitario': obj.valor_unitario,
'existencia': obj.existencia,
}
data = {'ok': True, 'row': row, 'new': False}
return data
@ -3210,6 +3212,7 @@ class Facturas(BaseModel):
obj.fecha_cancelacion = result['Fecha']
obj.acuse = result['Acuse']
self._actualizar_saldo_cliente(self, obj, True)
self._update_inventory(self, obj, True)
else:
obj.error = data['msg']
obj.save()
@ -3399,6 +3402,9 @@ class Facturas(BaseModel):
if invoice.donativo and invoice.forma_pago == '12':
return
if invoice.cliente.rfc == RFC_PUBLICO:
return
importe = invoice.total_mn
if invoice.tipo_comprobante == 'E':
importe *= -1
@ -3645,6 +3651,7 @@ class Facturas(BaseModel):
q.execute()
q = FacturasRelacionadas.delete().where(FacturasRelacionadas.factura==obj)
q.execute()
Tickets.uncancel(obj)
return bool(obj.delete_instance())
def _get_folio(self, serie):
@ -4156,8 +4163,26 @@ class Facturas(BaseModel):
}
return
@util.run_in_thread
def _update_inventory(self, invoice, cancel=False):
if invoice.tipo_comprobante != 'I':
return
products = FacturasDetalle.get_by_invoice(invoice.id)
for p in products:
if p.producto.inventario:
if cancel:
p.producto.existencia += Decimal(p.cantidad)
else:
p.producto.existencia -= Decimal(p.cantidad)
p.producto.save()
return
@classmethod
def timbrar(cls, id):
def timbrar(cls, values):
id = int(values['id'])
update = util.loads(values.get('update', 'true'))
auth = Emisor.get_auth()
obj = Facturas.get(Facturas.id == id)
obj.xml = cls._make_xml(cls, obj, auth)
@ -4169,7 +4194,6 @@ class Facturas(BaseModel):
anticipo = False
msg = 'Factura timbrada correctamente'
result = util.timbra_xml(obj.xml, auth)
# ~ print (result)
if result['ok']:
obj.xml = result['xml']
obj.uuid = result['uuid']
@ -4183,6 +4207,8 @@ class Facturas(BaseModel):
if obj.tipo_comprobante == 'I' and obj.tipo_relacion == '07':
anticipo = True
cls._actualizar_saldo_cliente(cls, obj)
if update:
cls._update_inventory(cls, obj)
cls._sync(cls, id, auth)
else:
msg = result['error']
@ -4231,7 +4257,7 @@ class Facturas(BaseModel):
tipo_persona = 1
if receptor['rfc'] == 'XEXX010101000':
tipo_persona = 4
elif receptor['rfc'] == 'XAXX010101000':
elif receptor['rfc'] == RFC_PUBLICO:
tipo_persona = 3
elif len(receptor['rfc']) == 12:
tipo_persona = 2
@ -4859,6 +4885,10 @@ class FacturasDetalle(BaseModel):
.where(model_pt.productos_id==id).dicts())
return impuestos
@classmethod
def get_by_invoice(cls, id):
return FacturasDetalle.select().where(FacturasDetalle.factura==id)
@classmethod
def reinvoice(cls, id):
data = []
@ -5328,6 +5358,15 @@ class Tickets(BaseModel):
return inicio
@classmethod
def uncancel(cls, invoice):
query = (Tickets
.update(estatus='Generado', cancelado=False, factura=None)
.where(Tickets.factura==invoice)
)
result = query.execute()
return result
def _cancel_tickets(self, invoice, tickets):
query = (Tickets
.update(estatus='Facturado', cancelado=True, factura=invoice)
@ -5428,7 +5467,7 @@ class Tickets(BaseModel):
if is_invoice_day:
filters = (
Socios.rfc == 'XAXX010101000' and
Socios.rfc == RFC_PUBLICO and
Socios.slug == 'publico_en_general')
try:
client = Socios.get(filters)
@ -7141,7 +7180,7 @@ def _init_values(rfc):
data = (
{'clave': 'version', 'valor': VERSION},
{'clave': 'migracion', 'valor': '0'},
{'clave': 'rfc_publico', 'valor': 'XAXX010101000'},
{'clave': 'rfc_publico', 'valor': RFC_PUBLICO},
{'clave': 'rfc_extranjero', 'valor': 'XEXX010101000'},
{'clave': 'decimales', 'valor': '2'},
{'clave': 'path_key', 'valor': ''},
@ -8089,8 +8128,16 @@ def _exportar_documentos():
msg = 'Extrayendo factura {} de {}: {}-{}'.format(
i+1, t, row['serie'], row['folio'])
log.info(msg)
Facturas.get_xml(row['id'])
_, name = Facturas.get_xml(row['id'])
msg = '\tXML extraido...'
log.info(msg)
# ~ name = name[:-3] + 'pdf'
# ~ path = '/home/mau/facturas/{}/{}/{}/{}'.format(rfc, year, month, name)
# ~ if util.exists(path):
# ~ continue
Facturas.get_pdf(row['id'], rfc, True)
msg = '\tPDF generado...'
log.info(msg)
log.info('Documentos exportados...')
return

View File

@ -495,6 +495,16 @@ function cmd_cancelar_ticket_click(){
return
}
if(row['estatus']=='Cancelado'){
msg_error('El ticket ya esta cancelado')
return
}
if(row['estatus']=='Facturado'){
msg_error('El ticket esta facturado')
return
}
msg = '¿Estás seguro de cancelar el siguiente Ticket?<BR><BR>'
msg += 'Folio: ' + row['folio']
msg += '<BR><BR>ESTA ACCIÓN NO SE PUEDE DESHACER'
@ -521,7 +531,7 @@ function chk_is_invoice_day_change(new_value, old_value){
function send_timbrar_invoice(id){
webix.ajax().get('/values/timbrar', {id: id}, function(text, data){
webix.ajax().get('/values/timbrar', {id: id, update: false}, function(text, data){
var values = data.json()
if(values.ok){
msg_ok(values.msg)