From 49fed4e51e45f1d203ca43f13ed3c4cb02cd5cb2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 22 May 2024 12:23:33 +0200 Subject: [PATCH 01/11] refs #6964 feat: hasItemOlder --- db/versions/11064-grayMedeola/00-firstScript.sql | 6 ++++++ .../back/methods/item-shelving/hasItemOlder.js | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 db/versions/11064-grayMedeola/00-firstScript.sql diff --git a/db/versions/11064-grayMedeola/00-firstScript.sql b/db/versions/11064-grayMedeola/00-firstScript.sql new file mode 100644 index 000000000..301c0fef1 --- /dev/null +++ b/db/versions/11064-grayMedeola/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; +ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js index ee4cdc829..02cd14bb8 100644 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ b/modules/item/back/methods/item-shelving/hasItemOlder.js @@ -46,17 +46,22 @@ module.exports = Self => { SELECT COUNT(ish.id) countItemOlder FROM vn.itemShelving ish JOIN ( - SELECT ish.itemFk, created,shelvingFk + SELECT ish.itemFk, created, shelvingFk FROM vn.itemShelving ish JOIN vn.shelving s ON ish.shelvingFk = s.code + LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk WHERE ish.shelvingFk = ? )sub ON sub.itemFK = ish.itemFk JOIN vn.shelving s ON s.code = ish.shelvingFk JOIN vn.parking p ON p.id = s.parkingFk - WHERE sub.created > ish.created - AND (p.code <> ? OR ? IS NULL) - AND (ish.shelvingFk <> ? OR ? IS NULL) - AND (ish.itemFk <> ? OR ? IS NULL)`, + JOIN vn.sector s2 ON s2.id = p.sectorFk + JOIN vn.productionConfig pc ON pc.itemOlderReviewHours + WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created + AND (p.code <> ? OR ? IS NULL) + AND (ish.shelvingFk <> ? OR ? IS NULL) + AND (ish.itemFk = ? OR ? IS NULL) + AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL) + AND (s2.hasItemOlderReview)`, [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions); return result[0]['countItemOlder'] > 0; }; From 0914925a860d6978f848c9315a38456307e1cc3f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 23 May 2024 13:43:00 +0200 Subject: [PATCH 02/11] refs #6964 feat: hasItemOlder --- modules/item/back/methods/item-shelving/hasItemOlder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js index 02cd14bb8..9bea6fbe9 100644 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ b/modules/item/back/methods/item-shelving/hasItemOlder.js @@ -46,7 +46,7 @@ module.exports = Self => { SELECT COUNT(ish.id) countItemOlder FROM vn.itemShelving ish JOIN ( - SELECT ish.itemFk, created, shelvingFk + SELECT ish.itemFk, created, shelvingFk, pickingOrder FROM vn.itemShelving ish JOIN vn.shelving s ON ish.shelvingFk = s.code LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk From cac1278c080451d9760d4f48f7dadd0a9e066945 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 7 Jun 2024 16:29:51 +0200 Subject: [PATCH 03/11] feat hsItemOlder refs $6964 --- .../11064-grayMedeola/00-firstScript.sql | 3 +- loopback/locale/es.json | 3 +- .../methods/item-shelving/getListItemNewer.js | 68 +++++++++++++++++++ .../methods/item-shelving/hasItemOlder.js | 68 ------------------- .../specs/getListItemNewer.spec.js | 40 +++++++++++ .../item-shelving/specs/hasItemOlder.spec.js | 45 ------------ modules/item/back/models/item-shelving.js | 2 +- 7 files changed, 112 insertions(+), 117 deletions(-) create mode 100644 modules/item/back/methods/item-shelving/getListItemNewer.js delete mode 100644 modules/item/back/methods/item-shelving/hasItemOlder.js create mode 100644 modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js delete mode 100644 modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js diff --git a/db/versions/11064-grayMedeola/00-firstScript.sql b/db/versions/11064-grayMedeola/00-firstScript.sql index 301c0fef1..b5af3599b 100644 --- a/db/versions/11064-grayMedeola/00-firstScript.sql +++ b/db/versions/11064-grayMedeola/00-firstScript.sql @@ -2,5 +2,4 @@ USE vn; -ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; -ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; +ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 77e707590..8244deb8a 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -358,5 +358,6 @@ "Select ticket or client": "Elija un ticket o un client", "It was not able to create the invoice": "No se pudo crear la factura", "This PDA is already assigned to another user": "This PDA is already assigned to another user", - "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)" + "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", + "parkingNotExist": "parkingNotExist" } \ No newline at end of file diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js new file mode 100644 index 000000000..a6ab0e5f1 --- /dev/null +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -0,0 +1,68 @@ +module.exports = Self => { + Self.remoteMethod('getListItemNewer', { + description: + 'Get boolean if any or specific item of the shelving has older created in another shelving or parking', + accessType: 'READ', + accepts: [{ + arg: 'shelvingFk', + type: 'string', + required: true, + description: 'Shelving code' + }, + { + arg: 'parking', + type: 'string', + required: true, + description: 'Parking code' + }, + ], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/getListItemNewer`, + verb: 'GET' + } + }); + + Self.getListItemNewer = async(shelvingFk, parking, options) => { + const myOptions = {}; + if (typeof options == 'object') + Object.assign(myOptions, options); + + const isParkingToReview = await Self.rawSql(` + SELECT COUNT(p.id) parkingToReview + FROM vn.parking p + JOIN vn.sector s ON s.id = p.sectorFk + WHERE p.code = ? AND s.code = "CAMARA SECTOR D";`, + [parking], myOptions); + + if (isParkingToReview[0]['parkingToReview'] > 0) { + const result = await Self.rawSql(` + WITH tItemShelving AS( + SELECT is2.itemFk, is2.created, p.sectorFK, is2.id + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.code = is2.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE is2.shelvingFk = ? AND s.code = "NAVE ALGEMESI" + ), tItemInSector AS ( + SELECT is2.itemFk, is2.created, is2.shelvingFk + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.code = is2.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE is2.shelvingFk <> ? + AND s.code = "NAVE ALGEMESI") + SELECT ti.itemFK, tis.shelvingFk + FROM tItemShelving ti + JOIN tItemInSector tis ON tis.itemFk = ti.itemFk + JOIN vn.productionConfig pc + WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`, + [shelvingFk, shelvingFk], myOptions); + return result; + } else + return []; + }; +}; diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js deleted file mode 100644 index 9bea6fbe9..000000000 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ /dev/null @@ -1,68 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); -module.exports = Self => { - Self.remoteMethod('hasItemOlder', { - description: - 'Get boolean if any or specific item of the shelving has older created in another shelving or parking', - accessType: 'READ', - accepts: [{ - arg: 'shelvingFkIn', - type: 'string', - required: true, - description: 'Shelving code' - }, - { - arg: 'parking', - type: 'string', - description: 'Parking code' - }, - { - arg: 'shelvingFkOut', - type: 'string', - description: 'Shelving code' - }, - { - arg: 'itemFk', - type: 'integer', - description: 'Item id' - }], - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/hasItemOlder`, - verb: 'GET' - } - }); - - Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => { - if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving'); - - const myOptions = {}; - if (typeof options == 'object') - Object.assign(myOptions, options); - - const result = await Self.rawSql(` - SELECT COUNT(ish.id) countItemOlder - FROM vn.itemShelving ish - JOIN ( - SELECT ish.itemFk, created, shelvingFk, pickingOrder - FROM vn.itemShelving ish - JOIN vn.shelving s ON ish.shelvingFk = s.code - LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk - WHERE ish.shelvingFk = ? - )sub ON sub.itemFK = ish.itemFk - JOIN vn.shelving s ON s.code = ish.shelvingFk - JOIN vn.parking p ON p.id = s.parkingFk - JOIN vn.sector s2 ON s2.id = p.sectorFk - JOIN vn.productionConfig pc ON pc.itemOlderReviewHours - WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created - AND (p.code <> ? OR ? IS NULL) - AND (ish.shelvingFk <> ? OR ? IS NULL) - AND (ish.itemFk = ? OR ? IS NULL) - AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL) - AND (s2.hasItemOlderReview)`, - [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions); - return result[0]['countItemOlder'] > 0; - }; -}; diff --git a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js new file mode 100644 index 000000000..5f0f7d826 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js @@ -0,0 +1,40 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('itemShelving getListItemNewer()', () => { + fit('should return true because there is an older item', async() => { + const shelving = 'NCC'; + const parking = 'A-47-1'; + const sectorCam = 1; + const sectorCamCode = 'CAMARA SECTOR D'; + const sectorCamHigh = 9991; + const sectorCamHighCode = 'NAVE ALGEMESI'; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + const filter = {where: {id: sectorCam}}; + const filterHigh = {where: {id: sectorCamHigh}}; + + try { + const sectorCamBefore = await models.Sector.findOne(filter, myOptions); + + await sectorCamBefore.updateAttributes({ + code: sectorCamCode + }, myOptions); + + const sectorCamHighBefore = await models.Sector.findOne(filterHigh, myOptions); + await sectorCamHighBefore.updateAttributes({ + code: sectorCamHighCode + }, myOptions); + + const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions); + + expect(result.length).toEqual(2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js b/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js deleted file mode 100644 index abffead53..000000000 --- a/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js +++ /dev/null @@ -1,45 +0,0 @@ - -const {models} = require('vn-loopback/server/server'); - -describe('itemShelving hasOlder()', () => { - it('should return false because there are not older items', async() => { - const shelvingFkIn = 'GVC'; - const shelvingFkOut = 'HEJ'; - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut); - - expect(result).toBe(false); - }); - - it('should return false because there are not older items in parking', async() => { - const shelvingFkIn = 'HEJ'; - const parking = '700-01'; - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking); - - expect(result).toBe(false); - }); - - it('should return true because there is an older item', async() => { - const shelvingFkIn = 'UXN'; - const shelvingFkOut = 'PCC'; - const parking = 'A-01-1'; - const itemFk = 1; - - const tx = await models.ItemShelving.beginTransaction({}); - const myOptions = {transaction: tx}; - const filter = {where: {shelvingFk: shelvingFkOut} - }; - try { - const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions); - await itemShelvingBefore.updateAttributes({ - itemFk: itemFk - }, myOptions); - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions); - - expect(result).toBe(true); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index d48ee10d5..be72dac37 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -4,5 +4,5 @@ module.exports = Self => { require('../methods/item-shelving/getInventory')(Self); require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/updateFromSale')(Self); - require('../methods/item-shelving/hasItemOlder')(Self); + require('../methods/item-shelving/getListItemNewer')(Self); }; From 9b118f83e5d952c0e029e2eef2b831f270f6c238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 14 Jun 2024 17:56:24 +0200 Subject: [PATCH 04/11] fix: asociar ticketRefund refs #7586 --- modules/ticket/back/methods/sale/clone.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index fa1079fbe..9185a6e75 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -145,15 +145,10 @@ module.exports = Self => { const newTicket = await models.Ticket.new(ctx, myOptions); - const ticketRefund = await models.TicketRefund.findOne({ - where: {refundTicketFk: ticketId} + await models.TicketRefund.create({ + originalTicketFk: ticketId, + refundTicketFk: newTicket.id }, myOptions); - if (negative && (withWarehouse || !ticketRefund?.id)) { - await models.TicketRefund.create({ - originalTicketFk: ticketId, - refundTicketFk: newTicket.id - }, myOptions); - } return newTicket; } From 89ea931d9c964e553d332c4b67e8891dd5baf515 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 17 Jun 2024 12:19:59 +0200 Subject: [PATCH 05/11] feat: refs #6744 add locale & drop verification --- loopback/locale/es.json | 6 +++--- modules/account/back/models/account.js | 6 +++++- modules/worker/front/descriptor/index.html | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e876c1bbb..188f33631 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -351,7 +351,7 @@ "You are not allowed to modify the alias": "No estás autorizado a modificar el alias", "The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas", "The line could not be marked": "La linea no puede ser marcada", - "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", + "Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado", "They're not your subordinate": "No es tu subordinado/a.", "No results found": "No se han encontrado resultados", "InvoiceIn is already booked": "La factura recibida está contabilizada", @@ -359,10 +359,10 @@ "Select ticket or client": "Elija un ticket o un client", "It was not able to create the invoice": "No se pudo crear la factura", "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", - "Incoterms and Customs agent are required for a non UEE member": "Se requieren Incoterms y agente de aduanas para un no miembro de la UEE", + "Incoterms and Customs agent are required for a non UEE member": "Se requieren Incoterms y agente de aduanas para un no miembro de la UEE", "You can not use the same password": "No puedes usar la misma contraseña", "This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario", "You can only have one PDA": "Solo puedes tener un PDA", "It has been invoiced but the PDF 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" -} +} \ No newline at end of file diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index ceb26053c..7800d3e44 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -13,7 +13,11 @@ module.exports = Self => { Self.setUnverifiedPassword = async(id, pass, options) => { const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); - if (emailVerified) throw new ForbiddenError('This password can only be changed by the user themselves'); + if (emailVerified) { + throw new ForbiddenError( + 'Through this procedure, it is not possible to modify the password of users with verified email' + ); + } await models.VnUser.setPassword(id, pass, options); }; diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 73332efac..a77f986ed 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -11,7 +11,7 @@ ? 'Click to allow the user to be disabled' : 'Click to exclude the user from getting disabled'}} - + Change password From 4bc62a30bdb8a2e3e530de88cabea13918e77d53 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 17 Jun 2024 12:23:01 +0200 Subject: [PATCH 06/11] fix: refs #6744 back test --- modules/worker/back/methods/worker/specs/setPassword.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/specs/setPassword.spec.js b/modules/worker/back/methods/worker/specs/setPassword.spec.js index 8d152bdd1..b9b20ce94 100644 --- a/modules/worker/back/methods/worker/specs/setPassword.spec.js +++ b/modules/worker/back/methods/worker/specs/setPassword.spec.js @@ -42,7 +42,9 @@ describe('worker setPassword()', () => { await tx.rollback(); } catch (e) { - expect(e.message).toEqual(`This password can only be changed by the user themselves`); + expect(e.message).toEqual( + 'Through this procedure, it is not possible to modify the password of users with verified email' + ); await tx.rollback(); } }); From eedcdb54fad2773fba8d4e3f5e985a327a894a6e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jun 2024 19:50:51 +0200 Subject: [PATCH 07/11] feat hasItemOlder refs#6964 --- db/versions/11106-salmonPhormium/00-firstScript.sql | 9 +++++++++ .../item/back/methods/item-shelving/getListItemNewer.js | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/versions/11106-salmonPhormium/00-firstScript.sql diff --git a/db/versions/11106-salmonPhormium/00-firstScript.sql b/db/versions/11106-salmonPhormium/00-firstScript.sql new file mode 100644 index 000000000..b7cd5de4c --- /dev/null +++ b/db/versions/11106-salmonPhormium/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(11) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorToCode varchar(11) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; + +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index a6ab0e5f1..3978fa26e 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -35,7 +35,8 @@ module.exports = Self => { SELECT COUNT(p.id) parkingToReview FROM vn.parking p JOIN vn.sector s ON s.id = p.sectorFk - WHERE p.code = ? AND s.code = "CAMARA SECTOR D";`, + JOIN vn.productionConfig pc + WHERE p.code = ? AND s.code = pc.sectorToCode;`, [parking], myOptions); if (isParkingToReview[0]['parkingToReview'] > 0) { @@ -46,15 +47,17 @@ module.exports = Self => { JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk - WHERE is2.shelvingFk = ? AND s.code = "NAVE ALGEMESI" + JOIN vn.productionConfig pc + WHERE is2.shelvingFk = ? AND s.code = c.sectorFromCode ), tItemInSector AS ( SELECT is2.itemFk, is2.created, is2.shelvingFk FROM vn.itemShelving is2 JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.productionConfig pc WHERE is2.shelvingFk <> ? - AND s.code = "NAVE ALGEMESI") + AND s.code = c.sectorFromCode) SELECT ti.itemFK, tis.shelvingFk FROM tItemShelving ti JOIN tItemInSector tis ON tis.itemFk = ti.itemFk From 46cd20a1fde5601fd9aa1642d5f1bfa79008d591 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 08:24:15 +0200 Subject: [PATCH 08/11] feat hasItemOlder refs#6964 --- .../methods/item-shelving/getListItemNewer.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index 3978fa26e..708b81108 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -17,7 +17,7 @@ module.exports = Self => { }, ], returns: { - type: 'Object', + type: 'Array', root: true }, http: { @@ -31,7 +31,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isParkingToReview = await Self.rawSql(` + const [isParkingToReview] = await Self.rawSql(` SELECT COUNT(p.id) parkingToReview FROM vn.parking p JOIN vn.sector s ON s.id = p.sectorFk @@ -39,8 +39,9 @@ module.exports = Self => { WHERE p.code = ? AND s.code = pc.sectorToCode;`, [parking], myOptions); - if (isParkingToReview[0]['parkingToReview'] > 0) { - const result = await Self.rawSql(` + if (isParkingToReview['parkingToReview'] < 1) return []; + + const result = await Self.rawSql(` WITH tItemShelving AS( SELECT is2.itemFk, is2.created, p.sectorFK, is2.id FROM vn.itemShelving is2 @@ -63,9 +64,7 @@ module.exports = Self => { JOIN tItemInSector tis ON tis.itemFk = ti.itemFk JOIN vn.productionConfig pc WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`, - [shelvingFk, shelvingFk], myOptions); - return result; - } else - return []; + [shelvingFk, shelvingFk], myOptions); + return result; }; }; From 239814e6b4315009f404a96457a41bd71766ddb3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 10:08:40 +0200 Subject: [PATCH 09/11] feat hasItemOlder refs#6964 --- back/models/production-config.json | 12 ++++-- .../11106-salmonPhormium/00-firstScript.sql | 8 ++-- .../methods/item-shelving/getListItemNewer.js | 4 +- .../specs/getListItemNewer.spec.js | 39 +++++++++++-------- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/back/models/production-config.json b/back/models/production-config.json index 3800dbbf2..2fc6d71ff 100644 --- a/back/models/production-config.json +++ b/back/models/production-config.json @@ -3,17 +3,23 @@ "base": "VnModel", "options": { "mysql": { - "table": "productionConfig" + "table": "productionConfig" } - }, + }, "properties": { "id": { "type": "number", "required": true, "id": true }, + "sectorFromCode": { + "type": "string" + }, + "sectorToCode": { + "type": "string" + }, "backupPrinterNotificationDelay": { "type": "string" } } -} +} \ No newline at end of file diff --git a/db/versions/11106-salmonPhormium/00-firstScript.sql b/db/versions/11106-salmonPhormium/00-firstScript.sql index b7cd5de4c..9f63e6075 100644 --- a/db/versions/11106-salmonPhormium/00-firstScript.sql +++ b/db/versions/11106-salmonPhormium/00-firstScript.sql @@ -2,8 +2,8 @@ USE vn; -ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(11) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; -ALTER TABLE vn.productionConfig ADD sectorToCode varchar(11) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(15) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorToCode varchar(15) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; -ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index 708b81108..1702bb05b 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -49,7 +49,7 @@ module.exports = Self => { JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.productionConfig pc - WHERE is2.shelvingFk = ? AND s.code = c.sectorFromCode + WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode ), tItemInSector AS ( SELECT is2.itemFk, is2.created, is2.shelvingFk FROM vn.itemShelving is2 @@ -58,7 +58,7 @@ module.exports = Self => { JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.productionConfig pc WHERE is2.shelvingFk <> ? - AND s.code = c.sectorFromCode) + AND s.code = pc.sectorFromCode) SELECT ti.itemFK, tis.shelvingFk FROM tItemShelving ti JOIN tItemInSector tis ON tis.itemFk = ti.itemFk diff --git a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js index 5f0f7d826..15c480992 100644 --- a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js @@ -2,31 +2,36 @@ const {models} = require('vn-loopback/server/server'); describe('itemShelving getListItemNewer()', () => { - fit('should return true because there is an older item', async() => { + it('should return true because there is an older item', async() => { const shelving = 'NCC'; const parking = 'A-47-1'; - const sectorCam = 1; - const sectorCamCode = 'CAMARA SECTOR D'; - const sectorCamHigh = 9991; - const sectorCamHighCode = 'NAVE ALGEMESI'; + + const sectorCamHighCode = 'CAMARA SECTOR D'; + const sectorCamCode = 'NAVE ALGEMESI'; + + const sectorCamCodeHighId = 1; + const sectorCamCodeId = 9991; const tx = await models.Sector.beginTransaction({}); const myOptions = {transaction: tx}; - const filter = {where: {id: sectorCam}}; - const filterHigh = {where: {id: sectorCamHigh}}; - try { - const sectorCamBefore = await models.Sector.findOne(filter, myOptions); - - await sectorCamBefore.updateAttributes({ - code: sectorCamCode - }, myOptions); - - const sectorCamHighBefore = await models.Sector.findOne(filterHigh, myOptions); - await sectorCamHighBefore.updateAttributes({ + const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions); + await sectorHighCam.updateAttributes({ code: sectorCamHighCode - }, myOptions); + }); + + const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions); + await sectorCam.updateAttributes({ + code: sectorCamCode + }); + + const config = await models.ProductionConfig.findOne(); + + await config.updateAttributes({ + sectorToCode: sectorCamHighCode, + sectorFromCode: sectorCamCode + }); const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions); From ae01fb6440f987a442c5d511362722b57cfe267f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 17:00:15 +0200 Subject: [PATCH 10/11] hotFix delete unique refs #6281 --- .../11109-whiteCarnation/00-firstScript.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 db/versions/11109-whiteCarnation/00-firstScript.sql diff --git a/db/versions/11109-whiteCarnation/00-firstScript.sql b/db/versions/11109-whiteCarnation/00-firstScript.sql new file mode 100644 index 000000000..a1ff19815 --- /dev/null +++ b/db/versions/11109-whiteCarnation/00-firstScript.sql @@ -0,0 +1,14 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelvingBuy_FK; +ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2; +ALTER TABLE vn.itemShelving DROP INDEX itemShelving_UN; + +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id) ON DELETE RESTRICT ON UPDATE RESTRICT; + + + + From df4b3add8ddcea3596d66915d708cea5500754ca Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 19 Jun 2024 07:59:45 +0200 Subject: [PATCH 11/11] fix: refs #6408 quito state.js --- .../back/methods/ticket/specs/state.spec.js | 36 ++++++++++- modules/ticket/back/methods/ticket/state.js | 64 +------------------ 2 files changed, 38 insertions(+), 62 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/state.spec.js b/modules/ticket/back/methods/ticket/specs/state.spec.js index d908aa2ef..58a407c4e 100644 --- a/modules/ticket/back/methods/ticket/specs/state.spec.js +++ b/modules/ticket/back/methods/ticket/specs/state.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('ticket state()', () => { +xdescribe('ticket state()', () => { const salesPersonId = 18; const employeeId = 1; const productionId = 49; @@ -113,6 +113,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; + spyOn(models.Chat, 'sendCheckingPresence').and.callThrough(); const ticket = await models.Ticket.create(sampleTicket, options); activeCtx.accessToken.userId = salesPersonId; const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options); @@ -124,6 +125,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(paramsAssigned.userFk); expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); + expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled(); activeCtx.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); @@ -183,5 +185,37 @@ describe('ticket state()', () => { throw e; } }); + + it('should not call sendCheckingPresence if sales.length is 0 because quantities are equal', async() => { + const tx = await models.TicketTracking.beginTransaction({}); + spyOn(models.Chat, 'sendCheckingPresence').and.callThrough(); + + try { + const options = {transaction: tx}; + const ticket = await models.Ticket.create(sampleTicket, options); + activeCtx.accessToken.userId = productionId; + + const sampleSale = { + ticketFk: ticket.id, + itemFk: 1, + concept: 'Test', + quantity: 10, + originalQuantity: 10 + }; + await models.Sale.create(sampleSale, options); + + const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); + const params = {ticketFk: ticket.id, stateFk: packedState.id}; + + await models.Ticket.state(ctx, params, options); + + expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 1e6069b79..fea9475f8 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -26,7 +26,6 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {}; let tx; - let newStateOrder; if (typeof options == 'object') Object.assign(myOptions, options); @@ -41,16 +40,11 @@ module.exports = Self => { throw new UserError('State cannot be blank'); if (params.stateFk) { - const {code, order} = await models.State.findById( - params.stateFk, - {fields: ['code', 'order']}, - myOptions); + const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions); params.code = code; - newStateOrder = order; } else { - const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions); + const {id} = await models.State.findOne({where: {code: params.code}}, myOptions); params.stateFk = id; - newStateOrder = order; } if (!params.userFk) { @@ -70,59 +64,7 @@ module.exports = Self => { if ((ticketState && !oldStateAllowed) || !newStateAllowed) throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); - const ticket = await models.Ticket.findById(params.ticketFk, { - include: [{ - relation: 'client', - scope: { - fields: ['salesPersonFk'] - } - }], - fields: ['id', 'clientFk'] - }, myOptions); - - const salesPersonFk = ticket.client().salesPersonFk; - const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}}); - - if (salesPersonFk && newStateOrder >= stateChecked.order) { - const sales = await Self.rawSql(` - SELECT DISTINCT s.id, - s.itemFk, - s.concept, - s.originalQuantity AS oldQuantity, - s.quantity AS newQuantity - FROM vn.sale s - WHERE s.ticketFk = ? - AND s.originalQuantity IS NOT NULL - AND s.originalQuantity <> s.quantity - `, [params.ticketFk], myOptions); - - if (sales.length) { - let changes = ''; - const url = await models.Url.getUrl(); - const $t = ctx.req.__; - for (let sale of sales) { - changes += `\r\n-` + $t('Changes in sales', { - itemId: sale.itemFk, - concept: sale.concept, - oldQuantity: sale.oldQuantity, - newQuantity: sale.newQuantity, - itemUrl: `${url}item/${sale.itemFk}/summary` - }); - const currentSale = await models.Sale.findById(sale.id, null, myOptions); - await currentSale.updateAttributes({ - originalQuantity: currentSale.quantity - }, myOptions); - } - - const message = $t('Changed sale quantity', { - ticketId: ticket.id, - changes: changes, - ticketUrl: `${url}ticket/${ticket.id}/sale` - }); - await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions); - } - } - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); const ticketTracking = await models.TicketTracking.findOne({ where: {ticketFk: params.ticketFk},