From 4f3bdbda9501bc7c7f9ca3cc72672e64ffb89697 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Thu, 8 Jul 2021 12:56:40 -0500 Subject: [PATCH] Add inventory entries manually --- source/app/controllers/main.py | 3 +- source/app/models/db.py | 4 +-- source/app/models/main.py | 29 ++++++++++++++++-- source/static/js/controller/products.js | 40 +++++++++++++++++++++---- source/static/js/ui/main.js | 2 +- source/static/js/ui/products.js | 2 +- 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/source/app/controllers/main.py b/source/app/controllers/main.py index 4635e5c..4bf3178 100644 --- a/source/app/controllers/main.py +++ b/source/app/controllers/main.py @@ -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 diff --git a/source/app/models/db.py b/source/app/models/db.py index f2cdff6..3083d56 100644 --- a/source/app/models/db.py +++ b/source/app/models/db.py @@ -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): diff --git a/source/app/models/main.py b/source/app/models/main.py index 7c83a0b..081b7f2 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -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 diff --git a/source/static/js/controller/products.js b/source/static/js/controller/products.js index 4415d60..5353526 100644 --- a/source/static/js/controller/products.js +++ b/source/static/js/controller/products.js @@ -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) + } + } + }) + +} diff --git a/source/static/js/ui/main.js b/source/static/js/ui/main.js index 469eb90..cb2e133 100644 --- a/source/static/js/ui/main.js +++ b/source/static/js/ui/main.js @@ -60,7 +60,7 @@ var menu_user = { var link_blog = "Blog"; -var link_forum = "Foro"; +var link_forum = "Foro"; var link_doc = "Doc"; diff --git a/source/static/js/ui/products.js b/source/static/js/ui/products.js index d05b209..7e27242 100644 --- a/source/static/js/ui/products.js +++ b/source/static/js/ui/products.js @@ -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'}, {},