From 33f1ed360b7dc91ec7e5c453e6b693edf3d69aef Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 23 May 2024 12:16:12 +0200 Subject: [PATCH 1/6] refactor: refs #7457 Added from param if not exists --- modules/order/back/methods/order/filter.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 592ed11e6..d22fa0804 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -96,9 +96,18 @@ module.exports = Self => { teamMembersId.push(userId); } - if (args && args.myTeam) + if (args?.myTeam) args.teamIds = teamIds; + if (args?.to) + args.to.setHours(23, 59, 0, 0); + + if (!args.from) { + const yesterday = new Date(); + yesterday.setDate(yesterday.getDate() - 1); + args.from = yesterday.toISOString().split('T')[0]; + } + const where = buildFilter(args, (param, value) => { switch (param) { case 'search': @@ -194,7 +203,7 @@ module.exports = Self => { `); stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(`GROUP BY id`); + stmt.merge(`GROUP BY o.id`); stmt.merge(conn.makePagination(filter)); stmts.push(stmt); stmts.push(`SET SESSION optimizer_search_depth = @_optimizer_search_depth`); -- 2.40.1 From a35c10adabbb4ea937fe43d55d8ca617a0f8d312 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 17 Oct 2024 08:35:24 +0200 Subject: [PATCH 2/6] fix: refs #7457 error on empty from param and add translate --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 3 ++- loopback/locale/fr.json | 5 +++-- loopback/locale/pt.json | 3 ++- modules/order/back/methods/order/filter.js | 9 +++------ 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index ea84cb6eb..0f6457754 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,5 +240,6 @@ "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" + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "The from field is required": "The 'from' field is required" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..8118b6f65 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -382,5 +382,6 @@ "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 se encontró un termógrafo válido", "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" + "type cannot be blank": "Se debe rellenar el tipo", + "The from field is required": "El campo 'desde' es obligatorio" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index a6648b186..5bc98c3dd 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -123,7 +123,7 @@ "Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", "Changed sale discount": "J'ai changé le rabais des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "J'ai créé la réclamation [{{claimId}}]({{{claimUrl}}}) des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",, + "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})", "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}", "State": "État", @@ -362,5 +362,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 from field is required": "Le champ de est requis" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index a43f0e780..91dc372c3 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -362,5 +362,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 from field is required": "O campo de origem é obrigatório" } diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index affa53a55..5b5fe8701 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -2,6 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethod('filter', { @@ -84,6 +85,8 @@ module.exports = Self => { const args = ctx.args; + if (!args.from) + throw new UserError('The from field is required'); // Apply filter by team const teamMembersId = []; if (args.myTeam != null) { @@ -106,12 +109,6 @@ module.exports = Self => { if (args?.to) args.to.setHours(23, 59, 0, 0); - if (!args.from) { - const yesterday = new Date(); - yesterday.setDate(yesterday.getDate() - 1); - args.from = yesterday.toISOString().split('T')[0]; - } - const where = buildFilter(args, (param, value) => { switch (param) { case 'search': -- 2.40.1 From 78ee7e141d4c118099a6ecf2770771346cd296c0 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 17 Oct 2024 08:40:25 +0200 Subject: [PATCH 3/6] fix: refs #7457 remove translate and use param definition for restriction --- loopback/locale/en.json | 3 +-- loopback/locale/es.json | 3 +-- loopback/locale/fr.json | 3 +-- loopback/locale/pt.json | 3 +-- modules/order/back/methods/order/filter.js | 7 ++----- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 0f6457754..ea84cb6eb 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,5 @@ "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", - "The from field is required": "The 'from' field is required" + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8118b6f65..9308fd4ec 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -382,6 +382,5 @@ "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 se encontró un termógrafo válido", "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", - "The from field is required": "El campo 'desde' es obligatorio" + "type cannot be blank": "Se debe rellenar el tipo" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 5bc98c3dd..3f6cc69e7 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -362,6 +362,5 @@ "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 from field is required": "Le champ de est requis" + "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" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index 91dc372c3..a43f0e780 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -362,6 +362,5 @@ "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 from field is required": "O campo de origem é obrigatório" + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" } diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 5b5fe8701..844adb51e 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -2,7 +2,6 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethod('filter', { @@ -23,7 +22,8 @@ module.exports = Self => { }, { arg: 'from', type: 'date', - description: 'The from date' + description: 'The from date', + required: true }, { arg: 'to', type: 'date', @@ -84,9 +84,6 @@ module.exports = Self => { Object.assign(myOptions, options); const args = ctx.args; - - if (!args.from) - throw new UserError('The from field is required'); // Apply filter by team const teamMembersId = []; if (args.myTeam != null) { -- 2.40.1 From fc61f7e4aba587c1577e28e9009d673e9fd9302a Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 11 Nov 2024 07:27:50 +0100 Subject: [PATCH 4/6] fix: refs #7457 remove group by calc time reduce bellow 1s --- modules/order/back/methods/order/filter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 844adb51e..eff2eecb6 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -201,7 +201,6 @@ module.exports = Self => { `); stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(`GROUP BY o.id`); stmt.merge(conn.makePagination(filter)); stmts.push(stmt); stmts.push(`SET SESSION optimizer_search_depth = @_optimizer_search_depth`); @@ -214,7 +213,6 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); - return result[ordersIndex]; }; }; -- 2.40.1 From 9ac54f463a9a714e092f2da8006905f5c580e2cc Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 14 Nov 2024 15:48:11 +0100 Subject: [PATCH 5/6] fix: refs #7457 add with on select to reduce --- modules/order/back/methods/order/filter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index eff2eecb6..307843d46 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -23,7 +23,6 @@ module.exports = Self => { arg: 'from', type: 'date', description: 'The from date', - required: true }, { arg: 'to', type: 'date', @@ -153,7 +152,12 @@ module.exports = Self => { CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) ENGINE = MEMORY - SELECT o.id, + WITH wOrderTicket AS( + SELECT orderFk, + ticketFk + FROM orderTicket + GROUP BY orderFk + )SELECT o.id, o.total, o.date_send landed, o.date_make created, -- 2.40.1