From 050c338ffb67283ae303f06e786a492bd88262b8 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Jan 2025 14:29:13 +0100 Subject: [PATCH 01/10] feat: refs #8387 crudModel --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 5 +++-- modules/item/back/models/item-tag.js | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 80da13ae59..e6b7b98c13 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -250,5 +250,6 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fcee0e1119..93ba0d59a8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,5 +398,6 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" -} + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 5b71639130..338ef64cff 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -10,4 +10,27 @@ module.exports = Self => { return new UserError(`Tag value cannot be blank`); return err; }); + + Self.observe('before save', async ctx => { + const validValue = new RegExp('^\\d{1,3}(-\\d{1,3})?$'); + let tagFk; + let value; + + if (ctx.isNewInstance) { + tagFk = ctx.instance.tagFk; + value = ctx.instance.value; + } + const newData = ctx.data.value || null; + const currentData = ctx.currentInstance.value || null; + const models = Self.app.models; + const validTag = await models.Tag.findOne({where: {name: 'Longitud(cm)'}}); + + if (tagFk === validTag.id || (currentData && currentData === validTag.id)) { + if ( + (value && !validValue.test(value)) || + (newData && !validValue.test(newData)) + ) + throw new UserError('The value must be a number or a range of numbers'); + } + }); }; From 6fd8c5ded6816c4437bd833af98de12d7ddc837b Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Jan 2025 14:33:32 +0100 Subject: [PATCH 02/10] feat: refs #8387 fix --- loopback/locale/en.json | 5 ++--- loopback/locale/es.json | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e6b7b98c13..2e25408c62 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -250,6 +250,5 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 93ba0d59a8..57aa2845a6 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,6 +398,5 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "There are tickets to be invoiced": "La zona tiene tickets por facturar" +} From 93c9ef6f4cbb3e4b2d752019e4b374fefe09eb23 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 15 Jan 2025 10:25:21 +0100 Subject: [PATCH 03/10] feat: refs #8387 changes --- loopback/locale/en.json | 7 ++++--- loopback/locale/es.json | 5 +++-- modules/item/back/models/item-tag.js | 14 ++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 8d5eab4bc5..4fe11c2b69 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -211,7 +211,7 @@ "Name should be uppercase": "Name should be uppercase", "You cannot update these fields": "You cannot update these fields", "CountryFK cannot be empty": "Country cannot be empty", - "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", + "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", "You are not allowed to modify the alias": "You are not allowed to modify the alias", "You already have the mailAlias": "You already have the mailAlias", "This machine is already in use.": "This machine is already in use.", @@ -251,5 +251,6 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" -} + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5558c09640..9a24f84ba2 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,5 +398,6 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" -} + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 338ef64cff..4c1ef4d4ac 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -19,17 +19,15 @@ module.exports = Self => { if (ctx.isNewInstance) { tagFk = ctx.instance.tagFk; value = ctx.instance.value; + } else { + tagFk = ctx.currentInstance.tagFk; + value = ctx.data.value; } - const newData = ctx.data.value || null; - const currentData = ctx.currentInstance.value || null; const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {name: 'Longitud(cm)'}}); + const validTag = await models.Tag.findOne({where: {name: 'Longitud(m)'}}); - if (tagFk === validTag.id || (currentData && currentData === validTag.id)) { - if ( - (value && !validValue.test(value)) || - (newData && !validValue.test(newData)) - ) + if (tagFk === validTag.id) { + if ((value && !validValue.test(value))) throw new UserError('The value must be a number or a range of numbers'); } }); From c72758685584378a28e2fdd9de127fc8968cbeb6 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 11:25:03 +0100 Subject: [PATCH 04/10] feat: refs #8387 add column validationRegex --- db/versions/11419-orangeSalal/00-firstScript.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 db/versions/11419-orangeSalal/00-firstScript.sql diff --git a/db/versions/11419-orangeSalal/00-firstScript.sql b/db/versions/11419-orangeSalal/00-firstScript.sql new file mode 100644 index 0000000000..432ed70aa2 --- /dev/null +++ b/db/versions/11419-orangeSalal/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`tag` +ADD COLUMN IF NOT EXISTS `validationRegex` varchar(50) DEFAULT NULL; From 3d5bfb81da18c83910213eedf63af1a3bbdbeb4a Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:12:03 +0100 Subject: [PATCH 05/10] feat: refs #8387 regular expression all tags --- loopback/locale/es.json | 4 ++-- modules/item/back/models/item-tag.js | 10 ++++++---- modules/item/back/models/tag.json | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9a24f84ba2..6199bb1065 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -399,5 +399,5 @@ "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The value must be a number or a range of numbers": "El valor debe ser un número o un rango de números" +} diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 4c1ef4d4ac..5a81f427f3 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -12,7 +12,6 @@ module.exports = Self => { }); Self.observe('before save', async ctx => { - const validValue = new RegExp('^\\d{1,3}(-\\d{1,3})?$'); let tagFk; let value; @@ -24,10 +23,13 @@ module.exports = Self => { value = ctx.data.value; } const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {name: 'Longitud(m)'}}); + const validTag = await models.Tag.findOne({where: {id: tagFk}}); - if (tagFk === validTag.id) { - if ((value && !validValue.test(value))) + if (validTag.validationRegex) { + const regexString = validTag.validationRegex.replace(/\\\\/g, '\\'); + const validExpresion = new RegExp(regexString); + + if (value && !validExpresion.test(value)) throw new UserError('The value must be a number or a range of numbers'); } }); diff --git a/modules/item/back/models/tag.json b/modules/item/back/models/tag.json index 6c5f5c0ba1..5269b849f9 100644 --- a/modules/item/back/models/tag.json +++ b/modules/item/back/models/tag.json @@ -30,6 +30,9 @@ "mysql": { "columnName": "isQuantitatif" } + }, + "validationRegex": { + "type": "string" } }, "acls": [ From b4ac80615b7422b9f829ab92d913886f5f984b81 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:13:30 +0100 Subject: [PATCH 06/10] feat: refs #8387 fix traductions --- loopback/locale/en.json | 5 ++--- loopback/locale/es.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 4fe11c2b69..818772e401 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -251,6 +251,5 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6199bb1065..b8a43285d4 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -399,5 +399,5 @@ "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "El valor debe ser un número o un rango de números" + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" } From a40e9a547b7d96fc047ad0dd6321ec1438768082 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:40:24 +0100 Subject: [PATCH 07/10] feat: refs #8387 --- loopback/locale/es.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b8a43285d4..5558c09640 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,6 +398,5 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" + "There are tickets to be invoiced": "La zona tiene tickets por facturar" } From 5ff27de72c20ee2e7b9800c75c9117599ca59f9e Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:42:12 +0100 Subject: [PATCH 08/10] feat: refs #8387 --- loopback/locale/es.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5558c09640..fc2b89caad 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -397,6 +397,5 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", - "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" + "Price cannot be blank": "Price cannot be blank" } From 3c89ea0df8e225bdbf4a9ec065114d4c66ec73b7 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 14:12:14 +0100 Subject: [PATCH 09/10] fix: refs #8387 local/es.json --- loopback/locale/es.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fc2b89caad..23a40a9fb3 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -397,5 +397,8 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", - "Price cannot be blank": "Price cannot be blank" + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", + "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", + "Price cannot be blank": "El precio no puede estar en blanco" } From 1f6779d86b2837e22f1165b4935eb92ac4b23720 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 Jan 2025 08:59:33 +0100 Subject: [PATCH 10/10] feat: refs #8387 change request --- modules/item/back/models/item-tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 5a81f427f3..2cd2e5f9bf 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -23,7 +23,7 @@ module.exports = Self => { value = ctx.data.value; } const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {id: tagFk}}); + const validTag = await models.Tag.findById(tagFk); if (validTag.validationRegex) { const regexString = validTag.validationRegex.replace(/\\\\/g, '\\');