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/db/dump/fixtures.sql b/db/dump/fixtures.sql index b46056135..5b7ac3240 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1882,6 +1882,7 @@ INSERT INTO `postgresql`.`calendar_state` (`calendar_state_id`, `type`, `rgb`, ` INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id`, `date`) VALUES + (1, 6, IF(MONTH(CURDATE()) = 12 AND DAY(CURDATE()) > 10, DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL 10 DAY))), (1106, 1, IF(MONTH(CURDATE()) = 12 AND DAY(CURDATE()) > 10, DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL 10 DAY))), (1106, 1, IF(MONTH(CURDATE()) = 12 AND DAY(CURDATE()) > 10, DATE_ADD(CURDATE(), INTERVAL -11 DAY), DATE_ADD(CURDATE(), INTERVAL 11 DAY))), (1106, 1, IF(MONTH(CURDATE()) = 12 AND DAY(CURDATE()) > 10, DATE_ADD(CURDATE(), INTERVAL -12 DAY), DATE_ADD(CURDATE(), INTERVAL 12 DAY))), diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e42c13c72..a54d2169f 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -193,6 +193,7 @@ "Client assignment has changed": "He cambiado el comercial ~*\"<{{previousWorkerName}}>\"*~ por *\"<{{currentWorkerName}}>\"* del cliente [{{clientName}} ({{clientId}})]({{{url}}})", "None": "Ninguno", "The contract was not active during the selected date": "El contrato no estaba activo durante la fecha seleccionada", + "Cannot add more than one '1/2 day vacation'": "No puedes añadir más de un 'Vacaciones 1/2 dia'", "This document already exists on this ticket": "Este documento ya existe en el ticket", "Some of the selected tickets are not billable": "Algunos de los tickets seleccionados no son facturables", "You can't invoice tickets from multiple clients": "No puedes facturar tickets de multiples clientes", 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; + } + }); }); diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index b276cf1f7..89830197d 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -65,6 +65,23 @@ module.exports = Self => { if (args.dated < labour.started || (labour.ended != null && args.dated > labour.ended)) throw new UserError(`The contract was not active during the selected date`); + const result = await Self.rawSql( + `SELECT COUNT(*) halfHolidayCounter + FROM vn.calendar c + JOIN postgresql.business b ON b.business_id = c.businessFk + JOIN postgresql.profile p ON p.profile_id = b.client_id + JOIN vn.person pe ON pe.id = p.person_id + WHERE c.dayOffTypeFk = 6 + AND pe.workerFk = ? + AND c.dated BETWEEN util.firstDayOfYear(CURDATE()) + AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [args.id]); + + const hasHalfHoliday = result[0].halfHolidayCounter > 0; + const isHalfHoliday = args.absenceTypeId == 6; + + if (isHalfHoliday && hasHalfHoliday) + throw new UserError(`Cannot add more than one '1/2 day vacation'`); + const absence = await models.Calendar.create({ businessFk: labour.businessFk, dayOffTypeFk: args.absenceTypeId, diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index f2c00e804..0d6ebfc80 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -74,4 +74,32 @@ describe('Worker createAbsence()', () => { throw e; } }); + + it(`should throw an error when adding a "Half holiday" absence if there's already one`, async() => { + const ctx = { + req: {accessToken: {userId: 19}}, + args: { + id: 1, + businessFk: 1, + absenceTypeId: 6, + dated: new Date() + } + }; + + const tx = await app.models.Calendar.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await app.models.Worker.createAbsence(ctx, workerId, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`); + }); });