From 9c52508a88a20d1d5d827b3c8c3e4d08494b32d0 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 08:40:22 +0200 Subject: [PATCH] feat: add total labels --- .../00-aclItemShelving.sql | 0 .../00-aclItemShelvingPlacementSupply.sql} | 0 .../00-itemType.sql | 0 .../item-shelving/deleteItemShelvings.js | 47 +++++++++++++++++++ .../specs/deleteItemShelvings.spec.js | 21 +++++++++ modules/item/back/models/item-shelving.js | 3 ++ modules/item/front/item-shelving/index.html | 18 +++---- modules/item/front/item-shelving/index.js | 45 ++++++------------ .../item/front/item-shelving/locale/es.yml | 4 +- 9 files changed, 98 insertions(+), 40 deletions(-) rename db/changes/{10490-august => 10491-august}/00-aclItemShelving.sql (100%) rename db/changes/{10490-august/00-aclItemShelvingPlacementSupply copy.sql => 10491-august/00-aclItemShelvingPlacementSupply.sql} (100%) rename db/changes/{10480-june => 10491-august}/00-itemType.sql (100%) create mode 100644 modules/item/back/methods/item-shelving/deleteItemShelvings.js create mode 100644 modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js create mode 100644 modules/item/back/models/item-shelving.js diff --git a/db/changes/10490-august/00-aclItemShelving.sql b/db/changes/10491-august/00-aclItemShelving.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelving.sql rename to db/changes/10491-august/00-aclItemShelving.sql diff --git a/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql b/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql rename to db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10491-august/00-itemType.sql similarity index 100% rename from db/changes/10480-june/00-itemType.sql rename to db/changes/10491-august/00-itemType.sql diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js new file mode 100644 index 000000000..0b58970d8 --- /dev/null +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -0,0 +1,47 @@ +module.exports = Self => { + Self.remoteMethod('deleteItemShelvings', { + description: 'Deletes the selected orders', + accessType: 'WRITE', + accepts: [{ + arg: 'itemShelvingIds', + type: ['number'], + required: true, + description: 'The itemShelving ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteItemShelvings`, + verb: 'POST' + } + }); + + Self.deleteItemShelvings = async(itemShelvingIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deletedItemShelvings = await models.ItemShelving.destroyAll({ + id: {inq: itemShelvingIds} + }, myOptions); + + if (tx) await tx.commit(); + + return deletedItemShelvings; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js new file mode 100644 index 000000000..a152b5981 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('ItemShelving deleteItemShelvings()', () => { + it('should return the deleted itemShelvings', async() => { + const tx = await models.Order.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const itemShelvingIds = [1, 2]; + const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); + + expect(result.count).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js new file mode 100644 index 000000000..5f372a3be --- /dev/null +++ b/modules/item/back/models/item-shelving.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/item-shelving/deleteItemShelvings')(Self); +}; diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html index 115829c8d..fa7a70544 100644 --- a/modules/item/front/item-shelving/index.html +++ b/modules/item/front/item-shelving/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemShelvingPlacementSupplyStocks" link="{itemFk: $ctrl.$params.id}" - data="itemShelvingPlacementSupplyStocks" + data="$ctrl.itemShelvingPlacementSupplyStocks" auto-load="true"> @@ -15,18 +15,18 @@
Total
+ label="Total labels" + value="{{$ctrl.labelTotal.toFixed(2)}}">
+ vn-acl="replenisherBos">
@@ -68,7 +68,9 @@ - + - {{::itemShelvingPlacementSupplyStock.label}} + {{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}} {{::itemShelvingPlacementSupplyStock.packing}} diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js index 6fd8825aa..b8584039b 100644 --- a/modules/item/front/item-shelving/index.js +++ b/modules/item/front/item-shelving/index.js @@ -40,8 +40,6 @@ export default class Controller extends Section { } ] }; - - this.getBalanceDueTotal(); } get checked() { @@ -49,46 +47,31 @@ export default class Controller extends Section { const checkedLines = []; for (let itemShelving of itemShelvings) { if (itemShelving.checked) - checkedLines.push(itemShelving); + checkedLines.push(itemShelving.itemShelvingFk); } return checkedLines; } - get label() { + calculateTotals() { + this.labelTotal = 0; const itemShelvings = this.$.model.data || []; - for (let itemShelving of itemShelvings) - itemShelving.label = itemShelving.stock / itemShelving.packing; - - return true; + itemShelvings.forEach(itemShelving => { + const label = itemShelving.stock / itemShelving.packing; + this.labelTotal += label; + }); } - getBalanceDueTotal() { - this.$http.get('Defaulters/filter') - .then(res => { - if (!res.data) return 0; - - this.balanceDueTotal = res.data.reduce( - (accumulator, currentValue) => { - return accumulator + (currentValue['amount'] || 0); - }, 0); + onRemove() { + const params = {itemShelvingIds: this.checked}; + const query = `ItemShelvings/deleteItemShelvings`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelvings removed')); + this.$.model.refresh(); }); } - async onRemove() { - const params = []; - for (let itemShelving of this.checked) - params.push(itemShelving.itemShelvingFk); - - for (let id of params) { - await this.$http.delete(`ItemShelvings/${id}`) - .then(() => { - this.vnApp.showSuccess(this.$t('ItemShelving removed')); - this.$state.reload(); - }); - } - } - exprBuilder(param, value) { switch (param) { case 'parking': diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml index 00b6ffe58..006363cfa 100644 --- a/modules/item/front/item-shelving/locale/es.yml +++ b/modules/item/front/item-shelving/locale/es.yml @@ -1,3 +1,5 @@ Shelving: Matrícula Remove selected lines: Eliminar líneas seleccionadas -Selected lines will be deleted: Las líneas seleccionadas serán eliminadas \ No newline at end of file +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas +ItemShelvings removed: Carros eliminados +Total labels: Total etiquetas \ No newline at end of file