refs #6882 absence #2271

Merged
carlossa merged 13 commits from 6682-notHolidays into dev 2024-05-08 10:27:21 +00:00
6 changed files with 65 additions and 4 deletions

View File

@ -0,0 +1,10 @@
-- Place your SQL code here
ALTER TABLE vn.absenceType ADD isFestiveEligible BOOL DEFAULT 1 NOT NULL COMMENT 'Para marcar un tipo de absence';
carlossa marked this conversation as resolved Outdated
Outdated
Review

No me acaba el nom

No me acaba el nom
UPDATE vn.absenceType
SET isFestiveEligible = 0
WHERE code = 'holiday';
carlossa marked this conversation as resolved Outdated
Outdated
Review

ficant el code se veu mes visual

ficant el code se veu mes visual
UPDATE vn.absenceType
SET isFestiveEligible=0
WHERE code = 'halfHoliday';

View File

@ -226,4 +226,4 @@
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
"They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked"
}
}

View File

@ -10,6 +10,9 @@
"id": {
"type": "number",
"id": true
},
"workcenterFk" : {
"type": "number"
}
},
"relations": {
@ -24,4 +27,4 @@
"foreignKey": "departmentFk"
}
}
}
}

View File

@ -98,6 +98,22 @@ module.exports = Self => {
if (isHalfHoliday && hasHalfHoliday)
throw new UserError(`Cannot add more than one '1/2 day vacation'`);
const isFestive = absenceType.isFestiveEligible;
const workCenter = await models.Business.findOne({
where: {id: args.businessFk}
carlossa marked this conversation as resolved
Review

es lo mateix q fer const holiday = ... .findOne no?

es lo mateix q fer `const holiday = ... .findOne` no?
},);
const [holiday] = await models.CalendarHoliday.find({
where: {
dated: args.dated,
workCenterFk: workCenter.workCenterFk
}
});
carlossa marked this conversation as resolved Outdated
Outdated
Review

if (isHalfHoliday && (hasHalfHoliday || isFestive))

if (isHalfHoliday && (hasHalfHoliday || isFestive))
carlossa marked this conversation as resolved Outdated
Outdated
Review

El error este el posaria de lo primer (aixina no cal fer peticions) i sobra el isFestive

El error este el posaria de lo primer (aixina no cal fer peticions) i sobra el isFestive
if (holiday && isFestive)
throw new UserError(`Cannot add holidays on this day`);
const absence = await models.Calendar.create({
businessFk: labour.businessFk,
dayOffTypeFk: args.absenceTypeId,

View File

@ -104,6 +104,35 @@ describe('Worker createAbsence()', () => {
expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`);
});
it(`should throw an error when adding a "Holiday" absence if there's a festivity`, async() => {
const ctx = {
req: {accessToken: {userId: 9}},
args: {
id: 3,
businessFk: 3,
absenceTypeId: 1,
dated: '2001-12-08T23:00:00.000Z'
}
};
const workerId = 1;
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 holidays on this day`);
});
it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => {
const ctx = {
req: {accessToken: {userId: 19}},

View File

@ -22,7 +22,10 @@
},
"holidayEntitlementRate": {
"type": "number"
}
},
"isFestiveEligible": {
"type": "boolean"
}
},
"acls": [
{
@ -32,4 +35,4 @@
"permission": "ALLOW"
}
]
}
}