Fix - Issue #157

This commit is contained in:
Mauricio Baeza 2018-03-07 23:24:35 -06:00
parent facba9b629
commit 3e3c4be720
4 changed files with 43 additions and 6 deletions

View File

@ -1109,7 +1109,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 +1844,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

@ -3090,6 +3090,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 +3211,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()
@ -4156,8 +4158,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 +4189,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 +4202,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']
@ -4859,6 +4880,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 = []
@ -8089,8 +8114,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

@ -521,7 +521,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)