forked from elmau/empresa-libre
Facturar prefacturas
This commit is contained in:
parent
ceb11a367a
commit
7a63530ef6
|
@ -14,6 +14,9 @@ class StorageEngine(object):
|
|||
def get_values(self, table, values=None):
|
||||
return getattr(self, '_get_{}'.format(table))(values)
|
||||
|
||||
def _get_preproductos(self, values):
|
||||
return main.PreFacturasDetalle.facturar(values['id'])
|
||||
|
||||
def upload_file(self, session, table, file_obj):
|
||||
if not 'rfc' in session:
|
||||
return {'status': 'error'}
|
||||
|
|
|
@ -2029,6 +2029,44 @@ class PreFacturasDetalle(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 facturar(cls, id):
|
||||
data = []
|
||||
|
||||
q = PreFacturas.select(PreFacturas.cliente).where(PreFacturas.id==id)[0]
|
||||
receptor = {
|
||||
'id': q.cliente.id,
|
||||
'nombre': q.cliente.nombre,
|
||||
'rfc': q.cliente.rfc,
|
||||
'forma_pago': q.cliente.forma_pago.key,
|
||||
'uso_cfdi': q.cliente.uso_cfdi.key,
|
||||
}
|
||||
|
||||
productos = PreFacturasDetalle.select().where(
|
||||
PreFacturasDetalle.factura==id)
|
||||
|
||||
for p in productos:
|
||||
row = {'id': p.producto.id}
|
||||
row['clave'] = p.producto.clave
|
||||
row['descripcion'] = p.descripcion
|
||||
row['unidad'] = p.producto.unidad.name
|
||||
row['cantidad'] = p.cantidad
|
||||
row['valor_unitario'] = p.valor_unitario
|
||||
row['importe'] = p.importe
|
||||
impuestos = cls._get_impuestos(cls, row['id'])
|
||||
data.append({'row': row, 'taxes': impuestos})
|
||||
|
||||
return {'rows': data, 'receptor': receptor}
|
||||
|
||||
@classmethod
|
||||
def get_(cls, id):
|
||||
data = []
|
||||
|
|
|
@ -1015,8 +1015,46 @@ function cmd_delete_preinvoice_click(id, e, node){
|
|||
}
|
||||
|
||||
|
||||
function agregar_preproducto(values){
|
||||
var taxes = values.taxes
|
||||
var values = values.row
|
||||
var form = $$('form_invoice')
|
||||
var row = grid.getItem(values.id)
|
||||
|
||||
values['delete'] = '-'
|
||||
if (row == undefined){
|
||||
grid.add(values)
|
||||
} else {
|
||||
values['cantidad'] = parseFloat(row.cantidad) + parseFloat(values['cantidad'])
|
||||
values['importe'] = values['valor_unitario'] * values['cantidad']
|
||||
grid.updateItem(row.id, values)
|
||||
}
|
||||
|
||||
for(var v of taxes){
|
||||
var pt = table_pt.findOne(v)
|
||||
if(pt === null){
|
||||
table_pt.insert(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function refacturar_preinvoice(id){
|
||||
$$('tv_invoice').getTabbar().setValue('Generar')
|
||||
|
||||
webix.ajax().get('/values/preproductos', {'id': id}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg_error('Error al consultar')
|
||||
},
|
||||
success: function(text, data, xhr){
|
||||
var values = data.json()
|
||||
set_client(values.receptor)
|
||||
for(var p of values.rows){
|
||||
agregar_preproducto(p)
|
||||
}
|
||||
calculate_taxes()
|
||||
$$('tv_invoice').getTabbar().setValue('Generar')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue