3338-worker_calendar #787
|
@ -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`)
|
INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id`, `date`)
|
||||||
VALUES
|
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 -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 -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))),
|
(1106, 1, IF(MONTH(CURDATE()) = 12 AND DAY(CURDATE()) > 10, DATE_ADD(CURDATE(), INTERVAL -12 DAY), DATE_ADD(CURDATE(), INTERVAL 12 DAY))),
|
||||||
|
|
|
@ -193,6 +193,7 @@
|
||||||
"Client assignment has changed": "He cambiado el comercial ~*\"<{{previousWorkerName}}>\"*~ por *\"<{{currentWorkerName}}>\"* del cliente [{{clientName}} ({{clientId}})]({{{url}}})",
|
"Client assignment has changed": "He cambiado el comercial ~*\"<{{previousWorkerName}}>\"*~ por *\"<{{currentWorkerName}}>\"* del cliente [{{clientName}} ({{clientId}})]({{{url}}})",
|
||||||
"None": "Ninguno",
|
"None": "Ninguno",
|
||||||
"The contract was not active during the selected date": "El contrato no estaba activo durante la fecha seleccionada",
|
"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",
|
"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",
|
"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",
|
"You can't invoice tickets from multiple clients": "No puedes facturar tickets de multiples clientes",
|
||||||
|
|
|
@ -65,6 +65,23 @@ module.exports = Self => {
|
||||||
if (args.dated < labour.started || (labour.ended != null && args.dated > labour.ended))
|
if (args.dated < labour.started || (labour.ended != null && args.dated > labour.ended))
|
||||||
throw new UserError(`The contract was not active during the selected date`);
|
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({
|
const absence = await models.Calendar.create({
|
||||||
businessFk: labour.businessFk,
|
businessFk: labour.businessFk,
|
||||||
dayOffTypeFk: args.absenceTypeId,
|
dayOffTypeFk: args.absenceTypeId,
|
||||||
|
|
|
@ -74,4 +74,32 @@ describe('Worker createAbsence()', () => {
|
||||||
throw e;
|
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;
|
||||||
|
}
|
||||||
carlosjr marked this conversation as resolved
|
|||||||
|
|
||||||
|
expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
this line of code is not needed if the error definition is at the level of the test error handler