From 7efb19ab8373bad4b5ebf8b00cb5b62f93d54e56 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 15 Nov 2021 14:49:14 +0100 Subject: [PATCH] =?UTF-8?q?feat(worker=5Fcalendar):=20add=20restriction=20?= =?UTF-8?q?to=20choose=20"Vacaciones=201/2=20d=C3=ADa"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loopback/locale/es.json | 1 + modules/worker/back/methods/worker/createAbsence.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index afa349684..f7377300a 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/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 549ba7fd1..3045a3169 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -65,6 +65,14 @@ 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`); + let result = await Self.rawSql( + `SELECT COUNT(*) halfDayHolidayCounter + FROM vn.calendar c + WHERE c.dayOffTypeFk = 6 AND c.businessFk = ?`, [args.businessFk]); + + if (args.absenceTypeId == 6 && result[0].halfDayHolidayCounter > 0) + throw new UserError(`Cannot add more than one '1/2 day vacation'`); + const absence = await models.Calendar.create({ businessFk: labour.businessFk, dayOffTypeFk: args.absenceTypeId,