Add inventory entries manually

This commit is contained in:
Mauricio Baeza 2021-07-08 12:56:40 -05:00
parent 34c467d26e
commit 4f3bdbda95
6 changed files with 67 additions and 13 deletions

View File

@ -693,6 +693,7 @@ class AppInventoryEntries(object):
def on_post(self, req, resp):
values = req.params
req.context['result'] = self._db.inventory_entries_post(values)
user = req.env['beaker.session']['userobj']
req.context['result'] = self._db.inventory_entries_post(values, user)
resp.status = falcon.HTTP_200

View File

@ -484,8 +484,8 @@ class StorageEngine(object):
def inventory_entries_get(self, filters):
return main.InventoryEntries.get_data(filters)
def inventory_entries_post(self, filters):
return main.InventoryEntries.post(filters)
def inventory_entries_post(self, filters, user):
return main.InventoryEntries.post(filters, user)
# Companies only in MV
def _get_empresas(self, values):

View File

@ -9524,7 +9524,7 @@ class InventoryEntries(BaseModel):
return msg
def _create(self, args):
def _create(self, args, user):
# ~ print('ARGS', args)
partner, error = self._get_or_create_partner(self, args['partner'])
@ -9542,11 +9542,34 @@ class InventoryEntries(BaseModel):
result = {'ok': True, 'msg': ''}
return result
def _create_manual(self, args, user):
product = Productos.get(Productos.id==args['product_id'])
if not product.inventario:
msg = 'Este producto no lleva inventario.'
result = {'ok': False, 'msg': msg}
return result
cant = args['cant']
values = dict(
product = product,
cant = cant,
)
obj = InventoryEntries.create(**values)
msg = 'A {}'.format(obj.id)
_save_log(user.usuario, msg, 'IE')
product.existencia += cant
product.save()
result = {'ok': True, 'row': {'existencia': product.existencia}}
return result
@classmethod
def post(cls, values):
def post(cls, values, user=None):
opt = values['opt']
args = utils.loads(values['values'])
return getattr(cls, f'_{opt}')(cls, args)
return getattr(cls, f'_{opt}')(cls, args, user)
@util.run_in_thread

View File

@ -706,7 +706,8 @@ function cmd_add_inventory_cancel_click(id, e, node){
function cmd_add_inventory_save_click(id, e, node){
var id_product = $$('txt_add_id').getValue()
var product_id = $$('txt_add_id').getValue()
//~ var product_key = $$('txt_add_key').getValue()
var new_cant = $$('txt_new_cant').getValue()
if(new_cant<=0) {
@ -726,7 +727,7 @@ function cmd_add_inventory_save_click(id, e, node){
text: msg,
callback:function(result){
if(result){
add_product_stock(id_product, new_cant)
add_product_stock(product_id, new_cant)
}
}
})
@ -734,8 +735,37 @@ function cmd_add_inventory_save_click(id, e, node){
}
function add_product_stock(id_product, new_cant){
msg_ok(id_product)
msg_ok(new_cant)
function add_product_stock(product_id, new_cant){
var data = {
product_id: product_id,
cant: new_cant,
}
_add_entries_inventory_manual(product_id, data)
$$('win_add_inventory').close()
}
function _add_entries_inventory_manual(row_id, data){
var grid = $$('grid_products')
var values = {
opt: 'create_manual',
values: data,
}
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) {
grid.updateItem(row_id, values.row)
grid.refresh()
}else{
msg_error(values.msg)
}
}
})
}

View File

@ -60,7 +60,7 @@ var menu_user = {
var link_blog = "<a class='link_default' target='_blank' href='https://blog.empresalibre.mx'>Blog</a>";
var link_forum = "<a class='link_default' target='_blank' href='https://gitlab.com/mauriciobaeza/empresa-libre/issues'>Foro</a>";
var link_forum = "<a class='link_default' target='_blank' href='https://git.cuates.net/elmau/empresa-libre/issues'>Foro</a>";
var link_doc = "<a class='link_default' target='_blank' href='https://doc.empresalibre.mx'>Doc</a>";

View File

@ -428,7 +428,7 @@ var body_add_inventory = {rows: [{minHeight: 10},
{view: 'textarea', id: 'txt_add_description', height: 100,
label: 'Descripción', readonly: true, labelPosition: 'top'},
{view: 'counter', id: 'txt_new_cant', label: 'Cantidad a agregar',
labelWidth: 'auto', step: 5, value: 0, min: 0.01},
labelWidth: 'auto', step: 1, value: 0, min: 0.01},
{minHeight: 20},
{cols: [{},
{view: 'button', id: 'cmd_add_inventory_save', label: 'Guardar'}, {},