Validate stock when invoice

This commit is contained in:
Mauricio Baeza 2021-06-01 19:34:34 -05:00
parent 0442019ea5
commit e9eeab8c2c
6 changed files with 52 additions and 11 deletions

View File

@ -1,4 +1,9 @@
v 1.42.1 [00-Jun-2021]
v 1.43.0 [00-Jun-2021]
----------------------
- Soporte para multialmacen
v 1.42.1 [31-May-2021]
----------------------
- Error - Ticket #5

View File

@ -1,2 +1,2 @@
1.42.1
1.43.0

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# ~ Empresa Libre
# ~ Copyright (C) 2016-2018 Mauricio Baeza Servin (web@correolibre.net)
# ~ Copyright (C) 2016-2021 Mauricio Baeza Servin (public@correolibre.net)
# ~
# ~ This program is free software: you can redistribute it and/or modify
# ~ it under the terms of the GNU General Public License as published by
@ -16,6 +16,7 @@
# ~ You should have received a copy of the GNU General Public License
# ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
from decimal import Decimal
import sqlite3
@ -3553,7 +3554,9 @@ class Productos(BaseModel):
Productos.descripcion,
SATUnidades.id.alias('unidad'),
Productos.valor_unitario,
Productos.descuento)
Productos.descuento,
Productos.inventario,
Productos.existencia)
.join(SATUnidades).switch(Productos)
.where((Productos.es_activo==True) &
((Productos.clave==clave) | (Productos.codigo_barras==clave)))
@ -3567,7 +3570,8 @@ class Productos(BaseModel):
model_pt.productos_id.alias('product'),
model_pt.satimpuestos_id.alias('tax'))
.where(model_pt.productos_id==id).dicts())
return {'ok': True, 'row': row[0], 'taxes': taxes}
product = row[0]
return {'ok': True, 'row': product, 'taxes': taxes}
return {'ok': False}

View File

@ -42,7 +42,7 @@ except ImportError:
DEBUG = DEBUG
VERSION = '1.42.1'
VERSION = '1.43.0'
EMAIL_SUPPORT = ('soporte@empresalibre.mx',)
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)

View File

@ -909,9 +909,9 @@ function calcular_impuestos(){
}
function set_product(values){
var taxes = values.taxes
var values = values.row
function set_product(data){
var taxes = data.taxes
var values = data.row
var form = $$('form_invoice')
var row = undefined
@ -928,17 +928,33 @@ function set_product(values){
if (row == undefined){
values['cantidad'] = 1
values['importe'] = values['valor_unitario']
grid.add(values)
//~ grid.add(values)
} else {
values['cantidad'] = parseFloat(row.cantidad) + 1
values['descuento'] = parseFloat(row.descuento)
values['valor_unitario'] = parseFloat(row.valor_unitario)
var precio_final = values['valor_unitario'] - values['descuento']
values['importe'] = (precio_final * values['cantidad']).round(DECIMALES)
grid.updateItem(row.id, values)
//~ grid.updateItem(row.id, values)
}
form.setValues({search_product_id: '', search_product_name: ''}, true)
//~ Validate stock
if(values.inventario){
if(values.cantidad > values.existencia){
msg_error('No hay suficiente existencia de este producto')
return
}
}
if(row == undefined){
grid.add(values)
}else{
grid.updateItem(row.id, values)
}
for(var v of taxes){
var pt = table_pt.findOne(v)
if(pt === null){
@ -1071,6 +1087,20 @@ function grid_details_before_edit_stop(state, editor){
}
cantidad = cantidad.round(DECIMALES)
//~ Validate stock
if(row['inventario']){
if(cantidad > row['existencia']){
msg = 'No hay suficiente existencia de este producto'
msg_error(msg)
grid.blockEvent()
state.value = state.old
grid.editCancel()
grid.unblockEvent()
return true
}
}
grid.blockEvent()
state.value = cantidad
grid.unblockEvent()

View File

@ -359,6 +359,8 @@ var grid_details_cols = [
format: webix.i18n.priceFormat, css: 'right'},
{id: "importe", header:{text: 'Importe', css: 'center'}, width: 150,
format: webix.i18n.priceFormat, css: 'right'},
{id: "inventario", hidden: true},
{id: "existencia", hidden: true},
]