Refacturar facturas grandes

This commit is contained in:
Mauricio Baeza 2018-02-24 17:34:55 -06:00
parent 7bc4f4631d
commit 853a29de84
2 changed files with 52 additions and 6 deletions

View File

@ -940,7 +940,7 @@ class Folios(BaseModel):
obj = Folios.get(Folios.serie==serie)
return obj.id
except:
return 0
return Folios.select()[0].id
@classmethod
def get_all(cls):
@ -3547,7 +3547,9 @@ class Facturas(BaseModel):
'condicion_pago': obj.condiciones_pago,
}
data = {'receptor': receptor, 'invoice': invoice}
products = FacturasDetalle.reinvoice(id)
data = {'receptor': receptor, 'invoice': invoice, 'products': products}
return data
def _get_opt(self, values):
@ -4846,6 +4848,34 @@ class FacturasDetalle(BaseModel):
class Meta:
order_by = ('factura',)
def _get_impuestos(self, id):
model_pt = Productos.impuestos.get_through_model()
impuestos = tuple(model_pt
.select(
model_pt.productos_id.alias('product'),
model_pt.satimpuestos_id.alias('tax'))
.where(model_pt.productos_id==id).dicts())
return impuestos
@classmethod
def reinvoice(cls, id):
data = []
products = FacturasDetalle.select().where(FacturasDetalle.factura==id)
for p in reversed(products):
row = {'delete': '-', 'id_product': p.producto.id}
row['clave'] = p.clave
row['clave_sat'] = p.clave_sat
row['descripcion'] = p.descripcion
row['unidad'] = p.producto.unidad.id
row['cantidad'] = p.cantidad
row['valor_unitario'] = p.valor_unitario
row['descuento'] = p.descuento
pf = p.valor_unitario - p.descuento
row['importe'] = round(pf * p.cantidad, DECIMALES)
impuestos = cls._get_impuestos(cls, row['id_product'])
data.append({'row': row, 'taxes': impuestos})
return data
class PreFacturasDetalle(BaseModel):
factura = ForeignKeyField(PreFacturas)

View File

@ -1139,6 +1139,25 @@ function set_invoice(row){
$$('txt_condicion_pago').setValue(row.condicion_pago)
}
function set_products_reinvoice(values){
var rows = []
for(var product of values){
var row = product.row
rows.push(row)
var taxes = product.taxes
for(var v of taxes){
var pt = table_pt.findOne(v)
if(pt === null){
table_pt.insert(v)
}
}
}
grid.parse(rows, 'json')
}
function refacturar_invoice(id){
filters = {id: id, opt: 'reinvoice'}
@ -1152,12 +1171,10 @@ function refacturar_invoice(id){
pause(500)
set_client(values.receptor)
set_invoice(values.invoice)
set_products_reinvoice(values.products)
calcular_impuestos()
}
})
//~ for(var p of values.rows){
//~ agregar_preproducto(p)
//~ }
}
@ -1890,7 +1907,6 @@ function lst_serie_change(nv, ov){
$$('lst_tipo_comprobante').setValue(query.usarcon)
$$('lst_tipo_comprobante').config.readonly = true
}else{
//~ $$('lst_tipo_comprobante').setValue('I')
$$('lst_tipo_comprobante').config.readonly = false
}
$$('lst_tipo_comprobante').refresh()