From 7efb19ab8373bad4b5ebf8b00cb5b62f93d54e56 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 15 Nov 2021 14:49:14 +0100 Subject: [PATCH 1/6] =?UTF-8?q?feat(worker=5Fcalendar):=20add=20restrictio?= =?UTF-8?q?n=20to=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, From 180fb95a0004dd360c8af130f93e30a39b8d3370 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 16 Nov 2021 10:09:42 +0100 Subject: [PATCH 2/6] feat(createAbsence): add backTest --- db/dump/fixtures.sql | 1 + .../back/methods/worker/createAbsence.js | 9 ++++-- .../worker/specs/createAbsence.spec.js | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 49ff08db9..745a2ee07 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -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`) 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 -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))), diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 3045a3169..217191a30 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -65,12 +65,15 @@ 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 + const result = await Self.rawSql( + `SELECT COUNT(*) halfHolidayCounter FROM vn.calendar c WHERE c.dayOffTypeFk = 6 AND c.businessFk = ?`, [args.businessFk]); - if (args.absenceTypeId == 6 && result[0].halfDayHolidayCounter > 0) + 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({ diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index f2c00e804..e5387c379 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -74,4 +74,35 @@ describe('Worker createAbsence()', () => { throw e; } }); + + it('should return an error trying to create a "Half holiday" absence', async() => { + const ctx = { + req: {accessToken: {userId: 19}}, + args: { + businessFk: 1, + absenceTypeId: 6, + dated: new Date() + } + }; + + const tx = await app.models.Calendar.beginTransaction({}); + + try { + const options = {transaction: tx}; + + let error; + await app.models.Worker.createAbsence(ctx, workerId, options).catch(e => { + error = e; + }).finally(() => { + expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`); + }); + + expect(error).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 651a9257085c0970087f541114d5a1634a24c0b5 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 17 Nov 2021 14:20:26 +0100 Subject: [PATCH 3/6] feat(worker_calendar): only can choose one halfHoliday by year --- modules/worker/back/methods/worker/createAbsence.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 217191a30..ba13a8a10 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -68,7 +68,13 @@ module.exports = Self => { const result = await Self.rawSql( `SELECT COUNT(*) halfHolidayCounter FROM vn.calendar c - WHERE c.dayOffTypeFk = 6 AND c.businessFk = ?`, [args.businessFk]); + 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; From 00a33fabb39775176addec37f82a5815a2305051 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 17 Nov 2021 14:38:12 +0100 Subject: [PATCH 4/6] update backTest --- modules/worker/back/methods/worker/specs/createAbsence.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index e5387c379..03467347a 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -79,6 +79,7 @@ describe('Worker createAbsence()', () => { const ctx = { req: {accessToken: {userId: 19}}, args: { + id: 1, businessFk: 1, absenceTypeId: 6, dated: new Date() From ac9ed90f4a7c8f21470fb903ea6a0e0a2b584770 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 19 Nov 2021 10:02:40 +0100 Subject: [PATCH 5/6] feat(item): modify item_getBalance and do test --- .../10390-constitution/00-item_getBalance.sql | 7 ++-- modules/item/back/methods/item/filter.js | 3 +- .../methods/item/specs/getBalance.spec.js | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/db/changes/10390-constitution/00-item_getBalance.sql b/db/changes/10390-constitution/00-item_getBalance.sql index 90e3ee2bb..54f612eae 100644 --- a/db/changes/10390-constitution/00-item_getBalance.sql +++ b/db/changes/10390-constitution/00-item_getBalance.sql @@ -2,8 +2,7 @@ DROP PROCEDURE IF EXISTS `vn`.`item_getBalance`; DELIMITER $$ $$ -CREATE - definer = root@`%` procedure `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int) +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int) BEGIN DECLARE vDateInventory DATETIME; DECLARE vCurdate DATE DEFAULT CURDATE(); @@ -116,7 +115,7 @@ BEGIN s.id, st.`order`, ct.code, - cl.id + cb.claimFk FROM sale s JOIN ticket t ON t.id = s.ticketFk LEFT JOIN ticketState ts ON ts.ticket = t.id @@ -132,6 +131,7 @@ BEGIN LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id LEFT JOIN claim cl ON cl.ticketFk = t.id + LEFT JOIN claimBeginning cb ON cl.id = cb.claimFk AND s.id = cb.saleFk WHERE t.shipped >= vDateInventory AND s.itemFk = vItemId AND vWarehouse =t.warehouseFk @@ -141,4 +141,3 @@ BEGIN END; $$ DELIMITER ; - diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 29099c7ec..810cf4071 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -112,8 +112,7 @@ module.exports = Self => { case 'isActive': case 'typeFk': case 'isFloramondo': - param = `i.${param}`; - return {[param]: value}; + return {[`i.${param}`]: value}; case 'multiplier': return {'i.stemMultiplier': value}; case 'categoryFk': diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index 5143a346f..779516b19 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -36,4 +36,36 @@ describe('item getBalance()', () => { throw e; } }); + + it('should show the claimFk only on the claimed item', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const firstFilter = { + where: { + itemFk: 1, + warehouseFk: 1 + } + }; + + const secondFilter = { + where: { + itemFk: 2, + warehouseFk: 1 + } + }; + + const firstItemBalance = await models.Item.getBalance(firstFilter, options); + const secondItemBalance = await models.Item.getBalance(secondFilter, options); + + expect(firstItemBalance[9].claimFk).toEqual(null); + expect(secondItemBalance[5].claimFk).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From cdf7c20b163132a0942758999cd3ca50f2a7818a Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 22 Nov 2021 13:34:42 +0100 Subject: [PATCH 6/6] feat(worker_createAbsense): update backTest --- .../methods/worker/specs/createAbsence.spec.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index 03467347a..0d6ebfc80 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -75,7 +75,7 @@ describe('Worker createAbsence()', () => { } }); - it('should return an error trying to create a "Half holiday" absence', async() => { + it(`should throw an error when adding a "Half holiday" absence if there's already one`, async() => { const ctx = { req: {accessToken: {userId: 19}}, args: { @@ -88,22 +88,18 @@ describe('Worker createAbsence()', () => { const tx = await app.models.Calendar.beginTransaction({}); + let error; try { const options = {transaction: tx}; - let error; - await app.models.Worker.createAbsence(ctx, workerId, options).catch(e => { - error = e; - }).finally(() => { - expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`); - }); - - expect(error).toBeDefined(); + await app.models.Worker.createAbsence(ctx, workerId, options); await tx.rollback(); } catch (e) { await tx.rollback(); - throw e; + error = e; } + + expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`); }); });