Merge pull request 'fix: hotfix 7323 createAbsence' (!3265) from hotfix-7323workerHoliday into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3265
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Carlos Satorres 2024-12-09 12:28:52 +00:00
commit d1bf0195f0
5 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,2 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Worker','canCreateAbsenceInPast','WRITE','ALLOW','ROLE','hr');

View File

@ -246,5 +246,5 @@
"Payment method is required": "Payment method is required", "Payment method is required": "Payment method is required",
"The raid information is not correct": "The raid information is not correct", "The raid information is not correct": "The raid information is not correct",
"Sales already moved": "Sales already moved", "Sales already moved": "Sales already moved",
"There are tickets to be invoiced": "There are tickets to be invoiced for this zone, please delete them first" "Holidays to past days not available": "Holidays to past days not available"
} }

View File

@ -389,5 +389,5 @@
"The web user's email already exists": "El correo del usuario web ya existe", "The web user's email already exists": "El correo del usuario web ya existe",
"Sales already moved": "Ya han sido transferidas", "Sales already moved": "Ya han sido transferidas",
"The raid information is not correct": "La información de la redada no es correcta", "The raid information is not correct": "La información de la redada no es correcta",
"There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero" "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles"
} }

View File

@ -58,6 +58,7 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
throw new UserError(`You don't have enough privileges`); throw new UserError(`You don't have enough privileges`);
const canCreateAbsenceInPast = await models.ACL.checkAccessAcl(ctx, 'Worker', 'canCreateAbsenceInPast', 'WRITE');
const labour = await models.WorkerLabour.findById(args.businessFk, { const labour = await models.WorkerLabour.findById(args.businessFk, {
include: {relation: 'department'} include: {relation: 'department'}
}, myOptions); }, myOptions);
@ -113,6 +114,11 @@ module.exports = Self => {
if ((holiday && isFestive) && (workCenter.workcenterFk === holiday.workCenterFk)) if ((holiday && isFestive) && (workCenter.workcenterFk === holiday.workCenterFk))
throw new UserError(`Cannot add holidays on this day`); throw new UserError(`Cannot add holidays on this day`);
const newDate = new Date(args.dated).getTime();
const nowDate = now.getTime();
if ((nowDate > newDate) && !canCreateAbsenceInPast)
throw new UserError(`Holidays to past days not available`);
const absence = await models.Calendar.create({ const absence = await models.Calendar.create({
businessFk: labour.businessFk, businessFk: labour.businessFk,
dayOffTypeFk: args.absenceTypeId, dayOffTypeFk: args.absenceTypeId,

View File

@ -162,4 +162,33 @@ describe('Worker createAbsence()', () => {
expect(error.message).toEqual(`The worker has hours recorded that day`); expect(error.message).toEqual(`The worker has hours recorded that day`);
}); });
it(`Should throw an error when adding a "Vacation" absence on a past day`, async() => {
const ctx = {
req: {accessToken: {userId: 19}},
args: {
id: 1110,
businessFk: 1110,
absenceTypeId: 1,
dated: '2000-12-27T23:00:00.000Z',
}
};
const workerId = 19;
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(`Holidays to past days not available`);
});
}); });