feat(item): modify item_getBalance and do test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2021-11-19 10:02:40 +01:00
parent c101bbb6be
commit ac9ed90f4a
3 changed files with 36 additions and 6 deletions

View File

@ -2,8 +2,7 @@ DROP PROCEDURE IF EXISTS `vn`.`item_getBalance`;
DELIMITER $$ DELIMITER $$
$$ $$
CREATE CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int)
definer = root@`%` procedure `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int)
BEGIN BEGIN
DECLARE vDateInventory DATETIME; DECLARE vDateInventory DATETIME;
DECLARE vCurdate DATE DEFAULT CURDATE(); DECLARE vCurdate DATE DEFAULT CURDATE();
@ -116,7 +115,7 @@ BEGIN
s.id, s.id,
st.`order`, st.`order`,
ct.code, ct.code,
cl.id cb.claimFk
FROM sale s FROM sale s
JOIN ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN ticketState ts ON ts.ticket = t.id LEFT JOIN ticketState ts ON ts.ticket = t.id
@ -132,6 +131,7 @@ BEGIN
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id 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 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 WHERE t.shipped >= vDateInventory
AND s.itemFk = vItemId AND s.itemFk = vItemId
AND vWarehouse =t.warehouseFk AND vWarehouse =t.warehouseFk
@ -141,4 +141,3 @@ BEGIN
END; END;
$$ $$
DELIMITER ; DELIMITER ;

View File

@ -112,8 +112,7 @@ module.exports = Self => {
case 'isActive': case 'isActive':
case 'typeFk': case 'typeFk':
case 'isFloramondo': case 'isFloramondo':
param = `i.${param}`; return {[`i.${param}`]: value};
return {[param]: value};
case 'multiplier': case 'multiplier':
return {'i.stemMultiplier': value}; return {'i.stemMultiplier': value};
case 'categoryFk': case 'categoryFk':

View File

@ -36,4 +36,36 @@ describe('item getBalance()', () => {
throw e; 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;
}
});
}); });