From 84997eacd5b42f923a4395dcc5bba9bce47c16ab Mon Sep 17 00:00:00 2001 From: jcasado Date: Mon, 8 Apr 2024 14:38:54 +0200 Subject: [PATCH 1/7] refs: 6697 remove claim quantity --- modules/claim/back/methods/claim/createFromSales.js | 2 +- modules/claim/back/models/claim-beginning.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index 30093e43d8..e5022d57e6 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -83,7 +83,7 @@ module.exports = Self => { const newClaimBeginning = models.ClaimBeginning.create({ saleFk: sale.id, claimFk: newClaim.id, - quantity: sale.quantity + }, myOptions); promises.push(newClaimBeginning); diff --git a/modules/claim/back/models/claim-beginning.json b/modules/claim/back/models/claim-beginning.json index d224586da4..ba6e838081 100644 --- a/modules/claim/back/models/claim-beginning.json +++ b/modules/claim/back/models/claim-beginning.json @@ -16,8 +16,7 @@ "description": "Identifier" }, "quantity": { - "type": "number", - "required": true + "type": "number" } }, "relations": { From d1659ce04c87ffb7bb531c07de854fd19cd7cf84 Mon Sep 17 00:00:00 2001 From: jcasado Date: Wed, 24 Apr 2024 11:19:15 +0200 Subject: [PATCH 2/7] refs #6697 fix claimQuantity --- modules/claim/back/methods/claim/createFromSales.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index e5022d57e6..1af479dbb5 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -83,7 +83,6 @@ module.exports = Self => { const newClaimBeginning = models.ClaimBeginning.create({ saleFk: sale.id, claimFk: newClaim.id, - }, myOptions); promises.push(newClaimBeginning); From aeee012c2b353608afc45e495a0d0ed5bcbb6ee1 Mon Sep 17 00:00:00 2001 From: jcasado Date: Wed, 24 Apr 2024 11:43:10 +0200 Subject: [PATCH 3/7] refs #6697 fix sql test --- db/versions/11014-orangePalmetto/00-firstScript.sql | 2 ++ .../claim/back/methods/claim/specs/createFromSales.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 db/versions/11014-orangePalmetto/00-firstScript.sql diff --git a/db/versions/11014-orangePalmetto/00-firstScript.sql b/db/versions/11014-orangePalmetto/00-firstScript.sql new file mode 100644 index 0000000000..fe85c7ec68 --- /dev/null +++ b/db/versions/11014-orangePalmetto/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.claimBeginning MODIFY COLUMN quantity double DEFAULT 0 NULL; diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index fe009c1c3e..25414d1db7 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -37,7 +37,7 @@ describe('Claim createFromSales()', () => { let claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options); expect(claimBeginning.saleFk).toEqual(newSale[0].id); - expect(claimBeginning.quantity).toEqual(newSale[0].quantity); + expect(claimBeginning.quantity).toEqual(0); await tx.rollback(); } catch (e) { @@ -67,7 +67,7 @@ describe('Claim createFromSales()', () => { const claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options); expect(claimBeginning.saleFk).toEqual(newSale[0].id); - expect(claimBeginning.quantity).toEqual(newSale[0].quantity); + expect(claimBeginning.quantity).toEqual(0); await tx.rollback(); } catch (e) { From 88b06ebef546f5fd07faee2fab49bebc9f9fd0fa Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 08:49:22 +0200 Subject: [PATCH 4/7] feat: refs #7211 check if there's available clockIn --- db/routines/vn/procedures/workerTimeControl_clockIn.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index e585284871..a3991913ec 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -121,15 +121,17 @@ BEGIN CALL util.throw(vErrorCode); END IF; + -- DIRECCION CORRECTA CALL workerTimeControl_direction(vWorkerFk, vTimed); IF (SELECT - IF(IF(option1 IN ('inMiddle', 'outMiddle'), + IF((IF(option1 IN ('inMiddle', 'outMiddle'), 'middle', option1) <> vDirection AND IF(option2 IN ('inMiddle', 'outMiddle'), 'middle', - IFNULL(option2, '')) <> vDirection, + IFNULL(option2, '')) <> vDirection) + OR (option1 IS NULL AND option2 IS NULL), TRUE , FALSE) FROM tmp.workerTimeControlDirection From c9dfccbc53abcf84ae1a692e6f9242a1f32a94a2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 09:35:53 +0200 Subject: [PATCH 5/7] feat: refs #7211 add test & changelog --- CHANGELOG.md | 3 +++ .../worker-time-control/specs/clockIn.spec.js | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b938797e7..5aaa571921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [24.20.01] - 2024-05-14 +### Fixed +- (Worker -> time-control) Corrección de errores + ## [24.18.01] - 2024-05-07 ## [24.16.01] - 2024-04-18 diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 343eb2a716..826ea60778 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -1,5 +1,6 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); +const { async } = require('regenerator-runtime'); describe('workerTimeControl clockIn()', () => { const workerId = 9; @@ -99,6 +100,32 @@ describe('workerTimeControl clockIn()', () => { } }); + it('should throw an error trying to add an "in" entry if the last clockIn is not out', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + ctx.args = {timed: "2000-12-25T21:00:00.000Z", direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-25T22:00:00.000Z", direction: 'middle'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-25T22:30:00.000Z", direction: 'middle'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-26T01:00:00.000Z", direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + await tx.rollback(); + } catch (e) { + expect(e.message).toBe('Dirección incorrecta'); + await tx.rollback(); + } + }); + describe('as Role errors', () => { it('should add if the current user is team boss and the target user is himself', async() => { activeCtx.accessToken.userId = teamBossId; From f7cdbd39f08e2119f110ae66f4ec34bc9d752568 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 16:08:52 +0200 Subject: [PATCH 6/7] fix: refs #7211 tests --- .../procedures/workerTimeControl_clockIn.sql | 9 +++++-- .../worker-time-control/specs/clockIn.spec.js | 26 ------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index a3991913ec..a1ce53bc2e 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -139,12 +139,17 @@ BEGIN SET vIsError = TRUE; END IF; - DROP TEMPORARY TABLE tmp.workerTimeControlDirection; + IF vIsError THEN SET vErrorCode = 'WRONG_DIRECTION'; + IF(SELECT option1 IS NULL AND option2 IS NULL + FROM tmp.workerTimeControlDirection) THEN + + SET vErrorCode = 'DAY_MAX_TIME'; + END IF; CALL util.throw(vErrorCode); END IF; - + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; -- FICHADAS IMPARES SELECT timed INTO vLastIn FROM workerTimeControl diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 826ea60778..cfff42172c 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -1,6 +1,5 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -const { async } = require('regenerator-runtime'); describe('workerTimeControl clockIn()', () => { const workerId = 9; @@ -47,31 +46,6 @@ describe('workerTimeControl clockIn()', () => { } }); - it('should throw an error trying to change a middle hour to out not resting 12h', async() => { - activeCtx.accessToken.userId = HHRRId; - const workerId = teamBossId; - - const tx = await models.WorkerTimeControl.beginTransaction({}); - try { - const options = {transaction: tx}; - - const entryTime = "2000-12-25T11:00:00.000Z"; - ctx.args = {timed: entryTime, direction: 'in'}; - await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); - - const middleTime ="2000-12-26T11:00:00.000Z"; - ctx.args = {timed: middleTime, direction: 'middle'}; - const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); - - const direction = 'out'; - await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); - await tx.rollback(); - } catch (e) { - expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida'); - await tx.rollback(); - } - }); - it('should updates the time entry direction and remaining not be manual', async() => { activeCtx.accessToken.userId = HHRRId; const workerId = teamBossId; From 180a484c558195926366f51b145aa759309bd0d9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 16:14:34 +0200 Subject: [PATCH 7/7] fix: refs #7211 rollback --- .../worker-time-control/specs/clockIn.spec.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index cfff42172c..daf7284ac0 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -45,6 +45,31 @@ describe('workerTimeControl clockIn()', () => { throw e; } }); + + it('should throw an error trying to change a middle hour to out not resting 12h', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + const entryTime = "2000-12-25T11:00:00.000Z"; + ctx.args = {timed: entryTime, direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const middleTime ="2000-12-26T11:00:00.000Z"; + ctx.args = {timed: middleTime, direction: 'middle'}; + const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const direction = 'out'; + await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); + await tx.rollback(); + } catch (e) { + expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida'); + await tx.rollback(); + } + }); it('should updates the time entry direction and remaining not be manual', async() => { activeCtx.accessToken.userId = HHRRId;