From 070a5640df8c40bba1b96fedc90440fcd8575576 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 24 Oct 2024 08:16:04 +0000 Subject: [PATCH 1/5] fix: recalculatePrice not working with all ids --- modules/ticket/back/methods/sale/recalculatePrice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index fd3d6aa9b..ea71032d0 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -48,7 +48,7 @@ module.exports = Self => { CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; - const recalculation = await Self.rawSql(query, salesIds, myOptions); + const recalculation = await Self.rawSql(query, [salesIds], myOptions); if (tx) await tx.commit(); From 4da11c65bbe5de6e63ab3287dbcadea3938b23bd Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 24 Oct 2024 12:26:03 +0200 Subject: [PATCH 2/5] fix: refs #235425 sale priceFixed update --- modules/ticket/back/methods/sale/updatePrice.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index 191fd09e3..afb25c365 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -92,6 +92,19 @@ module.exports = Self => { }, myOptions); } await sale.updateAttributes({price: newPrice}, myOptions); + await Self.rawSql(` + UPDATE sale + SET priceFixed = ( + SELECT SUM(value) + FROM sale s + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk + WHERE ct.isBase + AND s.id = ? + ) + WHERE id = ? + `, [id, id], myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); From 111480f7b7f84c785cc1ceac8fef2d2eaad7c543 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 07:22:36 +0200 Subject: [PATCH 3/5] fix: refs #235425 Requested changes --- .../ticket/back/methods/sale/updatePrice.js | 29 ++++++++++--------- modules/ticket/back/models/sale.json | 3 ++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index afb25c365..d4f128082 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -91,20 +91,21 @@ module.exports = Self => { value: componentValue }, myOptions); } - await sale.updateAttributes({price: newPrice}, myOptions); - await Self.rawSql(` - UPDATE sale - SET priceFixed = ( - SELECT SUM(value) - FROM sale s - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk - WHERE ct.isBase - AND s.id = ? - ) - WHERE id = ? - `, [id, id], myOptions); + + const [priceFixed] = await Self.rawSql(` + SELECT SUM(value) value + FROM sale s + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk + WHERE ct.isBase + AND s.id = ? + `, [id], myOptions); + + await sale.updateAttributes({ + price: newPrice, + priceFixed: priceFixed.value + }, myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 96a36bbc9..947115f5c 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -28,6 +28,9 @@ "discount": { "type": "number" }, + "priceFixed": { + "type": "number" + }, "reserved": { "type": "boolean" }, From 69e1df25042f03e5ae57f3a798dfdff6b2f8f3fc Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 25 Oct 2024 08:47:43 +0200 Subject: [PATCH 4/5] fix: refs #235425 Requested changes --- .../methods/sale/specs/updatePrice.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 9d1403df0..100f74bf0 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -85,6 +85,25 @@ describe('sale updatePrice()', () => { } }); + it('should check if priceFixed has changed', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const price = 3; + const beforeUpdate = await models.Sale.findById(saleId, null, options); + await models.Sale.updatePrice(ctx, saleId, price, options); + const afterUpdate = await models.Sale.findById(saleId, null, options); + + expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => { const tx = await models.Sale.beginTransaction({}); From 869c7ab598ffa951a479987b6ba2946efd2aeb5a Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 28 Oct 2024 07:37:42 +0100 Subject: [PATCH 5/5] fix: refs #6644 email and translations --- loopback/locale/en.json | 9 ++++++--- loopback/locale/es.json | 5 +++-- loopback/locale/fr.json | 3 ++- loopback/locale/pt.json | 3 ++- modules/client/back/methods/client/createWithUser.js | 3 +++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a7e21960b..8c1ee7bb9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,9 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" -} + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first", + "null": "null", + "Invalid or expired verification code": "Invalid or expired verification code", + "Payment method is required": "Payment method is required" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9f01bd290..144046f56 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -385,5 +385,6 @@ "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", - "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén" -} \ No newline at end of file + "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén", + "The web user's email already exists": "El correo del usuario web ya existe" +} diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 23bd5cc04..446c2ad0d 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -363,5 +363,6 @@ "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "The web user's email already exists": "L'email de l'internaute existe déjà" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index f85afd607..4f68dfa53 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -363,5 +363,6 @@ "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", "Cannot send mail": "Não é possível enviar o email", - "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", + "The web user's email already exists": "O e-mail do utilizador da web já existe." } diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index c8cd282e1..1d5e71fca 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -1,3 +1,4 @@ +/* eslint max-len: ["error", { "code": 150 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = function(Self) { @@ -98,6 +99,8 @@ module.exports = function(Self) { return client; } catch (e) { if (tx) await tx.rollback(); + if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`The web user's email already exists`); + throw e; } };