Add controller for warehouse movement

This commit is contained in:
Mauricio Baeza 2021-10-14 19:20:23 -05:00
parent 866e8c40b9
commit 75788474ba
3 changed files with 140 additions and 17 deletions

View File

@ -3684,7 +3684,6 @@ class Usuarios(BaseModel):
class Productos(BaseModel):
# ~ almacen = ForeignKeyField(Almacenes, null=True)
categoria = ForeignKeyField(Categorias, null=True)
clave = TextField(unique=True, index=True)
clave_sat = TextField(default='')
@ -9873,6 +9872,42 @@ class InventoryEntries(BaseModel):
result = {'ok': True, 'row': {'existencia': new_cant}}
return result
def _warehouse_movement(self, args, user):
if not user.es_admin:
msg = 'Solo un administrador puede usar esta función.'
result = {'ok': False, 'msg': msg}
return result
product = Productos.get(Productos.id==args['id_product'])
if not product.inventario:
msg = 'Este producto no lleva inventario.'
result = {'ok': False, 'msg': msg}
return result
storage = args['target']
cant = Decimal(args['cant'])
values = dict(
storage = storage,
product = product,
cant = cant,
)
obj = InventoryEntries.create(**values)
msg = 'a {}'.format(obj.id)
_save_log(user.usuario, msg, 'IE')
WareHouseProduct.update_exists(values)
values['storage'] = args['source']
values['cant'] *= -1
obj = InventoryEntries.create(**values)
msg = 'a {}'.format(obj.id)
_save_log(user.usuario, msg, 'IE')
WareHouseProduct.update_exists(values)
result = {'ok': True}
return result
@classmethod
def post(cls, values, user=None):

View File

@ -1,4 +1,5 @@
var cfg_products = new Object()
var gis_admin = false
function products_default_config(){
@ -30,6 +31,7 @@ function products_default_config(){
},
success: function(text, data, xhr) {
var values = data.json()
gis_admin = values.is_admin
if(values.is_admin){
$$('cmd_add_inventory').show()
//~ $$('cmd_products_add').show()
@ -478,11 +480,102 @@ function cmd_show_exists_click(id, e, node){
}
win_show_exists.init()
$$('txt_id_product').setValue(row.id)
$$('grid_warehouse_exists').load('warehouseproduct?opt=by_product&id='+row.id)
$$('grid_warehouse_exists').load('warehouseproduct?opt=by_product&id=' + row.id)
if(gis_admin){
$$('lst_warehouse_target').getList().load('/warehouse?opt=for_select')
}else{
$$('lbl_title_move').hide()
$$('txt_cant_to_move').hide()
$$('lst_warehouse_target').hide()
$$('cmd_warehouse_move').hide()
}
$$('win_show_exists').show()
}
function cmd_warehouse_move_click(id, e, node){
var id_product = $$('txt_id_product').getValue()
var row = $$('grid_warehouse_exists').getSelectedItem()
if (row == undefined){
msg_error('Selecciona un Almacen origen')
return
}
var warehouse_source = row.id
var cant_to_move = $$('txt_cant_to_move').getValue()
var warehouse_target = $$('lst_warehouse_target').getValue()
if(!cant_to_move){
msg_error('La cantidad no puede ser cero')
return
}
if(cant_to_move > row.exists){
msg_error('La cantidad a mover no puede ser mayor a la existencia')
return
}
if (warehouse_target == ''){
msg_error('Selecciona un Almacen destino')
return
}
if (warehouse_source == warehouse_target){
msg_error('Los almacenes origen y destino deben ser diferentes')
return
}
var values = {
id_product: id_product,
cant: cant_to_move,
source: warehouse_source,
target: warehouse_target
}
msg = '¿Estás seguro de hacer este movimiento?'
webix.confirm({
title: 'Movimiento de Almacen',
ok: 'Si',
cancel: 'No',
type: 'confirm-error',
text: msg,
callback:function(result){
if(result){
_warehouse_movement(values)
}
}
})
}
function _warehouse_movement(args){
var values = {
opt: 'warehouse_movement',
values: args,
}
webix.ajax().sync().post('inventoryentries', values, {
error:function(text, data, XmlHttpRequest){
msg = 'Ocurrio un error, consulta a soporte técnico'
msg_error(msg)
},
success:function(text, data, XmlHttpRequest){
var values = data.json();
if (values.ok) {
$$('txt_cant_to_move').setValue(0)
$$('lst_warehouse_target').setValue('')
$$('grid_warehouse_exists').load('warehouseproduct?opt=by_product&id=' + args.id_product)
$$('grid_warehouse_exists').clearSelection()
msg_ok('Movimiento realizado correctamente')
}else{
msg_error(values.msg)
}
}
})
}
function cmd_win_show_exists_close_click(id, e, node){
$$('win_show_exists').close()
}
@ -815,13 +908,5 @@ function _add_entries_inventory_manual(row_id, data){
}
}
})
}
function cmd_warehouse_move_click(id, e, node){
var id_product = $$('txt_id_product').getValue()
msg_ok(id_product)
}

View File

@ -464,9 +464,11 @@ var win_add_inventory = {
var grid_warehouse_exists_cols = [
{ id: 'id', header: 'ID', width: 75, hidden: true},
{ id: 'warehouse', header: ['Almacen'], fillspace:true},
{ id: 'warehouse', header: ['Almacen'], fillspace:true,
footer: {text: 'Total', css: 'right'}},
{ id: 'exists', header: ['Existencia'], width: 100, sort: 'int',
format: webix.i18n.numberFormat, css: 'right' },
format: webix.i18n.numberFormat, css: 'right',
footer: {content: 'summColumn', css: 'right'} },
]
@ -481,7 +483,8 @@ var grid_warehouse_exists = {
}
var body_win_show_exists = {rows: [{maxHeight: 10},
var body_win_show_exists = {rows: [{maxHeight: 10, minHeight: 10},
{minWidth: 500},
{cols: [
{maxWidth: 10},
{view: 'text', id: 'txt_id_product', readonly: true, hidden: true},
@ -490,8 +493,8 @@ var body_win_show_exists = {rows: [{maxHeight: 10},
]},
{maxHeight: 10},
{cols: [{maxWidth: 10},
{view: 'label', label: 'Primero, selecciona el almacen origen en la tabla superior.'},
{maxWidth: 10}]},
{view: 'label', id: 'lbl_title_move', label: 'Primero, selecciona el almacen origen en la tabla superior.'},
]},
{cols: [{maxWidth: 10},
{view: 'counter', id: 'txt_cant_to_move', label: 'Cantidad a mover:',
labelPosition: 'top', step: 1, value: 0, min: 0.01},
@ -499,11 +502,11 @@ var body_win_show_exists = {rows: [{maxHeight: 10},
labelPosition: 'top', required: false, options: []}, {maxWidth: 10},
{view: 'button', id: 'cmd_warehouse_move', label: 'Mover', maxWidth: 100},
{maxWidth: 10}]},
{maxHeight: 20},
{maxHeight: 20, minHeight: 20},
{cols: [{},
{view: 'button', id: 'cmd_win_show_exists_close', label: 'Cerrar', type: 'danger'},
{}]},
{maxHeight: 20},
{maxHeight: 20, minHeight: 20},
]}