Llevar inventario

This commit is contained in:
Mauricio Baeza 2018-01-05 13:33:43 -06:00
parent d88caeb8c6
commit f5b34eec5b
5 changed files with 51 additions and 9 deletions

View File

@ -203,6 +203,7 @@ class Configuracion(BaseModel):
'chk_config_cuenta_predial',
'chk_config_codigo_barras',
'chk_config_precio_con_impuestos',
'chk_llevar_inventario',
)
data = (Configuracion
.select()
@ -241,6 +242,7 @@ class Configuracion(BaseModel):
'chk_config_cuenta_predial',
'chk_config_codigo_barras',
'chk_config_precio_con_impuestos',
'chk_llevar_inventario',
'chk_config_ine',
'chk_config_edu',
'chk_usar_punto_de_venta',
@ -2195,6 +2197,9 @@ class Productos(BaseModel):
Productos.unidad,
Productos.valor_unitario,
Productos.cuenta_predial,
Productos.inventario,
Productos.existencia,
Productos.minimo,
)
.where(Productos.id==id).dicts()[0]
)
@ -4050,6 +4055,10 @@ class Tickets(BaseModel):
TicketsDetalle.create(**producto)
if p.inventario:
p.existencia -= Decimal(cantidad)
p.save()
base = producto['importe']
for tax in p.impuestos:
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
@ -4292,13 +4301,24 @@ class Tickets(BaseModel):
data = {'ok': True, 'msg': msg, 'id': obj.id}
return data
def _update_inventory_if_cancel(self, id):
products = TicketsDetalle.select().where(TicketsDetalle.ticket==id)
for p in products:
if p.producto.inventario:
p.producto.existencia += p.cantidad
p.producto.save()
return
@classmethod
def cancel(cls, values):
id = int(values['id'])
msg = 'Ticket cancelado correctamente'
u = {'cancelado': True, 'estatus': 'Cancelado'}
obj = Tickets.update(**u).where(Tickets.id==id)
result = bool(obj.execute())
with database_proxy.atomic() as txn:
obj = Tickets.update(**u).where(Tickets.id==id)
result = bool(obj.execute())
if result:
cls._update_inventory_if_cancel(cls, id)
row = {'estatus': 'Cancelado'}
return {'ok': result, 'row': row, 'msg': msg}

View File

@ -61,6 +61,7 @@ var controllers = {
$$('chk_config_cuenta_predial').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_codigo_barras').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_precio_con_impuestos').attachEvent('onItemClick', chk_config_item_click)
$$('chk_llevar_inventario').attachEvent('onItemClick', chk_config_item_click)
$$('chk_usar_punto_de_venta').attachEvent('onItemClick', chk_config_item_click)
$$('chk_ticket_pdf_show').attachEvent('onItemClick', chk_config_item_click)
$$('chk_ticket_direct_print').attachEvent('onItemClick', chk_config_item_click)
@ -1763,4 +1764,4 @@ function txt_ticket_printer_key_press(code, e){
}
})
}
}

View File

@ -11,6 +11,7 @@ var products_controllers = {
$$("valor_unitario").attachEvent("onChange", valor_unitario_change)
$$('precio_con_impuestos').attachEvent('onChange', precio_con_impuestos_change)
$$('precio_con_impuestos').attachEvent('onTimedKeyPress', precio_con_impuestos_key_up);
$$("chk_inventario").attachEvent("onChange", chk_inventario_change)
$$('grid_products').attachEvent('onItemDblClick', cmd_edit_product_click)
}
}
@ -28,6 +29,9 @@ function configurar_productos(is_new){
show('cuenta_predial', values.chk_config_cuenta_predial)
show('codigo_barras', values.chk_config_codigo_barras)
show('precio_con_impuestos', values.chk_config_precio_con_impuestos)
show('chk_inventario', values.chk_llevar_inventario)
show('txt_existencia', values.chk_llevar_inventario)
show('txt_minimo', values.chk_llevar_inventario)
$$('unidad').setValue(values.default_unidad)
if(is_new){
$$('grid_product_taxes').select(values.default_tax)
@ -228,6 +232,20 @@ function chk_automatica_change(new_value, old_value){
}
function chk_inventario_change(new_value, old_value){
var value = Boolean(new_value)
if(value){
$$('txt_existencia').enable()
$$('txt_minimo').enable()
}else{
$$('txt_existencia').disable()
$$('txt_minimo').disable()
$$('txt_existencia').setValue(0)
$$('txt_minimo').setValue(0)
}
}
function get_new_key(){
webix.ajax().get('/values/newkey', {
error: function(text, data, xhr) {
@ -291,4 +309,4 @@ function precio_con_impuestos_key_up(){
return
}
calcular_sin_impuestos(parseFloat(value), taxes)
}
}

View File

@ -523,6 +523,8 @@ var options_admin_otros = [
labelRight: 'Mostrar código de barras'},
{view: 'checkbox', id: 'chk_config_precio_con_impuestos', labelWidth: 0,
labelRight: 'Mostrar precio con impuestos'},
{view: 'checkbox', id: 'chk_llevar_inventario', labelWidth: 0,
labelRight: 'Mostrar inventario'},
]},
{maxHeight: 20},
{template: 'Complementos', type: 'section'},

View File

@ -134,13 +134,14 @@ var controls_generals = [
invalidMessage: 'Captura un valor númerico', inputAlign: 'right'},
{},]},
{cols: [
{view: 'checkbox', id: 'inventario', name: 'inventario', hidden: true,
{view: 'checkbox', id: 'chk_inventario', name: 'inventario', hidden: true,
label: 'Inventario', labelAlign: 'right', labelWidth: 130},
{view: 'counter', id: 'existencia', name: 'existencia', hidden: true,
label: 'Existencia', step: 5, value: 0, min: 0, disabled: true},
{view: 'counter', id: 'minimo', name: 'minimo', hidden: true,
{view: 'counter', id: 'txt_existencia', name: 'existencia',
hidden: true, label: 'Existencia', step: 5, value: 0, min: 0,
disabled: true},
{view: 'counter', id: 'txt_minimo', name: 'minimo', hidden: true,
label: 'Mínimo', step: 5, value: 0, min: 0, disabled: true},
{id: 'txt_col2'}]},
]},
{cols:[{view:'label', label:'Impuestos', width: 300, align:'center'}, {}]},
{cols:[grid_product_taxes, {}]}
]