From a3e69d604a642e7aa06ce5dce415cd3fb5b63f24 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 18 Feb 2019 13:31:57 +0100 Subject: [PATCH] getAvailable aislado --- modules/item/back/methods/item/getCard.js | 10 ------ .../back/methods/item/getVisibleAvailable.js | 11 +++---- modules/item/front/descriptor/index.html | 11 ++----- modules/item/front/descriptor/index.js | 31 ++++++++++++------- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/modules/item/back/methods/item/getCard.js b/modules/item/back/methods/item/getCard.js index eb479607b..9780c5601 100644 --- a/modules/item/back/methods/item/getCard.js +++ b/modules/item/back/methods/item/getCard.js @@ -60,16 +60,6 @@ module.exports = Self => { }; [item] = await Self.app.models.Item.find(filter); - // Visible Available - let query = ` - CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; - - let options = [item.id, item.itemType().warehouseFk, false]; - let [res] = await Self.rawSql(query, options); - - item.available = res[0].available; - item.visible = res[0].visible; - return item; }; }; diff --git a/modules/item/back/methods/item/getVisibleAvailable.js b/modules/item/back/methods/item/getVisibleAvailable.js index 6e9f2b531..fecdb736b 100644 --- a/modules/item/back/methods/item/getVisibleAvailable.js +++ b/modules/item/back/methods/item/getVisibleAvailable.js @@ -4,7 +4,7 @@ module.exports = Self => { accessType: '', accepts: [ { - arg: 'itemFk', + arg: 'id', type: 'Number', required: true, }, @@ -18,21 +18,20 @@ module.exports = Self => { root: true }, http: { - path: `/getVisibleAvailable`, + path: `/:id/getVisibleAvailable`, verb: 'GET' } }); Self.getVisibleAvailable = async(itemFk, warehouseFk) => { - let item = {}; let query = ` CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; let options = [itemFk, warehouseFk, false]; [res] = await Self.rawSql(query, options); - item.available = res[0].available; - item.visible = res[0].visible; - return item; + return { + available: res[0].available, + visible: res[0].visible}; }; }; diff --git a/modules/item/front/descriptor/index.html b/modules/item/front/descriptor/index.html index 22769d5a7..a0d6404f5 100644 --- a/modules/item/front/descriptor/index.html +++ b/modules/item/front/descriptor/index.html @@ -1,10 +1,3 @@ - -
diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index 268fbfb8a..edf6d6444 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import './style.scss'; +import {runInThisContext} from 'vm'; class Controller { constructor($state, $scope, $http, vnApp, $translate) { @@ -34,23 +35,29 @@ class Controller { set item(value) { this._item = value; - this.available = null; - this.visible = null; - if (!this.item) { - this.params = { - params: { - itemFk: this.item, - warehouseFk: this._warehouseFk - } - }; - } - return this._item; + this.updateStock(); } get item() { return this._item; } + updateStock() { + this.available = null; + this.visible = null; + if (this._item && this._item.id) { + let options = { + params: { + warehouseFk: this._warehouseFk + } + }; + this.$http.get(`/item/api/Items/${this._item.id}/getVisibleAvailable`, options).then(response => { + this.available = response.data.available; + this.visible = response.data.visible; + }); + } + } + onMoreChange(callback) { callback.call(this); } @@ -75,7 +82,7 @@ class Controller { warehouseFk: this.warehouseFk }).then(res => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.card.reload(); + this.updateStock(); }); } }