From ccfd8fad058b0f75deea374a7536a64974495a86 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 11 Sep 2023 12:32:46 +0200 Subject: [PATCH 01/15] refs #6213 fixCreateError --- .../233801/00-supplierAccountCheckLength.sql | 1 + loopback/locale/es.json | 10 ++++++---- modules/supplier/back/models/supplier.js | 17 +++++++++++++++++ modules/supplier/front/create/index.html | 1 - modules/supplier/front/create/index.js | 1 + 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 db/changes/233801/00-supplierAccountCheckLength.sql diff --git a/db/changes/233801/00-supplierAccountCheckLength.sql b/db/changes/233801/00-supplierAccountCheckLength.sql new file mode 100644 index 000000000..99f571ba1 --- /dev/null +++ b/db/changes/233801/00-supplierAccountCheckLength.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier ADD CONSTRAINT supplier_CHECK CHECK (LENGTH(account) = 10); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index ccd63e0ff..6388c01a4 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -216,6 +216,7 @@ "The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día", "The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día", "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", + "The account size must be exactly 10 characters": "El tamaño de la cuenta debe ser exactamente de 10 caracteres", "Can't transfer claimed sales": "No puedes transferir lineas reclamadas", "You don't have privileges to create refund": "No tienes permisos para crear un abono", "The item is required": "El artículo es requerido", @@ -307,14 +308,15 @@ "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", "You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado", "This ticket cannot be left empty.": "Este ticket no se puede dejar vacío. %s", - "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", + "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado", "You don't have enough privileges.": "No tienes suficientes permisos.", "This ticket is locked.": "Este ticket está bloqueado.", "This ticket is not editable.": "Este ticket no es editable.", "The ticket doesn't exist.": "No existe el ticket.", - "Social name should be uppercase": "La razón social debe ir en mayúscula", + "Social name should be uppercase": "La razón social debe ir en mayúscula", "Street should be uppercase": "La dirección fiscal debe ir en mayúscula", - "Ticket without Route": "Ticket sin ruta" -} + "Ticket without Route": "Ticket sin ruta", + "The account size must be exactly 10 characters": "The account size must be exactly 10 characters" +} \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 96042c9a0..28e53e3c5 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -112,9 +112,26 @@ module.exports = Self => { const hasChanges = orgData && changes; const isPayMethodCheckedChanged = hasChanges && orgData.isPayMethodChecked != isPayMethodChecked; + const isAccountChanged = hasChanges && orgData.account != changes.account; if (!editPayMethodCheck && isPayMethodCheckedChanged) throw new UserError('You can not modify is pay method checked'); + + if (isAccountChanged && !(changes.account.length === 10)) + throw new UserError('The account size must be exactly 10 characters'); + }); + + Self.observe('after save', async function(ctx) { + if (ctx.instance && ctx.isNewInstance) { + const supplierId = ctx.instance.id; + const models = Self.app.models; + + const supplier = await models.Supplier.findById(supplierId); + await supplier.updateAttribute( + 'account', + supplierId.toString().padStart(10, '0') + ); + } }); Self.validateAsync('name', 'countryFk', hasSupplierSameName, { diff --git a/modules/supplier/front/create/index.html b/modules/supplier/front/create/index.html index c3efcf6ae..eb6e7261e 100644 --- a/modules/supplier/front/create/index.html +++ b/modules/supplier/front/create/index.html @@ -18,7 +18,6 @@ Date: Mon, 11 Sep 2023 12:36:42 +0200 Subject: [PATCH 02/15] refs #6213 remove console log --- modules/supplier/front/create/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/supplier/front/create/index.js b/modules/supplier/front/create/index.js index f11df2884..c33367dac 100644 --- a/modules/supplier/front/create/index.js +++ b/modules/supplier/front/create/index.js @@ -4,7 +4,6 @@ import Section from 'salix/components/section'; class Controller extends Section { constructor($element, $) { super($element, $); - console.log($.name); } onSubmit() { From 6a753d26af5573c910732be2dc1f190f2b56ca8c Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 11 Sep 2023 18:28:47 +0200 Subject: [PATCH 03/15] refs #6213 default account value --- db/changes/233801/00-supplierAccountCheckLength.sql | 8 +++++++- modules/supplier/back/models/supplier.js | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/db/changes/233801/00-supplierAccountCheckLength.sql b/db/changes/233801/00-supplierAccountCheckLength.sql index 99f571ba1..30ff739b8 100644 --- a/db/changes/233801/00-supplierAccountCheckLength.sql +++ b/db/changes/233801/00-supplierAccountCheckLength.sql @@ -1 +1,7 @@ -ALTER TABLE vn.supplier ADD CONSTRAINT supplier_CHECK CHECK (LENGTH(account) = 10); + +UPDATE `vn`.`supplier` + SET account = LPAD(id,10,'0') + WHERE account IS NULL; + +ALTER TABLE `vn`.`supplier` ADD CONSTRAINT supplierAccountTooShort CHECK (LENGTH(account) = 10); +ALTER TABLE vn.supplier MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.'; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 28e53e3c5..6bfec86d1 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -112,13 +112,9 @@ module.exports = Self => { const hasChanges = orgData && changes; const isPayMethodCheckedChanged = hasChanges && orgData.isPayMethodChecked != isPayMethodChecked; - const isAccountChanged = hasChanges && orgData.account != changes.account; if (!editPayMethodCheck && isPayMethodCheckedChanged) throw new UserError('You can not modify is pay method checked'); - - if (isAccountChanged && !(changes.account.length === 10)) - throw new UserError('The account size must be exactly 10 characters'); }); Self.observe('after save', async function(ctx) { @@ -126,10 +122,11 @@ module.exports = Self => { const supplierId = ctx.instance.id; const models = Self.app.models; - const supplier = await models.Supplier.findById(supplierId); + const supplier = await models.Supplier.findById(supplierId, null, ctx.options); await supplier.updateAttribute( 'account', - supplierId.toString().padStart(10, '0') + supplier.account + supplierId, + ctx.options ); } }); From f82af979ed5511e893c60651f2c1987892b31987 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 13 Sep 2023 16:54:50 +0200 Subject: [PATCH 04/15] refs #6213 fixTraductionFile --- 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 6388c01a4..f568b9a58 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -317,6 +317,5 @@ "The ticket doesn't exist.": "No existe el ticket.", "Social name should be uppercase": "La razón social debe ir en mayúscula", "Street should be uppercase": "La dirección fiscal debe ir en mayúscula", - "Ticket without Route": "Ticket sin ruta", - "The account size must be exactly 10 characters": "The account size must be exactly 10 characters" + "Ticket without Route": "Ticket sin ruta" } \ No newline at end of file From 7ab8cb37cd4b2a34c3899ccfafac3a5c22e8d33f Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 13 Sep 2023 19:22:21 +0200 Subject: [PATCH 05/15] ref #6213 fixformat --- modules/supplier/back/models/supplier.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 6bfec86d1..0337fe9db 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -119,15 +119,12 @@ module.exports = Self => { Self.observe('after save', async function(ctx) { if (ctx.instance && ctx.isNewInstance) { - const supplierId = ctx.instance.id; - const models = Self.app.models; + const {id} = ctx.instance; + const {Supplier} = Self.app.models; - const supplier = await models.Supplier.findById(supplierId, null, ctx.options); - await supplier.updateAttribute( - 'account', - supplier.account + supplierId, - ctx.options - ); + const supplier = await Supplier.findById(id, null, ctx.options); + if (supplier) + await supplier.updateAttribute('account', `${supplier.account}${id}`, ctx.options); } }); From a44e5206a7f2701f9195fd9af64ae3a538c342c1 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 14 Sep 2023 14:18:00 +0200 Subject: [PATCH 06/15] refs #6213 fixConcatBug --- modules/supplier/back/models/supplier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 0337fe9db..273c8c816 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -124,7 +124,7 @@ module.exports = Self => { const supplier = await Supplier.findById(id, null, ctx.options); if (supplier) - await supplier.updateAttribute('account', `${supplier.account}${id}`, ctx.options); + await supplier.updateAttribute('account', Number(supplier.account) + id, ctx.options); } }); From 55b53c86c436ca42f76a34c045dc9f961303106a Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 18 Sep 2023 07:38:30 +0200 Subject: [PATCH 07/15] refs #6213 formatfix --- modules/supplier/back/models/supplier.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 273c8c816..5cf357c13 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -123,8 +123,7 @@ module.exports = Self => { const {Supplier} = Self.app.models; const supplier = await Supplier.findById(id, null, ctx.options); - if (supplier) - await supplier.updateAttribute('account', Number(supplier.account) + id, ctx.options); + await supplier?.updateAttribute('account', Number(supplier.account) + id, ctx.options); } }); From cdf0951a1b9106015ffcf187d4c3da96e2e889d6 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 18 Sep 2023 10:12:32 +0200 Subject: [PATCH 08/15] refs #6213 newSuplierSpec --- .../back/models/specs/supplier.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index f317f1fb9..d75c80558 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -124,4 +124,22 @@ describe('loopback model Supplier', () => { } }); }); + + describe('after save observer', () => { + fit('should update the account attribute when a new supplier is created', async() => { + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; + + try { + const newSupplier = await models.Supplier.create({id: '6969', name: 'Alfred Pennyworth'}, options); + const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options); + + expect(fetchedSupplier.account).toEqual('4100006969'); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + }); }); From 361c2b4cad3cfccaddb2d012055ecd72ed10a77d Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 19 Sep 2023 07:33:27 +0200 Subject: [PATCH 09/15] refs #6213 fixSpec --- .../{233801 => 234001}/00-supplierAccountCheckLength.sql | 0 modules/supplier/back/models/specs/supplier.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename db/changes/{233801 => 234001}/00-supplierAccountCheckLength.sql (100%) diff --git a/db/changes/233801/00-supplierAccountCheckLength.sql b/db/changes/234001/00-supplierAccountCheckLength.sql similarity index 100% rename from db/changes/233801/00-supplierAccountCheckLength.sql rename to db/changes/234001/00-supplierAccountCheckLength.sql diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index d75c80558..043399dc9 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -126,12 +126,12 @@ describe('loopback model Supplier', () => { }); describe('after save observer', () => { - fit('should update the account attribute when a new supplier is created', async() => { + it('should update the account attribute when a new supplier is created', async() => { const tx = await models.Supplier.beginTransaction({}); const options = {transaction: tx}; try { - const newSupplier = await models.Supplier.create({id: '6969', name: 'Alfred Pennyworth'}, options); + const newSupplier = await models.Supplier.create({id: '9999', name: 'Alfred Pennyworth'}, options); const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options); expect(fetchedSupplier.account).toEqual('4100006969'); From 971d77a198148582d8411d5eee04c34760eba906 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 19 Sep 2023 07:46:44 +0200 Subject: [PATCH 10/15] refs #6213 specChangeId --- modules/supplier/back/models/specs/supplier.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 043399dc9..9dd84d9fa 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -134,7 +134,7 @@ describe('loopback model Supplier', () => { const newSupplier = await models.Supplier.create({id: '9999', name: 'Alfred Pennyworth'}, options); const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options); - expect(fetchedSupplier.account).toEqual('4100006969'); + expect(fetchedSupplier.account).toEqual('4100009999'); await tx.rollback(); } catch (e) { await tx.rollback(); From 9b10a2904c39fd5d6931dd796bb43759a574983c Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 25 Sep 2023 08:23:23 +0200 Subject: [PATCH 11/15] refs #6213 unifyTest --- modules/supplier/back/models/specs/supplier.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 9dd84d9fa..782c5cdf0 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -123,10 +123,8 @@ describe('loopback model Supplier', () => { throw e; } }); - }); - describe('after save observer', () => { - it('should update the account attribute when a new supplier is created', async() => { + fit('should update the account attribute when a new supplier is created', async() => { const tx = await models.Supplier.beginTransaction({}); const options = {transaction: tx}; From af8773612cf1b2e8da64a88df81ee30c94fc0b69 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 25 Sep 2023 08:23:59 +0200 Subject: [PATCH 12/15] refs #6213 remove f --- modules/supplier/back/models/specs/supplier.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 782c5cdf0..3db273a95 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -124,7 +124,7 @@ describe('loopback model Supplier', () => { } }); - fit('should update the account attribute when a new supplier is created', async() => { + it('should update the account attribute when a new supplier is created', async() => { const tx = await models.Supplier.beginTransaction({}); const options = {transaction: tx}; From 96769d9ff9b178a01679329d87f84d0032bb71cc Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 3 Oct 2023 08:57:59 +0200 Subject: [PATCH 13/15] refs #6213 fixIntermitentError --- .../{234001 => 234201}/00-supplierAccountCheckLength.sql | 0 e2e/helpers/tests.js | 9 +++++++++ .../back/methods/supplier/specs/newSupplier.spec.js | 1 + modules/supplier/back/models/specs/supplier.spec.js | 4 ++-- 4 files changed, 12 insertions(+), 2 deletions(-) rename db/changes/{234001 => 234201}/00-supplierAccountCheckLength.sql (100%) diff --git a/db/changes/234001/00-supplierAccountCheckLength.sql b/db/changes/234201/00-supplierAccountCheckLength.sql similarity index 100% rename from db/changes/234001/00-supplierAccountCheckLength.sql rename to db/changes/234201/00-supplierAccountCheckLength.sql diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index 992ec051f..718b49834 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -52,6 +52,15 @@ async function test() { await backendStatus(); jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; + const myReporter = { + specDone: function(result) { + for (const expectation of result.failedExpectations) { + console.warn('SpecFailed: ' + result.description); + console.warn('Failure: ' + expectation.message); + } + } + }; + jasmine.addReporter(myReporter); await jasmine.execute(); } diff --git a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js index c368ec1b8..5fc2ea752 100644 --- a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js +++ b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js @@ -32,6 +32,7 @@ describe('Supplier newSupplier()', () => { const result = await models.Supplier.newSupplier(ctx, options); expect(result.name).toEqual('newSupplier'); + await tx.rollback(); } catch (e) { await tx.rollback(); throw e; diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 3db273a95..fbd3a00db 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -129,10 +129,10 @@ describe('loopback model Supplier', () => { const options = {transaction: tx}; try { - const newSupplier = await models.Supplier.create({id: '9999', name: 'Alfred Pennyworth'}, options); + const newSupplier = await models.Supplier.create({name: 'Alfred Pennyworth'}, options); const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options); - expect(fetchedSupplier.account).toEqual('4100009999'); + expect(Number(fetchedSupplier.account)).toEqual(4100000000 + newSupplier.id); await tx.rollback(); } catch (e) { await tx.rollback(); From e14049a082b485bce185797318704a415d2f67f6 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 4 Oct 2023 07:48:00 +0200 Subject: [PATCH 14/15] refs #6213 fixJasmineConfiguration --- e2e/helpers/tests.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index 718b49834..992ec051f 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -52,15 +52,6 @@ async function test() { await backendStatus(); jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; - const myReporter = { - specDone: function(result) { - for (const expectation of result.failedExpectations) { - console.warn('SpecFailed: ' + result.description); - console.warn('Failure: ' + expectation.message); - } - } - }; - jasmine.addReporter(myReporter); await jasmine.execute(); } From 90fe65acc244fabd2c910bfe109ac00b408d6afc Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 6 Oct 2023 08:03:37 +0200 Subject: [PATCH 15/15] refs #6213 fixChanges --- db/changes/234201/00-supplierAccountCheckLength.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/changes/234201/00-supplierAccountCheckLength.sql b/db/changes/234201/00-supplierAccountCheckLength.sql index 30ff739b8..55a68e37b 100644 --- a/db/changes/234201/00-supplierAccountCheckLength.sql +++ b/db/changes/234201/00-supplierAccountCheckLength.sql @@ -1,7 +1,6 @@ - UPDATE `vn`.`supplier` SET account = LPAD(id,10,'0') WHERE account IS NULL; ALTER TABLE `vn`.`supplier` ADD CONSTRAINT supplierAccountTooShort CHECK (LENGTH(account) = 10); -ALTER TABLE vn.supplier MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.'; +ALTER TABLE `vn`.`supplier` MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.';