From ac9ed90f4a7c8f21470fb903ea6a0e0a2b584770 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 19 Nov 2021 10:02:40 +0100 Subject: [PATCH] feat(item): modify item_getBalance and do test --- .../10390-constitution/00-item_getBalance.sql | 7 ++-- modules/item/back/methods/item/filter.js | 3 +- .../methods/item/specs/getBalance.spec.js | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/db/changes/10390-constitution/00-item_getBalance.sql b/db/changes/10390-constitution/00-item_getBalance.sql index 90e3ee2bb..54f612eae 100644 --- a/db/changes/10390-constitution/00-item_getBalance.sql +++ b/db/changes/10390-constitution/00-item_getBalance.sql @@ -2,8 +2,7 @@ DROP PROCEDURE IF EXISTS `vn`.`item_getBalance`; DELIMITER $$ $$ -CREATE - definer = root@`%` procedure `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int) +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int) BEGIN DECLARE vDateInventory DATETIME; DECLARE vCurdate DATE DEFAULT CURDATE(); @@ -116,7 +115,7 @@ BEGIN s.id, st.`order`, ct.code, - cl.id + cb.claimFk FROM sale s JOIN ticket t ON t.id = s.ticketFk LEFT JOIN ticketState ts ON ts.ticket = t.id @@ -132,6 +131,7 @@ BEGIN LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id LEFT JOIN claim cl ON cl.ticketFk = t.id + LEFT JOIN claimBeginning cb ON cl.id = cb.claimFk AND s.id = cb.saleFk WHERE t.shipped >= vDateInventory AND s.itemFk = vItemId AND vWarehouse =t.warehouseFk @@ -141,4 +141,3 @@ BEGIN END; $$ DELIMITER ; - diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 29099c7ec..810cf4071 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -112,8 +112,7 @@ module.exports = Self => { case 'isActive': case 'typeFk': case 'isFloramondo': - param = `i.${param}`; - return {[param]: value}; + return {[`i.${param}`]: value}; case 'multiplier': return {'i.stemMultiplier': value}; case 'categoryFk': diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index 5143a346f..779516b19 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -36,4 +36,36 @@ describe('item getBalance()', () => { throw e; } }); + + it('should show the claimFk only on the claimed item', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const firstFilter = { + where: { + itemFk: 1, + warehouseFk: 1 + } + }; + + const secondFilter = { + where: { + itemFk: 2, + warehouseFk: 1 + } + }; + + const firstItemBalance = await models.Item.getBalance(firstFilter, options); + const secondItemBalance = await models.Item.getBalance(secondFilter, options); + + expect(firstItemBalance[9].claimFk).toEqual(null); + expect(secondItemBalance[5].claimFk).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); });