From 97b07ea561e1456ea1480785c2328e58dbb1743d Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 9 Sep 2024 13:56:30 +0200 Subject: [PATCH 1/9] fix: refs #7356 ticket weekly filter --- modules/ticket/back/methods/ticket-weekly/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index a43b5e270..d988f0c10 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -66,7 +66,7 @@ module.exports = Self => { FROM ticketWeekly tw JOIN ticket t ON t.id = tw.ticketFk JOIN client c ON c.id = t.clientFk - JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN account.user u ON u.id = c.salesPersonFk JOIN warehouse wh ON wh.id = t.warehouseFk LEFT JOIN agencyMode am ON am.id = tw.agencyModeFk` ); From b642147d82a25aa3823041300c70a9f491a5deb5 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 19 Sep 2024 13:14:22 +0200 Subject: [PATCH 2/9] feat: refs #7356 added new filter field --- modules/ticket/back/methods/ticket/filter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 2209c8df4..c3eea4201 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -76,7 +76,8 @@ module.exports = Self => { { arg: 'myTeam', type: 'boolean', - description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)` + description: `Whether to show only tickets for the current logged user team + (For now it shows only the current user tickets)` }, { arg: 'problems', @@ -258,7 +259,8 @@ module.exports = Self => { MINUTE(z.hour) zoneMinute, z.name zoneName, z.id zoneFk, - CAST(z.hour AS CHAR) hour + CAST(z.hour AS CHAR) hour, + a.nickname addressNickname FROM ticket t LEFT JOIN invoiceOut io ON t.refFk = io.ref LEFT JOIN zone z ON z.id = t.zoneFk From 98f33807dd743868e41b1d99194c71feafb9916d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 24 Sep 2024 16:48:48 +0200 Subject: [PATCH 3/9] fix: updateAvailable refs #6861 --- .../vn/procedures/clearShelvingList.sql | 8 --- .../procedures/itemShelvingMakeFromDate.sql | 58 ------------------- .../itemShelvingPlacementSupplyAdd.sql | 20 ------- .../vn/procedures/itemShelvingSale_Add.sql | 3 +- .../itemShelving_selfConsumption.sql | 9 +-- .../vn/procedures/itemShelving_transfer.sql | 3 +- db/routines/vn/procedures/item_devalueA2.sql | 3 +- 7 files changed, 11 insertions(+), 93 deletions(-) delete mode 100644 db/routines/vn/procedures/clearShelvingList.sql delete mode 100644 db/routines/vn/procedures/itemShelvingMakeFromDate.sql delete mode 100644 db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql diff --git a/db/routines/vn/procedures/clearShelvingList.sql b/db/routines/vn/procedures/clearShelvingList.sql deleted file mode 100644 index 1ba726e85..000000000 --- a/db/routines/vn/procedures/clearShelvingList.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`clearShelvingList`(vShelvingFk VARCHAR(8)) -BEGIN - UPDATE vn.itemShelving - SET visible = 0 - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk COLLATE utf8_unicode_ci; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingMakeFromDate.sql b/db/routines/vn/procedures/itemShelvingMakeFromDate.sql deleted file mode 100644 index 4918d55e1..000000000 --- a/db/routines/vn/procedures/itemShelvingMakeFromDate.sql +++ /dev/null @@ -1,58 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22)) -BEGIN - - DECLARE vItemFk INT; - - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - SELECT itemFk INTO vItemFk - FROM vn.buy b - WHERE b.id = vItemFk; - - IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN - - INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk); - INSERT INTO vn.shelving(`code`, parkingFk) - SELECT vShelvingFk, id - FROM vn.parking - WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; - - END IF; - - IF (SELECT COUNT(*) FROM vn.itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN - - UPDATE vn.itemShelving - SET visible = visible+vQuantity, - created = vCreated - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking; - - ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - created, - `grouping`, - packing, - packagingFk) - SELECT vItemFk, - vShelvingFk, - vQuantity, - vCreated, - IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`, - IF(vPacking = 0, b.packing, vPacking) packing, - IF(vPackagingFk = '', b.packagingFk, vPackagingFk) packaging - FROM vn.item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql b/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql deleted file mode 100644 index 085a3fe4b..000000000 --- a/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT) -BEGIN - - INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk, - itemPlacementSupplyFk, - quantity, - userFk) - VALUES (vItemShelvingFk, - vItemPlacementSupplyFk, - vQuantity, - getUser()); - - UPDATE vn.itemShelving - SET visible = visible - vQuantity - WHERE id = vItemShelvingFk; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_Add.sql b/db/routines/vn/procedures/itemShelvingSale_Add.sql index 05b6b9d45..c00f25150 100644 --- a/db/routines/vn/procedures/itemShelvingSale_Add.sql +++ b/db/routines/vn/procedures/itemShelvingSale_Add.sql @@ -18,7 +18,8 @@ BEGIN getUser()); UPDATE itemShelving - SET visible = visible - vQuantity + SET visible = visible - vQuantity, + available = available - vQuantity WHERE id = vItemShelvingFk; UPDATE vn.saleTracking diff --git a/db/routines/vn/procedures/itemShelving_selfConsumption.sql b/db/routines/vn/procedures/itemShelving_selfConsumption.sql index 25ff2363c..083d8d74c 100644 --- a/db/routines/vn/procedures/itemShelving_selfConsumption.sql +++ b/db/routines/vn/procedures/itemShelving_selfConsumption.sql @@ -6,12 +6,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfCons ) BEGIN /** - * Leave the indicated amount on the shelf + * Leave the indicated amount on the shelve * and create a ticket with the difference. * - * @param vShelvingFk id of the shelf where the item is located. + * @param vShelvingFk id of the shelve where the item is located. * @param vItemFk article of which the self-consumption ticket is to be created. - * @param vQuantity amount that will stay on the shelf + * @param vQuantity amount that will stay on the shelve */ DECLARE vVisible INT; DECLARE vClientFk INT; @@ -80,7 +80,8 @@ BEGIN WHERE id = vItemFk; UPDATE itemShelving - SET visible = IF(id = vItemShelvingFk, vQuantity, 0) + SET visible = IF(id = vItemShelvingFk, vQuantity, 0), + available = IF(id = vItemShelvingFk, vQuantity, 0) WHERE shelvingFk = vShelvingFk AND itemFk = vItemFk; diff --git a/db/routines/vn/procedures/itemShelving_transfer.sql b/db/routines/vn/procedures/itemShelving_transfer.sql index 3597da7e1..95d70227f 100644 --- a/db/routines/vn/procedures/itemShelving_transfer.sql +++ b/db/routines/vn/procedures/itemShelving_transfer.sql @@ -31,7 +31,8 @@ BEGIN IF vNewItemShelvingFk THEN UPDATE itemShelving ish JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk - SET ish.visible = ish.visible + ish2.visible + SET ish.visible = ish.visible + ish2.visible, + ish.available = ish.available + ish2.available WHERE ish.id = vNewItemShelvingFk; DELETE FROM itemShelving diff --git a/db/routines/vn/procedures/item_devalueA2.sql b/db/routines/vn/procedures/item_devalueA2.sql index 44ae306ec..d0178f6a7 100644 --- a/db/routines/vn/procedures/item_devalueA2.sql +++ b/db/routines/vn/procedures/item_devalueA2.sql @@ -303,7 +303,8 @@ BEGIN WHERE id = vTargetItemShelvingFk; ELSE UPDATE itemShelving - SET visible = vCurrentVisible - vQuantity + SET visible = vCurrentVisible - vQuantity, + available = GREATEST(0, available - vQuantity) WHERE id = vTargetItemShelvingFk; END IF; From b7767887141c4e3f63a1f5bce42fd1288914f07d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 25 Sep 2024 08:35:15 +0200 Subject: [PATCH 4/9] feat: refs #7855 delete isChecked --- db/versions/11264-turquoisePaniculata/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11264-turquoisePaniculata/00-firstScript.sql diff --git a/db/versions/11264-turquoisePaniculata/00-firstScript.sql b/db/versions/11264-turquoisePaniculata/00-firstScript.sql new file mode 100644 index 000000000..9115e1460 --- /dev/null +++ b/db/versions/11264-turquoisePaniculata/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here + +ALTER TABLE dipole.expedition_PrintOut DROP COLUMN IF EXISTS isChecked; From eb85181ea06d9fe8d5052c73cb7f7c9d17c9c2a8 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 25 Sep 2024 08:43:38 +0200 Subject: [PATCH 5/9] feat: refs #7855 delete isChecked --- db/versions/11264-turquoisePaniculata/00-firstScript.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/versions/11264-turquoisePaniculata/00-firstScript.sql b/db/versions/11264-turquoisePaniculata/00-firstScript.sql index 9115e1460..8ca3df265 100644 --- a/db/versions/11264-turquoisePaniculata/00-firstScript.sql +++ b/db/versions/11264-turquoisePaniculata/00-firstScript.sql @@ -1,3 +1 @@ --- Place your SQL code here - ALTER TABLE dipole.expedition_PrintOut DROP COLUMN IF EXISTS isChecked; From aadce7971b60ebbd6b8480a4c921480a3183ff62 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 25 Sep 2024 12:06:50 +0200 Subject: [PATCH 6/9] fix: translation --- loopback/locale/es.json | 4 ++-- loopback/locale/pt.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8b443d96b..b9933f596 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -366,11 +366,11 @@ "The invoices have been created but the PDFs could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", - "Cannot send mail": "Não é possível enviar o email", + "Cannot send mail": "No se pudo enviar el correo", "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", "The sale not exists in the item shelving": "La venta no existe en la estantería del artículo", "The entry not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", "Original invoice not found": "Factura original no encontrada", "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe" -} \ No newline at end of file +} diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index 6425db9ed..a6a65710f 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -360,6 +360,6 @@ "It was not able to create the invoice": "Não foi possível criar a fatura", "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", - "Original invoice not found": "Fatura original não encontrada" - + "Original invoice not found": "Fatura original não encontrada", + "Cannot send mail": "Não é possível enviar o email" } From 9ef44d8d8df07e368c8dfc8c6f48186dd1385146 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 25 Sep 2024 13:23:31 +0200 Subject: [PATCH 7/9] feat: refs #6722 refactor createThermograph --- back/methods/dms/updateFile.js | 2 +- db/dump/fixtures.before.sql | 15 +- .../00-thermographTemperature.sql | 3 + .../11254-tealCarnation/01-thermographFk.sql | 2 + loopback/locale/es.json | 3 +- .../methods/thermograph/createThermograph.js | 12 +- .../specs/createThermograph.spec.js | 53 ++++--- .../back/methods/travel/createThermograph.js | 103 -------------- .../back/methods/travel/saveThermograph.js | 131 ++++++++++++++++++ .../travel/specs/createThermograph.spec.js | 51 ------- .../travel/specs/saveThermograph.spec.js | 69 +++++++++ .../back/methods/travel/updateThermograph.js | 83 ----------- .../back/models/travel-thermograph.json | 8 ++ modules/travel/back/models/travel.js | 3 +- .../travel/front/thermograph/create/index.js | 2 +- .../travel/front/thermograph/edit/index.js | 8 +- .../front/thermograph/edit/index.spec.js | 2 +- 17 files changed, 262 insertions(+), 288 deletions(-) create mode 100644 db/versions/11254-tealCarnation/00-thermographTemperature.sql create mode 100644 db/versions/11254-tealCarnation/01-thermographFk.sql delete mode 100644 modules/travel/back/methods/travel/createThermograph.js create mode 100644 modules/travel/back/methods/travel/saveThermograph.js delete mode 100644 modules/travel/back/methods/travel/specs/createThermograph.spec.js create mode 100644 modules/travel/back/methods/travel/specs/saveThermograph.spec.js delete mode 100644 modules/travel/back/methods/travel/updateThermograph.js diff --git a/back/methods/dms/updateFile.js b/back/methods/dms/updateFile.js index cfc4c322f..68149ef62 100644 --- a/back/methods/dms/updateFile.js +++ b/back/methods/dms/updateFile.js @@ -38,7 +38,7 @@ module.exports = Self => { { arg: 'hasFile', type: 'Boolean', - description: 'True if has an attached file' + description: 'True if has the original in paper' }, { arg: 'hasFileAttached', diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 514a94506..7aed7013f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2522,14 +2522,15 @@ INSERT INTO `vn`.`thermograph`(`id`, `model`) ('138350-0', 'DISPOSABLE'); -INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`) +INSERT INTO `vn`.`travelThermograph` + (`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `minTemperature`, `maxTemperature`, `result`, `dmsFk`) VALUES - ('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', 'Ok', NULL), - ('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL), - ('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL), - ('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5), - ('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5), - ('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL); + ('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Ok', NULL), + ('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', NULL, NULL, 'Ok', NULL), + ('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', NULL, NULL, 'can not read the temperature', NULL), + ('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Temperature in range', 5), + ('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', 2, 12, NULL, 5), + ('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL, NULL, NULL); REPLACE INTO `vn`.`incoterms`(`code`, `name`) VALUES diff --git a/db/versions/11254-tealCarnation/00-thermographTemperature.sql b/db/versions/11254-tealCarnation/00-thermographTemperature.sql new file mode 100644 index 000000000..123e6c665 --- /dev/null +++ b/db/versions/11254-tealCarnation/00-thermographTemperature.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`travelThermograph` +ADD COLUMN `maxTemperature` DECIMAL(5,2) NULL AFTER `temperatureFk`, +ADD COLUMN `minTemperature` DECIMAL(5,2) NULL AFTER `maxTemperature`; diff --git a/db/versions/11254-tealCarnation/01-thermographFk.sql b/db/versions/11254-tealCarnation/01-thermographFk.sql new file mode 100644 index 000000000..2baf99a45 --- /dev/null +++ b/db/versions/11254-tealCarnation/01-thermographFk.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`travelThermograph` DROP FOREIGN KEY travelThermographDmsFgn; +ALTER TABLE `vn`.`travelThermograph` ADD CONSTRAINT travelThermographDmsFgn FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 49c44a4d8..965b0c457 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -378,5 +378,6 @@ "The maximum height of the wagon is 200cm": "La altura máxima es 200cm", "The entry does not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", - "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha" + "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", + "No valid travel thermograph found": "No valid travel thermograph found" } \ No newline at end of file diff --git a/modules/travel/back/methods/thermograph/createThermograph.js b/modules/travel/back/methods/thermograph/createThermograph.js index 243e2129f..2c47bbf0e 100644 --- a/modules/travel/back/methods/thermograph/createThermograph.js +++ b/modules/travel/back/methods/thermograph/createThermograph.js @@ -56,14 +56,16 @@ module.exports = Self => { model: model }, myOptions); - await Self.rawSql(` - INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created) - VALUES (?, ?, ?, ?) - `, [thermograph.id, warehouseId, temperatureFk, date], myOptions); + const travelThermograph = await models.TravelThermograph.create({ + thermographFk: thermograph.id, + warehouseFk: warehouseId, + temperatureFk: temperatureFk, + created: date + }, myOptions); if (tx) await tx.commit(); - return thermograph; + return travelThermograph; } catch (err) { if (tx) await tx.rollback(); throw err; diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index 71b9fcccb..f9b2a19f9 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -6,47 +6,42 @@ describe('Termograph createThermograph()', () => { const temperatureFk = 'COOL'; const warehouseId = 1; const ctx = beforeAll.getCtx(); + let tx; + + beforeEach(async() => { + tx = await models.Thermograph.beginTransaction({}); + }); + + afterEach(async() => { + await tx.rollback(); + }); it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { - const tx = await models.Thermograph.beginTransaction({}); + const options = {transaction: tx}; - try { - const options = {transaction: tx}; + const createdThermograph = await models.Thermograph.createThermograph( + ctx, thermographId, model, temperatureFk, warehouseId, options); - const createdThermograph = await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); + expect(createdThermograph.thermographFk).toEqual(thermographId); - expect(createdThermograph.id).toEqual(thermographId); - expect(createdThermograph.model).toEqual(model); + const createdTravelThermograph = + await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options); - const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options); - - expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId); - expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(createdTravelThermograph.warehouseFk).toEqual(warehouseId); + expect(createdTravelThermograph.temperatureFk).toEqual(temperatureFk); }); - it(`should throw an error when trying to created repeated thermograph`, async() => { - const tx = await models.Thermograph.beginTransaction({}); - - let error; - + it(`should throw an error when trying to create a repeated thermograph`, async() => { try { const options = {transaction: tx}; - await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); - await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); - - await tx.rollback(); + await models.Thermograph.createThermograph( + ctx, thermographId, model, temperatureFk, warehouseId, options); + await models.Thermograph.createThermograph( + ctx, thermographId, model, temperatureFk, warehouseId, options); + fail('Expected an error to be thrown when trying to create a repeated thermograph'); } catch (e) { - await tx.rollback(); - error = e; + expect(e.message).toBe('This thermograph id already exists'); } - - expect(error.message).toBe('This thermograph id already exists'); }); }); diff --git a/modules/travel/back/methods/travel/createThermograph.js b/modules/travel/back/methods/travel/createThermograph.js deleted file mode 100644 index aac3a22b9..000000000 --- a/modules/travel/back/methods/travel/createThermograph.js +++ /dev/null @@ -1,103 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('createThermograph', { - description: 'Creates a new travel thermograph', - accessType: 'WRITE', - accepts: [{ - arg: 'id', - type: 'number', - description: 'The travel id', - http: {source: 'path'} - }, - { - arg: 'thermographId', - type: 'string', - description: 'The thermograph id', - required: true - }, - { - arg: 'state', - type: 'string', - required: true - }, - { - arg: 'warehouseId', - type: 'number', - description: 'The warehouse id', - required: true - }, - { - arg: 'companyId', - type: 'number', - description: 'The company id', - required: true - }, - { - arg: 'dmsTypeId', - type: 'number', - description: 'The dms type id', - required: true - }, - { - arg: 'reference', - type: 'string', - required: true - }, - { - arg: 'description', - type: 'string', - required: true - }], - returns: { - type: 'object', - root: true - }, - http: { - path: `/:id/createThermograph`, - verb: 'POST' - } - }); - - Self.createThermograph = async(ctx, id, thermographId, state, options) => { - const models = Self.app.models; - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const travelThermograph = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: null - } - }, myOptions); - - if (!travelThermograph) - throw new UserError('No valid travel thermograph found'); - - const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - const firstDms = uploadedFiles[0]; - - await travelThermograph.updateAttributes({ - dmsFk: firstDms.id, - travelFk: id, - result: state - }, myOptions); - - if (tx) await tx.commit(); - - return travelThermograph; - } catch (err) { - if (tx) await tx.rollback(); - throw err; - } - }; -}; diff --git a/modules/travel/back/methods/travel/saveThermograph.js b/modules/travel/back/methods/travel/saveThermograph.js new file mode 100644 index 000000000..d246d8149 --- /dev/null +++ b/modules/travel/back/methods/travel/saveThermograph.js @@ -0,0 +1,131 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('saveThermograph', { + description: 'Creates or updates a travel thermograph', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + description: 'The travel id', + http: {source: 'path'} + }, + { + arg: 'travelThermographFk', + type: 'number', + description: 'The travel thermograph id', + required: true + }, + { + arg: 'state', + type: 'string', + required: true + }, + { + arg: 'maxTemperature', + type: 'number', + description: 'The maximum temperature' + }, + { + arg: 'minTemperature', + type: 'number', + description: 'The minimum temperature' + }, + { + arg: 'temperatureFk', + type: 'string', + description: 'Range of temperature' + }, { + arg: 'warehouseId', + type: 'Number', + description: 'The warehouse id' + }, { + arg: 'companyId', + type: 'Number', + description: 'The company id' + }, { + arg: 'dmsTypeId', + type: 'Number', + description: 'The dms type id' + }, { + arg: 'reference', + type: 'String' + }, { + arg: 'description', + type: 'String' + }, { + arg: 'hasFileAttached', + type: 'Boolean', + description: 'True if has an attached file' + }], + returns: {type: 'object', root: true}, + http: {path: `/:id/saveThermograph`, verb: 'POST'} + }); + + Self.saveThermograph = async( + ctx, + id, + travelThermographFk, + state, + maxTemperature, + minTemperature, + temperatureFk, + warehouseId, + companyId, + dmsTypeId, + reference, + description, + hasFileAttached, + options + ) => { + const models = Self.app.models; + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let dmsFk; + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const travelThermograph = await models.TravelThermograph.findById( + travelThermographFk, + {fields: ['id', 'dmsFk', 'warehouseFk']}, + myOptions + ); + + if (!travelThermograph) + throw new UserError('No valid travel thermograph found'); + + if (travelThermograph.dmsFk) { + await models.Dms.updateFile(ctx, travelThermograph.dmsFk, myOptions); + dmsFk = travelThermograph.dmsFk; + } else { + const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); + const firstDms = uploadedFiles[0]; + dmsFk = firstDms.id; + } + + await travelThermograph.updateAttributes({ + dmsFk, + travelFk: id, + result: state, + maxTemperature, + minTemperature, + temperatureFk + }, myOptions); + + if (tx) await tx.commit(); + + return travelThermograph; + } catch (err) { + if (tx) await tx.rollback(); + throw err; + } + }; +}; diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js deleted file mode 100644 index f70e27368..000000000 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ /dev/null @@ -1,51 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -describe('Travel createThermograph()', () => { - beforeAll.mockLoopBackContext(); - const travelId = 3; - const currentUserId = 1102; - const thermographId = '138350-0'; - const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}}; - - it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => { - const tx = await models.Travel.beginTransaction({}); - - try { - const options = {transaction: tx}; - - spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]); - - travelThermographBefore = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: null - } - }, options); - - await models.Travel.createThermograph(ctx, travelId, thermographId, options); - - const travelThermographAfter = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: travelId - } - }, options); - - expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object)); - - expect(travelThermographBefore).toBeDefined(); - expect(travelThermographBefore.thermographFk).toEqual(thermographId); - expect(travelThermographBefore.travelFk).toBeNull(); - expect(travelThermographAfter).toBeDefined(); - - expect(travelThermographAfter.thermographFk).toEqual(thermographId); - expect(travelThermographAfter.travelFk).toEqual(travelId); - expect(travelThermographAfter.dmsFk).toEqual(5); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/travel/back/methods/travel/specs/saveThermograph.spec.js b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js new file mode 100644 index 000000000..c7d848c08 --- /dev/null +++ b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js @@ -0,0 +1,69 @@ +const models = require('vn-loopback/server/server').models; + +describe('Thermograph saveThermograph()', () => { + const ctx = beforeAll.getCtx(); + const travelFk = 1; + const thermographId = '138350-0'; + const warehouseFk = '1'; + const state = 'COMPLETED'; + const maxTemperature = 30; + const minTemperature = 10; + const temperatureFk = 'COOL'; + let tx; + let options; + + beforeEach(async() => { + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should update an existing travel thermograph', async() => { + const dmsFk = 5; + spyOn(models.Dms, 'uploadFile').and.returnValue([{id: dmsFk}]); + + const travelThermograph = await models.TravelThermograph.create({ + travelFk, + thermographFk: thermographId, + temperatureFk, + warehouseFk, + }, options); + + const updatedThermograph = await models.Travel.saveThermograph( + ctx, + travelFk, + travelThermograph.id, + state, + maxTemperature, + minTemperature, + temperatureFk, + null, + null, + null, + null, + null, + null, options + ); + + expect(updatedThermograph.result).toEqual(state); + expect(updatedThermograph.maxTemperature).toEqual(maxTemperature); + expect(updatedThermograph.minTemperature).toEqual(minTemperature); + expect(updatedThermograph.temperatureFk).toEqual(temperatureFk); + expect(updatedThermograph.dmsFk).toEqual(dmsFk); + }); + + it('should throw an error if no valid travel thermograph is found', async() => { + try { + await models.Travel.saveThermograph( + ctx, null, 'notExists', state, maxTemperature, minTemperature, temperatureFk, options + ); + fail('Expected an error to be thrown when no valid travel thermograph is found'); + } catch (e) { + expect(e.message).toBe('No valid travel thermograph found'); + } + }); +}); diff --git a/modules/travel/back/methods/travel/updateThermograph.js b/modules/travel/back/methods/travel/updateThermograph.js deleted file mode 100644 index d89725920..000000000 --- a/modules/travel/back/methods/travel/updateThermograph.js +++ /dev/null @@ -1,83 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('updateThermograph', { - description: 'Updates a travel thermograph', - accessType: 'WRITE', - accepts: [{ - arg: 'id', - type: 'Number', - description: 'The travel id', - http: {source: 'path'} - }, { - arg: 'thermographId', - type: 'String', - description: 'The thermograph id', - required: true - }, { - arg: 'state', - type: 'String', - required: true - }, { - arg: 'warehouseId', - type: 'Number', - description: 'The warehouse id' - }, { - arg: 'companyId', - type: 'Number', - description: 'The company id' - }, { - arg: 'dmsTypeId', - type: 'Number', - description: 'The dms type id' - }, { - arg: 'reference', - type: 'String' - }, { - arg: 'description', - type: 'String' - }, { - arg: 'hasFileAttached', - type: 'Boolean', - description: 'True if has an attached file' - }], - returns: { - type: 'Object', - root: true - }, - http: { - path: `/:id/updateThermograph`, - verb: 'POST' - } - }); - - Self.updateThermograph = async(ctx, id, thermographId, state) => { - const models = Self.app.models; - const tx = await Self.beginTransaction({}); - - try { - const options = {transaction: tx}; - const travelThermograph = await models.TravelThermograph.findOne({ - where: { - thermographFk: thermographId, - travelFk: id - } - }, options); - - if (!travelThermograph) - throw new UserError('No valid travel thermograph found'); - - const dmsFk = travelThermograph.dmsFk; - await models.Dms.updateFile(ctx, dmsFk, options); - await travelThermograph.updateAttributes({ - result: state - }, options); - - await tx.commit(); - return travelThermograph; - } catch (e) { - await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index cc8e60aaf..cb0a9b4f8 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -28,6 +28,14 @@ "warehouseFk": { "type": "number", "required": true + }, + "maxTemperature": { + "type": "number", + "description": "Maximum temperature" + }, + "minTemperature": { + "type": "number", + "description": "Minimum temperature" } }, "relations": { diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index 4bcf7b31d..369be7919 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -4,9 +4,8 @@ module.exports = Self => { require('../methods/travel/getTravel')(Self); require('../methods/travel/getEntries')(Self); require('../methods/travel/filter')(Self); - require('../methods/travel/createThermograph')(Self); require('../methods/travel/deleteThermograph')(Self); - require('../methods/travel/updateThermograph')(Self); + require('../methods/travel/saveThermograph')(Self); require('../methods/travel/extraCommunityFilter')(Self); require('../methods/travel/getAverageDays')(Self); require('../methods/travel/cloneWithEntries')(Self); diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index fa2c1261a..9f0678807 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -87,7 +87,7 @@ class Controller extends Section { } onSubmit() { - const query = `Travels/${this.travel.id}/createThermograph`; + const query = `Travels/${this.travel.id}/saveThermograph`; const options = { method: 'POST', url: query, diff --git a/modules/travel/front/thermograph/edit/index.js b/modules/travel/front/thermograph/edit/index.js index a8df3142d..17caf9ef2 100644 --- a/modules/travel/front/thermograph/edit/index.js +++ b/modules/travel/front/thermograph/edit/index.js @@ -34,7 +34,7 @@ class Controller extends Section { const filter = encodeURIComponent(JSON.stringify(filterObj)); const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`; this.$http.get(path).then(res => { - const thermograph = res.data && res.data; + const thermograph = res.data; this.thermograph = { thermographId: thermograph.thermographFk, state: thermograph.result, @@ -51,7 +51,7 @@ class Controller extends Section { } onSubmit() { - const query = `travels/${this.$params.id}/updateThermograph`; + const query = `travels/${this.$params.id}/saveThermograph`; const options = { method: 'POST', url: query, @@ -62,8 +62,8 @@ class Controller extends Section { transformRequest: files => { const formData = new FormData(); - for (let i = 0; i < files.length; i++) - formData.append(files[i].name, files[i]); + for (const element of files) + formData.append(element.name, element); return formData; }, diff --git a/modules/travel/front/thermograph/edit/index.spec.js b/modules/travel/front/thermograph/edit/index.spec.js index c0b044a8d..0b3ef4fbe 100644 --- a/modules/travel/front/thermograph/edit/index.spec.js +++ b/modules/travel/front/thermograph/edit/index.spec.js @@ -109,7 +109,7 @@ describe('Worker', () => { const files = [{id: 1, name: 'MyFile'}]; controller.thermograph = {files}; const serializedParams = $httpParamSerializer(controller.thermograph); - const query = `travels/${controller.$params.id}/updateThermograph?${serializedParams}`; + const query = `travels/${controller.$params.id}/saveThermograph?${serializedParams}`; $httpBackend.expect('POST', query).respond({}); controller.onSubmit(); From 80c6497d3c0ff9ee055d8126b41163f39084c3a6 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 25 Sep 2024 13:29:11 +0200 Subject: [PATCH 8/9] feat: refs #6722 traduccion --- loopback/locale/es.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 965b0c457..59ee11db1 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -379,5 +379,5 @@ "The entry does not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha", - "No valid travel thermograph found": "No valid travel thermograph found" + "No valid travel thermograph found": "No se encontró un termógrafo válido" } \ No newline at end of file From 6b4b5f2338a353356a82e2e5f5e80f3a4250654a Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 26 Sep 2024 16:26:50 +0200 Subject: [PATCH 9/9] fix: e2e not necesary --- e2e/paths/10-travel/05_thermograph.spec.js | 64 ---------------------- 1 file changed, 64 deletions(-) delete mode 100644 e2e/paths/10-travel/05_thermograph.spec.js diff --git a/e2e/paths/10-travel/05_thermograph.spec.js b/e2e/paths/10-travel/05_thermograph.spec.js deleted file mode 100644 index c9709f2f5..000000000 --- a/e2e/paths/10-travel/05_thermograph.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -import selectors from '../../helpers/selectors.js'; -import getBrowser from '../../helpers/puppeteer'; - -describe('Travel thermograph path', () => { - const thermographName = '7H3-37H3RN4L-FL4M3'; - let browser; - let page; - - beforeAll(async() => { - browser = await getBrowser(); - page = browser.page; - await page.loginAndModule('buyer', 'travel'); - await page.write(selectors.travelIndex.generalSearchFilter, '3'); - await page.keyboard.press('Enter'); - await page.accessToSection('travel.card.thermograph.index'); - }); - - afterAll(async() => { - await browser.close(); - }); - - it('should reach the thermograph section', async() => { - await page.waitForState('travel.card.thermograph.index'); - }); - - it('should click the add thermograph floating button', async() => { - await page.waitToClick(selectors.travelThermograph.add); - await page.waitForState('travel.card.thermograph.create'); - }); - - it('should click on the add thermograph icon of the thermograph autocomplete', async() => { - await page.waitToClick(selectors.travelThermograph.addThermographIcon); - await page.write(selectors.travelThermograph.newThermographId, thermographName); - await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE'); - await page.autocompleteSearch(selectors.travelThermograph.newThermographWarehouse, 'Warehouse Two'); - await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'Warm'); - await page.waitToClick(selectors.travelThermograph.createThermographButton); - }); - - it('should select the file to upload', async() => { - let currentDir = process.cwd(); - let filePath = `${currentDir}/e2e/assets/thermograph.jpeg`; - - const [fileChooser] = await Promise.all([ - page.waitForFileChooser(), - page.waitToClick(selectors.travelThermograph.uploadIcon) - ]); - await fileChooser.accept([filePath]); - - await page.waitToClick(selectors.travelThermograph.upload); - - const message = await page.waitForSnackbar(); - const state = await page.getState(); - - expect(message.text).toContain('Data saved!'); - expect(state).toBe('travel.card.thermograph.index'); - }); - - it('should check everything was saved correctly', async() => { - const result = await page.waitToGetProperty(selectors.travelThermograph.createdThermograph, 'innerText'); - - expect(result).toContain(thermographName); - }); -});