From b51710fb310a998a65c3bb03968bfe6e1d971509 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 3 Apr 2023 15:44:12 +0200 Subject: [PATCH 001/100] refs #5525 mod yml y sql --- db/changes/231401/00-accountCountry.sql | 10 ++++++++++ print/templates/reports/sepa-core/locale/es.yml | 2 ++ print/templates/reports/sepa-core/locale/fr.yml | 2 ++ print/templates/reports/sepa-core/sepa-core.html | 4 ++-- print/templates/reports/sepa-core/sepa-core.js | 5 +++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 db/changes/231401/00-accountCountry.sql diff --git a/db/changes/231401/00-accountCountry.sql b/db/changes/231401/00-accountCountry.sql new file mode 100644 index 000000000..73c21f0b2 --- /dev/null +++ b/db/changes/231401/00-accountCountry.sql @@ -0,0 +1,10 @@ +-- vn.accountCountry definition + +CREATE TABLE `accountCountry` in `vn` ( + `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, + `countryFk` mediumint(8) unsigned DEFAULT NULL, + KEY `supplierAccountFk` (`supplierAccountFk`), + KEY `countryFk` (`countryFk`), + CONSTRAINT `accountCountry_ibfk_1` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`), + CONSTRAINT `accountCountry_ibfk_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/print/templates/reports/sepa-core/locale/es.yml b/print/templates/reports/sepa-core/locale/es.yml index 5f3f08fc3..ebb8dce1a 100644 --- a/print/templates/reports/sepa-core/locale/es.yml +++ b/print/templates/reports/sepa-core/locale/es.yml @@ -17,6 +17,8 @@ supplier: toCompleteBySupplier: A cumplimentar por el acreedor orderReference: Referencia de la orden de domiciliación identifier: Identificador del acreedor + iban: ES89000B97367486 + cif: B97367486-000 name: Nombre del acreedor street: Dirección location: CP - Población - Provincia diff --git a/print/templates/reports/sepa-core/locale/fr.yml b/print/templates/reports/sepa-core/locale/fr.yml index 354c06114..3f39d18d4 100644 --- a/print/templates/reports/sepa-core/locale/fr.yml +++ b/print/templates/reports/sepa-core/locale/fr.yml @@ -13,6 +13,8 @@ sendOrder: APRÈS SIGNATURA, RENVOYER AU CRÉANCIER ET AU VOTRE ÉTABLISSEMENT F supplier: toCompleteBySupplier: Á compléter pour le créancier orderReference: Numéro de référence du mandat + iban: FR7630003012690002801121597 + cif: B97367486-000 identifier: Identifiant créancier name: Nom du céancier street: Adresse diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index a8c270ad5..defbdb110 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -27,8 +27,8 @@ {{$t('supplier.identifier')}} -
ES89000B97367486
-
B97367486-000
+
{{$t('supplier.iban')}}
+
{{$t('supplier.cif')}}
diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 0e19d2a6a..2198984f3 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -1,5 +1,10 @@ const vnReport = require('../../../core/mixins/vn-report.js'); +// class Controller { +// constructor(country, supplier, iban, cif) { +// this.country = countryFk; +// } +// } module.exports = { name: 'sepa-core', mixins: [vnReport], -- 2.40.1 From 95602895df87beb59bc2075bee83487f8e15ebc1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 14:40:02 +0200 Subject: [PATCH 002/100] refs #5525 update changes --- db/changes/{231401 => 231601}/00-accountCountry.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/changes/{231401 => 231601}/00-accountCountry.sql (91%) diff --git a/db/changes/231401/00-accountCountry.sql b/db/changes/231601/00-accountCountry.sql similarity index 91% rename from db/changes/231401/00-accountCountry.sql rename to db/changes/231601/00-accountCountry.sql index 73c21f0b2..05e9d83f1 100644 --- a/db/changes/231401/00-accountCountry.sql +++ b/db/changes/231601/00-accountCountry.sql @@ -1,6 +1,6 @@ -- vn.accountCountry definition -CREATE TABLE `accountCountry` in `vn` ( +CREATE TABLE `vn`.`accountCountry` ( `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, KEY `supplierAccountFk` (`supplierAccountFk`), -- 2.40.1 From 790de4f05f1645ca087f3c4f56bdf5f3d83dc9f5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 25 May 2023 13:08:24 +0200 Subject: [PATCH 003/100] refs #5525 trad fr pt --- .../email/letter-debtor-nd/locale/fr.yml | 26 +++++++++++++++++++ .../email/letter-debtor-nd/locale/pt.yml | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 print/templates/email/letter-debtor-nd/locale/fr.yml create mode 100644 print/templates/email/letter-debtor-nd/locale/pt.yml diff --git a/print/templates/email/letter-debtor-nd/locale/fr.yml b/print/templates/email/letter-debtor-nd/locale/fr.yml new file mode 100644 index 000000000..3ea3501d7 --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/fr.yml @@ -0,0 +1,26 @@ +subject: Réitération de l'avis de solde débiteur +title: Avis réitéré +sections: + introduction: + title: Cher client + description: Nous vous écrivons à nouveau pour vous informer qu'il est toujours en attente + votre dette envers notre société, comme vous pouvez le voir dans le relevé ci-joint. + terms: Étant donné que les délais de paiement convenus sont largement dépassés, il n'est pas approprié + retard plus important dans le règlement du montant dû. + payMethod: + description: Pour cela, vous disposez des modes de paiement suivants + options: + - Paiement en ligne depuis notre site internet. + - Revenu ou virement sur le numéro de compte que nous détaillons en bas de ce courrier, + indiquant le numéro de client. + legalAction: + description: Si cette obligation de paiement n'est pas remplie, nous serons contraints de + d'engager les actions judiciaires qui se déroulent, parmi lesquelles + options: + - Inclusion dans les dossiers négatifs sur la solvabilité financière et le crédit. + - Réclamation judiciaire. + - Cession de créance à une société de gestion de recouvrement. +contactPhone: Pour toute demande, vous pouvez nous contacter au 96 + 324 21 00. +conclusion: En attente de vos nouvelles.
Merci pour ton attention. +transferAccount: Données pour virement bancaire \ No newline at end of file diff --git a/print/templates/email/letter-debtor-nd/locale/pt.yml b/print/templates/email/letter-debtor-nd/locale/pt.yml new file mode 100644 index 000000000..f4acbd1d3 --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/pt.yml @@ -0,0 +1,26 @@ +subject: Reiteração de aviso de saldo devedor +title: Aviso reiterado +sections: + introduction: + title: Estimado cliente + description: Estamos escrevendo para você novamente para informar que ainda está pendente + sua dívida para com nossa empresa, conforme demonstrativo anexo. + terms: Dado que os prazos de pagamento acordados são largamente excedidos, não é adequado + maior atraso na liquidação do valor devido. + payMethod: + description: Para isso você tem as seguintes formas de pagamento + options: + - Pagamento online em nosso site. + - Renda ou transferência para o número da conta que detalhamos no final desta carta, + indicando o número do cliente. + legalAction: + description: Se esta obrigação de pagamento não for cumprida, seremos obrigados a + para iniciar as ações legais que procedem, entre as quais estão + options: + - Inclusão em processos negativos de solvência financeira e de crédito. + - Reivindicação judicial. + - Cessão de dívida a uma empresa de gestão de cobranças. +contactPhone: Para consultas, você pode entrar em contato conosco em 96 + 324 21 00. +conclusion: Aguardando suas notícias.
Agradecimentos para sua atenção. +transferAccount: Dados para transferência bancária \ No newline at end of file -- 2.40.1 From de7b270d9e6528f29d768a90b9a091fa4c0a5401 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 9 Jun 2023 11:24:51 +0200 Subject: [PATCH 004/100] refs #5525 sql --- db/changes/231801/00-accountCountry.sql | 10 ---------- db/changes/232601/00-accountCountry.sql | 13 +++++++++++++ db/changes/232601/00-supplierDefault.sql | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) delete mode 100644 db/changes/231801/00-accountCountry.sql create mode 100644 db/changes/232601/00-accountCountry.sql create mode 100644 db/changes/232601/00-supplierDefault.sql diff --git a/db/changes/231801/00-accountCountry.sql b/db/changes/231801/00-accountCountry.sql deleted file mode 100644 index 05e9d83f1..000000000 --- a/db/changes/231801/00-accountCountry.sql +++ /dev/null @@ -1,10 +0,0 @@ --- vn.accountCountry definition - -CREATE TABLE `vn`.`accountCountry` ( - `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, - `countryFk` mediumint(8) unsigned DEFAULT NULL, - KEY `supplierAccountFk` (`supplierAccountFk`), - KEY `countryFk` (`countryFk`), - CONSTRAINT `accountCountry_ibfk_1` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`), - CONSTRAINT `accountCountry_ibfk_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/changes/232601/00-accountCountry.sql b/db/changes/232601/00-accountCountry.sql new file mode 100644 index 000000000..f92abd9df --- /dev/null +++ b/db/changes/232601/00-accountCountry.sql @@ -0,0 +1,13 @@ +-- vn.supplierAccountContry definition + +CREATE TABLE `supplierAccountCountry` ( + `supplierAccountFk` mediumint(8) unsigned NOT NULL, + `companyFk` int(11) DEFAULT NULL, + `countryFk` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`supplierAccountFk`), + UNIQUE KEY `countryFk` (`countryFk`), + UNIQUE KEY `companyFk` (`companyFk`), + CONSTRAINT `companyFk_supplier` FOREIGN KEY (`companyFk`) REFERENCES `supplierAccount` (`supplierFk`) ON UPDATE CASCADE, + CONSTRAINT `countryFk_id` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccountFk_id` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/changes/232601/00-supplierDefault.sql b/db/changes/232601/00-supplierDefault.sql new file mode 100644 index 000000000..c411558f1 --- /dev/null +++ b/db/changes/232601/00-supplierDefault.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier ADD defaultAccountFk varchar(100) DEFAULT NULL NULL; -- 2.40.1 From b8f0b205db1b9e732a43d05c826f1e963bf4e5b2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 28 Jun 2023 06:53:42 +0200 Subject: [PATCH 005/100] refs #5525 move sql --- db/changes/{232601 => 232801}/00-accountCountry.sql | 0 db/changes/{232601 => 232801}/00-supplierDefault.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{232601 => 232801}/00-accountCountry.sql (100%) rename db/changes/{232601 => 232801}/00-supplierDefault.sql (100%) diff --git a/db/changes/232601/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql similarity index 100% rename from db/changes/232601/00-accountCountry.sql rename to db/changes/232801/00-accountCountry.sql diff --git a/db/changes/232601/00-supplierDefault.sql b/db/changes/232801/00-supplierDefault.sql similarity index 100% rename from db/changes/232601/00-supplierDefault.sql rename to db/changes/232801/00-supplierDefault.sql -- 2.40.1 From 0a78dd344fab7f8fbb77a3c6240db0d6b77db723 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 29 Jun 2023 06:24:13 +0200 Subject: [PATCH 006/100] refs #5525 sql --- db/changes/232801/00-accountCountry.sql | 38 ++++++++++++++++-------- db/changes/232801/00-supplierDefault.sql | 1 - 2 files changed, 25 insertions(+), 14 deletions(-) delete mode 100644 db/changes/232801/00-supplierDefault.sql diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql index f92abd9df..d44cdcc4e 100644 --- a/db/changes/232801/00-accountCountry.sql +++ b/db/changes/232801/00-accountCountry.sql @@ -1,13 +1,25 @@ --- vn.supplierAccountContry definition - -CREATE TABLE `supplierAccountCountry` ( - `supplierAccountFk` mediumint(8) unsigned NOT NULL, - `companyFk` int(11) DEFAULT NULL, - `countryFk` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`supplierAccountFk`), - UNIQUE KEY `countryFk` (`countryFk`), - UNIQUE KEY `companyFk` (`companyFk`), - CONSTRAINT `companyFk_supplier` FOREIGN KEY (`companyFk`) REFERENCES `supplierAccount` (`supplierFk`) ON UPDATE CASCADE, - CONSTRAINT `countryFk_id` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccountFk_id` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +CREATE TABLE `supplierAccount` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `supplierFk` int(11) DEFAULT NULL, + `iban` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `office` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `DC` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `number` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `description__` varchar(45) DEFAULT NULL COMMENT '@deprecated 2023-03-23', + `bankEntityFk` int(10) unsigned DEFAULT NULL, + `accountingFk` int(11) DEFAULT NULL, + `beneficiary` varchar(50) DEFAULT NULL, + `editorFk` int(10) unsigned DEFAULT NULL, + `countryFk` int(10) unsigned UNIQUE KEY, + `companyFk` int(10) unsigned UNIQUE KEY, + PRIMARY KEY (`id`), + KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), + KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), + KEY `fk_banco_prov_account_idx` (`accountingFk`), + KEY `supplierAccount_fk_editor` (`editorFk`), + CONSTRAINT `supplierAccount_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccount_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), + CONSTRAINT `supplierAccount_FK_country` FOREIGN KEY (`countryFk`) REFERENCES `vn`.`country` (`id`), + CONSTRAINT `supplierAccount_FK_company` FOREIGN KEY (`companyFk`) REFERENCES `vn`.`company` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=242 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/changes/232801/00-supplierDefault.sql b/db/changes/232801/00-supplierDefault.sql deleted file mode 100644 index c411558f1..000000000 --- a/db/changes/232801/00-supplierDefault.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.supplier ADD defaultAccountFk varchar(100) DEFAULT NULL NULL; -- 2.40.1 From f3a40dfb231f5e23b9535080ffdbae36652753a2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 29 Jun 2023 06:33:50 +0200 Subject: [PATCH 007/100] refs #5525 comment --- db/changes/232801/00-accountCountry.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql index d44cdcc4e..9f16b9b00 100644 --- a/db/changes/232801/00-accountCountry.sql +++ b/db/changes/232801/00-accountCountry.sql @@ -10,7 +10,7 @@ CREATE TABLE `supplierAccount` ( `accountingFk` int(11) DEFAULT NULL, `beneficiary` varchar(50) DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, - `countryFk` int(10) unsigned UNIQUE KEY, + `countryFk` int(10) unsigned UNIQUE KEY COMMENT 'Cuenta por defecto para ingresos desde esta empresa', `companyFk` int(10) unsigned UNIQUE KEY, PRIMARY KEY (`id`), KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), -- 2.40.1 From c453935ddd8bc6beb2d0d334f318a6e7e13073d5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 11 Jul 2023 06:38:44 +0200 Subject: [PATCH 008/100] refs #5525 sql --- db/.archive/231001/00-supplier.sql | 3 +++ print/templates/email/letter-debtor-st/letter-debtor-st.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/.archive/231001/00-supplier.sql diff --git a/db/.archive/231001/00-supplier.sql b/db/.archive/231001/00-supplier.sql new file mode 100644 index 000000000..fccc35ba3 --- /dev/null +++ b/db/.archive/231001/00-supplier.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; +ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); +ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.html b/print/templates/email/letter-debtor-st/letter-debtor-st.html index 36f300c98..6679567c0 100644 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.html +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.html @@ -28,4 +28,4 @@ - \ No newline at end of file + -- 2.40.1 From 5b5191a6a5e0bd79666752556de0025d3d06a1d4 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 11 Jul 2023 13:49:39 +0200 Subject: [PATCH 009/100] refs #5525 findOne sql --- .../231001 => changes/233001}/00-supplier.sql | 0 .../email/letter-debtor-st/letter-debtor-st.js | 12 ++++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) rename db/{.archive/231001 => changes/233001}/00-supplier.sql (100%) diff --git a/db/.archive/231001/00-supplier.sql b/db/changes/233001/00-supplier.sql similarity index 100% rename from db/.archive/231001/00-supplier.sql rename to db/changes/233001/00-supplier.sql diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index e0a690f81..5d93116af 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -1,14 +1,18 @@ const Component = require(`vn-print/core/component`); const emailBody = new Component('email-body'); const attachment = new Component('attachment'); +const db = require('../../../core/database'); module.exports = { name: 'letter-debtor-st', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.id, this.companyId); - - if (!this.debtor) - throw new Error('Something went wrong'); + this.debtor = await db.findOne(` + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + [this.id]); }, data() { return { -- 2.40.1 From cc6ffff018842fc4c28539b4ba1e437ff8ce44ab Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 19 Jul 2023 07:14:01 +0200 Subject: [PATCH 010/100] refs #5525 nd debtor --- db/changes/232801/00-accountCountry.sql | 25 ------------------- .../letter-debtor-nd/letter-debtor-nd.js | 12 ++++++--- 2 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 db/changes/232801/00-accountCountry.sql diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql deleted file mode 100644 index 9f16b9b00..000000000 --- a/db/changes/232801/00-accountCountry.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE `supplierAccount` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `supplierFk` int(11) DEFAULT NULL, - `iban` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `office` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `DC` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `number` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `description__` varchar(45) DEFAULT NULL COMMENT '@deprecated 2023-03-23', - `bankEntityFk` int(10) unsigned DEFAULT NULL, - `accountingFk` int(11) DEFAULT NULL, - `beneficiary` varchar(50) DEFAULT NULL, - `editorFk` int(10) unsigned DEFAULT NULL, - `countryFk` int(10) unsigned UNIQUE KEY COMMENT 'Cuenta por defecto para ingresos desde esta empresa', - `companyFk` int(10) unsigned UNIQUE KEY, - PRIMARY KEY (`id`), - KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), - KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), - KEY `fk_banco_prov_account_idx` (`accountingFk`), - KEY `supplierAccount_fk_editor` (`editorFk`), - CONSTRAINT `supplierAccount_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccount_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), - CONSTRAINT `supplierAccount_FK_country` FOREIGN KEY (`countryFk`) REFERENCES `vn`.`country` (`id`), - CONSTRAINT `supplierAccount_FK_company` FOREIGN KEY (`companyFk`) REFERENCES `vn`.`company` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=242 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 54ed9fed6..2f4a25cfe 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -1,14 +1,18 @@ const Component = require(`vn-print/core/component`); const emailBody = new Component('email-body'); const attachment = new Component('attachment'); +const db = require('../../../core/database'); module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.id, this.companyId); - - if (!this.debtor) - throw new Error('Something went wrong'); + this.debtor = await db.findOne(` + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + [this.id]); }, data() { return { -- 2.40.1 From 2f9979046d66725ea9a33dc10ba489324e82df51 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 26 Jul 2023 13:10:18 +0200 Subject: [PATCH 011/100] refs #5525 iban --- .../templates/reports/sepa-core/sepa-core.html | 2 +- print/templates/reports/sepa-core/sepa-core.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index defbdb110..1b2ad13d9 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -28,7 +28,7 @@ {{$t('supplier.identifier')}}
{{$t('supplier.iban')}}
-
{{$t('supplier.cif')}}
+
{{supplier.nif}}
diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 2198984f3..efc9ed7ed 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -1,10 +1,6 @@ const vnReport = require('../../../core/mixins/vn-report.js'); +const db = require('../../../core/database'); -// class Controller { -// constructor(country, supplier, iban, cif) { -// this.country = countryFk; -// } -// } module.exports = { name: 'sepa-core', mixins: [vnReport], @@ -12,6 +8,7 @@ module.exports = { this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); this.checkMainEntity(this.client); this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); + console.log(this.supplier); }, props: { id: { @@ -23,5 +20,16 @@ module.exports = { type: Number, required: true } + }, + methods: { + getSupplierCif() { + return db.findOne(` + SELECT sa.iban, s.nif + FROM supplierAccount sa + INNER JOIN supplier s ON sa.supplierFk = s.id + WHERE s.countryFk = ? + LIMIT 1`), [this.countryFk]; + } } + }; -- 2.40.1 From 344b5d984a3de6fe2484ffa5dc629c1ddaa2e99e Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Jul 2023 17:19:44 +0200 Subject: [PATCH 012/100] refs #5525 add nif iban --- .../reports/sepa-core/sepa-core.html | 2 +- .../reports/sepa-core/sql/supplier.sql | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index 1b2ad13d9..363ebdfe5 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -27,7 +27,7 @@ {{$t('supplier.identifier')}} -
{{$t('supplier.iban')}}
+
{{supplier.iban}}
{{supplier.nif}}
diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index 55b0e49ca..d93175118 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -1,17 +1,24 @@ SELECT - m.code mandateCode, - s.name, - s.street, - sc.country, - s.postCode, - s.city, - sp.name province -FROM client c - LEFT JOIN mandate m ON m.clientFk = c.id - AND m.companyFk = ? AND m.finished IS NULL + m.code AS mandateCode, + s.name, + s.street, + sc.country, + s.postCode, + s.city, + sp.name AS province, + s.nif, + sa.iban, + be.name AS bankName +FROM + client c + LEFT JOIN mandate m ON m.clientFk = c.id AND m.companyFk = ? AND m.finished IS NULL LEFT JOIN supplier s ON s.id = m.companyFk LEFT JOIN country sc ON sc.id = s.countryFk LEFT JOIN province sp ON sp.id = s.provinceFk LEFT JOIN province p ON p.id = c.provinceFk -WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? -ORDER BY m.created DESC LIMIT 1 \ No newline at end of file + LEFT JOIN bankEntity be ON sa.supplierFk = s.id + LEFT JOIN supplierAccount sa ON sa.bankEntityFk = be.id + WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk) + ORDER BY + m.created DESC + LIMIT 1; -- 2.40.1 From 5664ec3a8f97935e098a49d434d8ba46d5b53c99 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 31 Aug 2023 17:23:01 +0200 Subject: [PATCH 013/100] refs #5525 change supplier --- db/changes/{233001 => 233801}/00-supplier.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{233001 => 233801}/00-supplier.sql (100%) diff --git a/db/changes/233001/00-supplier.sql b/db/changes/233801/00-supplier.sql similarity index 100% rename from db/changes/233001/00-supplier.sql rename to db/changes/233801/00-supplier.sql -- 2.40.1 From 8678d2b1e0d451913f2d55c043c951860d854e13 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Sep 2023 17:23:31 +0200 Subject: [PATCH 014/100] refs #5525 new sql --- .../email/letter-debtor-nd/letter-debtor-nd.html | 2 +- .../templates/email/letter-debtor-st/letter-debtor-st.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html index 44a34a9b4..01bab7939 100644 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html @@ -45,4 +45,4 @@ - \ No newline at end of file + diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 5d93116af..478249b80 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,11 +7,10 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + SELECT sa.iban FROM client c + LEFT JOIN supplierAccount sa ON c.countryFk = sa.countryFk + WHERE c.id = ? + OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, [this.id]); }, data() { -- 2.40.1 From d26a73bdd98b2b3954214bde040ae508ce7834b9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Sep 2023 11:02:47 +0200 Subject: [PATCH 015/100] refs #5525 sql correct --- db/changes/233801/00-supplier.sql | 4 ++++ .../templates/email/letter-debtor-st/letter-debtor-st.js | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/233801/00-supplier.sql index fccc35ba3..5708749fd 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/233801/00-supplier.sql @@ -1,3 +1,7 @@ ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; + + + ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; +d diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 478249b80..5d0a11baf 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,10 +7,11 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban FROM client c - LEFT JOIN supplierAccount sa ON c.countryFk = sa.countryFk - WHERE c.id = ? - OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk);`, [this.id]); }, data() { -- 2.40.1 From cdc91e76f56f3306199ac06abf06c572a72c71a2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 14 Sep 2023 10:04:34 +0200 Subject: [PATCH 016/100] refs #5525 supplier sql table i18n --- db/changes/233801/00-supplier.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/233801/00-supplier.sql index 5708749fd..ad9ce892c 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/233801/00-supplier.sql @@ -1,7 +1,9 @@ -ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; - - - -ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; -d + +CREATE TABLE `vn`.`supplierAccountI18n` ( + supplierAccountFk int(10) unsigned NOT NULL, + countryFk mediumint(8) unsigned NOT NULL, + FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), + FOREIGN KEY (countryFk) REFERENCES country(id) +); + -- 2.40.1 From f4ac6f68c09cf839c7df52dfbe1061ab6e1bcda6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 20 Sep 2023 13:03:49 +0200 Subject: [PATCH 017/100] refs #5525 trad en --- .../email/letter-debtor-nd/locale/en.yml | 21 +++++++++++++++++++ .../email/letter-debtor-st/locale/en.yml | 11 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 print/templates/email/letter-debtor-nd/locale/en.yml create mode 100644 print/templates/email/letter-debtor-st/locale/en.yml diff --git a/print/templates/email/letter-debtor-nd/locale/en.yml b/print/templates/email/letter-debtor-nd/locale/en.yml new file mode 100644 index 000000000..34b1c7b5f --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/en.yml @@ -0,0 +1,21 @@ +subject: Reminder of Outstanding Balance Notice +title: Reminder Notice +sections: + introduction: + title: Dear Customer + description: We are writing to you once again to inform you that your debt with our company remains unpaid, as you can verify in the attached statement. + terms: Since the agreed payment deadlines have significantly passed, there should be no further delay in settling the outstanding amount. + payMethod: + description: To do so, you have the following payment options: + options: + - Online payment through our website. + - Deposit or transfer to the account number provided at the bottom of this letter, indicating your customer number. + legalAction: + description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include: + options: + - Inclusion in negative credit and financial solvency records. + - Legal proceedings. + - Debt assignment to a debt collection agency. +contactPhone: For inquiries, you can reach us at 96 324 21 00. +conclusion: We look forward to hearing from you.
Thank you for your attention. +transferAccount: Bank Transfer Details diff --git a/print/templates/email/letter-debtor-st/locale/en.yml b/print/templates/email/letter-debtor-st/locale/en.yml new file mode 100644 index 000000000..42b3bb504 --- /dev/null +++ b/print/templates/email/letter-debtor-st/locale/en.yml @@ -0,0 +1,11 @@ +subject: Initial Notice for Outstanding Balance +title: Initial Notice for Outstanding Balance +sections: + introduction: + title: Dear Customer + description: Through this letter, we would like to inform you that, according to our accounting records, your account has an outstanding balance that needs to be settled. +checkExtract: We kindly request you to verify that the attached statement corresponds to the information you have. Our administration department will be happy to clarify any questions you may have and provide any documents you may request. +checkValidData: If, upon reviewing the provided information, everything appears to be accurate, we kindly ask you to proceed with rectifying your situation. +payMethod: If you prefer not to visit our offices in person, you can make the payment through a bank transfer to the account listed at the bottom of this communication, indicating your customer number. Alternatively, you can make the payment online through our website. +conclusion: We sincerely appreciate your kind cooperation. +transferAccount: Bank Transfer Details -- 2.40.1 From 5dbfe31a60d129f2d076c548096f5e653050b218 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 10 Nov 2023 15:12:03 +0100 Subject: [PATCH 018/100] refs #5666 feat: define VnRole --- .vscode/settings.json | 6 ++++++ back/model-config.json | 3 +++ back/models/vn-role.json | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 back/models/vn-role.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 05d23f3bb..4c2761987 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,11 @@ "eslint.format.enable": true, "[javascript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "cSpell.words": [ + "Loggable" + ], + "[json]": { + "editor.defaultFormatter": "vscode.json-language-features" } } diff --git a/back/model-config.json b/back/model-config.json index ebc0e321b..84dd9eebd 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -142,6 +142,9 @@ "VnUser": { "dataSource": "vn" }, + "VnRole": { + "dataSource": "vn" + }, "OsTicket": { "dataSource": "osticket" }, diff --git a/back/models/vn-role.json b/back/models/vn-role.json new file mode 100644 index 000000000..e841f8a88 --- /dev/null +++ b/back/models/vn-role.json @@ -0,0 +1,13 @@ +{ + "name": "VnRole", + "base": "Role", + "validateUpsert": true, + "options": { + "mysql": { + "table": "account.role" + } + }, + "mixins": { + "RegisterLog": true + } +} -- 2.40.1 From cf3cc37d97f61372dd9072492b60ffce5ad35cfd Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 10 Nov 2023 15:12:24 +0100 Subject: [PATCH 019/100] refs #5666 feat: create mixin --- back/mixins/register-log.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 back/mixins/register-log.js diff --git a/back/mixins/register-log.js b/back/mixins/register-log.js new file mode 100644 index 000000000..555191e57 --- /dev/null +++ b/back/mixins/register-log.js @@ -0,0 +1,20 @@ + +const loggable = require('vn-loopback/util/log'); + +module.exports = function(Self, options) { + Self.once('attached', function(ctx) { + }); + + Self.observe('before save', async function(ctx, next) { + await loggable.translateValues(Self, ctx.currentInstance); + }); + + let Mixin = { + + }; + + for (let method in Mixin) { + if (!Self.prototype[method]) + Self.prototype[method] = Mixin[method]; + } +}; -- 2.40.1 From 3c5af184bbc6458ca3963b7a561b187577a1509f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 10 Nov 2023 15:12:49 +0100 Subject: [PATCH 020/100] refs #5666 feat: use mixin for this models --- back/models/vn-user.json | 3 +++ modules/account/back/models/account.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/back/models/vn-user.json b/back/models/vn-user.json index 0f6daff5a..28fca8fe8 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -7,6 +7,9 @@ "table": "account.user" } }, + "mixins": { + "RegisterLog": true + }, "resetPasswordTokenTTL": "604800", "properties": { "id": { diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 3c22521cb..3c76c85c3 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -6,6 +6,9 @@ "table": "account.account" } }, + "mixins": { + "RegisterLog": true + }, "properties": { "id": { "id": true -- 2.40.1 From a102c3f3a952da468734039c1e133e4470270842 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Nov 2023 09:53:35 +0100 Subject: [PATCH 021/100] refs #5666 perf: loggable to mixin --- loopback/common/mixins/loggable.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 loopback/common/mixins/loggable.js diff --git a/loopback/common/mixins/loggable.js b/loopback/common/mixins/loggable.js new file mode 100644 index 000000000..760fdf60a --- /dev/null +++ b/loopback/common/mixins/loggable.js @@ -0,0 +1,12 @@ +const LoopBackContext = require('loopback-context'); +async function handleObserve(ctx) { + ctx.options.httpCtx = LoopBackContext.getCurrentContext(); +} +module.exports = function(Self) { + let Mixin = { + 'before save': handleObserve, + 'before delete': handleObserve, + }; + for (const [listener, handler] of Object.entries(Mixin)) + Self.observe(listener, handler); +}; -- 2.40.1 From aab88dc7dede9b31d733b5ff647224fc3b93d3f4 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Nov 2023 09:54:12 +0100 Subject: [PATCH 022/100] refs #5666 perf: use use loggable as mixin --- back/models/vn-role.json | 2 +- back/models/vn-user.json | 2 +- loopback/common/models/loggable.json | 13 ++++++++----- modules/account/back/models/account.json | 5 +---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/back/models/vn-role.json b/back/models/vn-role.json index e841f8a88..c7d7e172b 100644 --- a/back/models/vn-role.json +++ b/back/models/vn-role.json @@ -8,6 +8,6 @@ } }, "mixins": { - "RegisterLog": true + "Loggable": true } } diff --git a/back/models/vn-user.json b/back/models/vn-user.json index 28fca8fe8..bda0a6ec3 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -8,7 +8,7 @@ } }, "mixins": { - "RegisterLog": true + "Loggable": true }, "resetPasswordTokenTTL": "604800", "properties": { diff --git a/loopback/common/models/loggable.json b/loopback/common/models/loggable.json index 9101532a3..62822d0af 100644 --- a/loopback/common/models/loggable.json +++ b/loopback/common/models/loggable.json @@ -1,5 +1,8 @@ -{ - "name": "Loggable", - "base": "VnModel", - "validateUpsert": true -} +{ + "name": "Loggable", + "base": "VnModel", + "validateUpsert": true, + "mixins": { + "Loggable": true + } +} diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 3c76c85c3..3e4371604 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -6,10 +6,7 @@ "table": "account.account" } }, - "mixins": { - "RegisterLog": true - }, - "properties": { + "properties": { "id": { "id": true } -- 2.40.1 From 384b5eb7c7705cc1603bebaa67d09d58afbe4c91 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Nov 2023 09:56:16 +0100 Subject: [PATCH 023/100] refs #5666 remove old file --- back/mixins/register-log.js | 20 ------ modules/account/back/models/account.json | 86 ++++++++++++------------ 2 files changed, 43 insertions(+), 63 deletions(-) delete mode 100644 back/mixins/register-log.js diff --git a/back/mixins/register-log.js b/back/mixins/register-log.js deleted file mode 100644 index 555191e57..000000000 --- a/back/mixins/register-log.js +++ /dev/null @@ -1,20 +0,0 @@ - -const loggable = require('vn-loopback/util/log'); - -module.exports = function(Self, options) { - Self.once('attached', function(ctx) { - }); - - Self.observe('before save', async function(ctx, next) { - await loggable.translateValues(Self, ctx.currentInstance); - }); - - let Mixin = { - - }; - - for (let method in Mixin) { - if (!Self.prototype[method]) - Self.prototype[method] = Mixin[method]; - } -}; diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 3e4371604..6c2784696 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -1,49 +1,49 @@ { - "name": "Account", - "base": "VnModel", - "options": { - "mysql": { - "table": "account.account" - } - }, + "name": "Account", + "base": "VnModel", + "options": { + "mysql": { + "table": "account.account" + } + }, "properties": { - "id": { - "id": true - } - }, - "relations": { - "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "id" - }, - "aliases": { - "type": "hasMany", - "model": "MailAliasAccount", - "foreignKey": "account" - } - }, - "acls": [ - { - "property": "login", - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" + "id": { + "id": true + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "id" }, - { + "aliases": { + "type": "hasMany", + "model": "MailAliasAccount", + "foreignKey": "account" + } + }, + "acls": [ + { + "property": "login", + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }, + { "property": "logout", - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$authenticated", - "permission": "ALLOW" - }, - { + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$authenticated", + "permission": "ALLOW" + }, + { "property": "changePassword", - "accessType": "EXECUTE", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] } -- 2.40.1 From b57106af483b482776f62aec82798d78d3c985f6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 14 Nov 2023 11:13:33 +0100 Subject: [PATCH 024/100] refs #6291 validateTin --- modules/worker/back/models/worker.js | 21 +++++++++++++++++++++ modules/worker/front/create/index.js | 1 + 2 files changed, 22 insertions(+) diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 985d83e9f..8fb4c8a02 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -23,4 +23,25 @@ module.exports = Self => { Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' }); + + Self.validateAsync('fi', tinIsValid, { + message: 'Invalid TIN' + }); + + async function tinIsValid(err, done) { + if (!this.isTaxDataChecked) + return done(); + + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + const countryCode = this.fi?.toLowerCase().substring(0, 2); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) + err(); + done(); + } }; diff --git a/modules/worker/front/create/index.js b/modules/worker/front/create/index.js index e6d65221f..b112fc06f 100644 --- a/modules/worker/front/create/index.js +++ b/modules/worker/front/create/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; +const validateTin = require('vn-loopback/util/validateTin'); export default class Controller extends Section { constructor($element, $) { -- 2.40.1 From 0a5e8e1902c8ec328c5bb9740863f9b490797a10 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 14 Nov 2023 14:49:54 +0100 Subject: [PATCH 025/100] refactor(ticketTracking.create): refs #6366 unify Ticket.state ticketTracking.create i vn.ticket_setState --- loopback/locale/es.json | 1 + .../importToNewRefundTicket.js | 2 +- .../ticket/back/methods/ticket/saveSign.js | 14 +++++++++- .../back/methods/ticket/specs/state.spec.js | 23 +++++++--------- modules/ticket/back/methods/ticket/state.js | 27 ++++++++++--------- modules/zone/back/methods/zone/deleteZone.js | 2 +- 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b42720458..c9e1f1ff2 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -296,6 +296,7 @@ "Invalid NIF for VIES": "Invalid NIF for VIES", "Ticket does not exist": "Este ticket no existe", "Ticket is already signed": "Este ticket ya ha sido firmado", + "The DELIVERED state does not exist": "El estado DELIVERED no existe", "Authentication failed": "Autenticación fallida", "You can't use the same password": "No puedes usar la misma contraseña", "You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono", diff --git a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js index be3baccd7..faa143a45 100644 --- a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js +++ b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js @@ -120,7 +120,7 @@ module.exports = Self => { observationTypeFk: obsevationType.id }, myOptions); - await models.TicketTracking.create({ + await models.Ticket.state(ctx, { ticketFk: newRefundTicket.id, stateFk: state.id, workerFk: worker.id diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 9888328e7..9f953cb1a 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -130,7 +130,19 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions); const ticket = await models.Ticket.findById(ticketId, null, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions); + + const deliveryState = await models.State.find({ + where: { + code: 'DELIVERED' + } + }, options); + if (!deliveryState) + throw new UserError('The DELIVERED state does not exist'); + + await models.Ticket.state(ctx, { + ticketFk: ticketId, + stateFk: deliveryState.id + }, myOptions); } if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/ticket/specs/state.spec.js b/modules/ticket/back/methods/ticket/specs/state.spec.js index 9b5e80165..50fecd4a5 100644 --- a/modules/ticket/back/methods/ticket/specs/state.spec.js +++ b/modules/ticket/back/methods/ticket/specs/state.spec.js @@ -45,9 +45,8 @@ describe('ticket state()', () => { const options = {transaction: tx}; activeCtx.accessToken.userId = salesPersonId; - const params = {ticketFk: 2, stateFk: 3}; - await models.Ticket.state(ctx, params, options); + await models.Ticket.state(ctx, {ticketFk: 2, stateFk: 3}, options); await tx.rollback(); } catch (e) { @@ -67,9 +66,8 @@ describe('ticket state()', () => { const options = {transaction: tx}; activeCtx.accessToken.userId = employeeId; - const params = {ticketFk: 11, stateFk: 13}; - await models.Ticket.state(ctx, params, options); + await models.Ticket.state(ctx, {ticketFk: 11, stateFk: 13}, options); await tx.rollback(); } catch (e) { @@ -94,10 +92,10 @@ describe('ticket state()', () => { const ticketTracking = await models.Ticket.state(ctx, params, options); - expect(ticketTracking.__data.ticketFk).toBe(params.ticketFk); - expect(ticketTracking.__data.stateFk).toBe(params.stateFk); - expect(ticketTracking.__data.workerFk).toBe(49); - expect(ticketTracking.__data.id).toBeDefined(); + expect(ticketTracking.ticketFk).toBe(params.ticketFk); + expect(ticketTracking.stateFk).toBe(params.stateFk); + expect(ticketTracking.workerFk).toBe(49); + expect(ticketTracking.id).toBeDefined(); await tx.rollback(); } catch (e) { @@ -119,11 +117,10 @@ describe('ticket state()', () => { const params = {ticketFk: ticket.id, stateFk: assignedState.id, workerFk: 1}; const res = await models.Ticket.state(ctx, params, options); - expect(res.__data.ticketFk).toBe(params.ticketFk); - expect(res.__data.stateFk).toBe(params.stateFk); - expect(res.__data.workerFk).toBe(params.workerFk); - expect(res.__data.workerFk).toBe(1); - expect(res.__data.id).toBeDefined(); + expect(res.ticketFk).toBe(params.ticketFk); + expect(res.stateFk).toBe(params.stateFk); + expect(res.workerFk).toBe(params.workerFk); + expect(res.id).toBeDefined(); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 01bfbba20..5282597eb 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -37,18 +37,14 @@ module.exports = Self => { } try { - const userId = ctx.req.accessToken.userId; + const {userId} = ctx.req.accessToken; if (!params.stateFk && !params.code) throw new UserError('State cannot be blank'); - if (params.code) { - const state = await models.State.findOne({ - where: {code: params.code}, - fields: ['id'] - }, myOptions); - - params.stateFk = state.id; + if (params.stateFk) { + const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions); + params.code = code; } if (!params.workerFk) { @@ -68,12 +64,19 @@ module.exports = Self => { oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions); const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions); - const isAllowed = (!ticketState || oldStateAllowed == true) && newStateAllowed == true; - - if (!isAllowed) + if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true)) throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); - const ticketTracking = await models.TicketTracking.create(params, myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); + + const ticketTracking = await models.TicketTracking.findOne({ + where: {ticketFk: params.ticketFk}, + order: 'id DESC', + limit: 1 + }, myOptions); + + if (params.workerFk) + await ticketTracking.updateAttribute('workerFk', params.workerFk, myOptions); if (tx) await tx.commit(); diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 13d45428c..380b5fcfd 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -61,7 +61,7 @@ module.exports = Self => { for (ticket of ticketList) { if (ticket.ticketState().alertLevel == 0) { - promises.push(models.TicketTracking.create({ + promises.push(models.Ticket.state(ctx, { ticketFk: ticket.id, stateFk: fixingState.id, workerFk: worker.id -- 2.40.1 From 7c6798c56426d38b09b2cad9f21b33a3a0e07dd0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 21 Nov 2023 16:25:48 +0100 Subject: [PATCH 026/100] refs #6291 dni vn-user --- back/models/vn-user.js | 22 ++++++++++++++++++++++ modules/worker/back/models/worker.js | 21 --------------------- modules/worker/front/create/index.js | 1 - 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/back/models/vn-user.js b/back/models/vn-user.js index de5bf7b63..5ab0c755e 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -2,6 +2,7 @@ const vnModel = require('vn-loopback/common/models/vn-model'); const {Email} = require('vn-print'); const ForbiddenError = require('vn-loopback/util/forbiddenError'); const LoopBackContext = require('loopback-context'); +const validateTin = require('vn-loopback/util/validateTin'); module.exports = function(Self) { vnModel(Self); @@ -19,6 +20,27 @@ module.exports = function(Self) { // Validations + Self.validateAsync('fi', tinIsValid, { + message: 'Invalid TIN' + }); + + async function tinIsValid(err, done) { + if (!this.isTaxDataChecked) + return done(); + + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + const countryCode = this.fi?.toLowerCase().substring(0, 2); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) + err(); + done(); + } + Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 8fb4c8a02..985d83e9f 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -23,25 +23,4 @@ module.exports = Self => { Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' }); - - Self.validateAsync('fi', tinIsValid, { - message: 'Invalid TIN' - }); - - async function tinIsValid(err, done) { - if (!this.isTaxDataChecked) - return done(); - - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - const countryCode = this.fi?.toLowerCase().substring(0, 2); - - if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) - err(); - done(); - } }; diff --git a/modules/worker/front/create/index.js b/modules/worker/front/create/index.js index b112fc06f..e6d65221f 100644 --- a/modules/worker/front/create/index.js +++ b/modules/worker/front/create/index.js @@ -1,6 +1,5 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -const validateTin = require('vn-loopback/util/validateTin'); export default class Controller extends Section { constructor($element, $) { -- 2.40.1 From a7361a89bd1d6d65a734bed619ec675d71f7d3a0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Nov 2023 12:58:07 +0100 Subject: [PATCH 027/100] refs #6489 remove auth --- back/methods/osticket/sendToSupport.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/back/methods/osticket/sendToSupport.js b/back/methods/osticket/sendToSupport.js index 5b9ebb4e3..135774919 100644 --- a/back/methods/osticket/sendToSupport.js +++ b/back/methods/osticket/sendToSupport.js @@ -35,10 +35,17 @@ module.exports = Self => { let html = `Motivo:
${reason}
`; html += `Usuario:
${ctx.req.accessToken.userId} ${emailUser.email}
`; + delete additionalData.backError.config.headers.Authorization; + const httpRequest = JSON.parse(additionalData?.httpRequest); + + if (httpRequest) + delete httpRequest.config.headers.Authorization; + additionalData.httpRequest = httpRequest; + for (const data in additionalData) html += `${data}:
${tryParse(additionalData[data])}
`; - const subjectReason = JSON.parse(additionalData?.httpRequest)?.data?.error; + const subjectReason = httpRequest?.data?.error; smtp.send({ to: `${config.app.reportEmail}, ${emailUser.email}`, subject: -- 2.40.1 From 50a97693b99d91df8d5c6b776de7d784a6195c4f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 28 Nov 2023 07:48:42 +0100 Subject: [PATCH 028/100] refs 5666 feat: remove loggable.js file --- loopback/common/models/loggable.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 loopback/common/models/loggable.js diff --git a/loopback/common/models/loggable.js b/loopback/common/models/loggable.js deleted file mode 100644 index 360c84566..000000000 --- a/loopback/common/models/loggable.js +++ /dev/null @@ -1,15 +0,0 @@ -const LoopBackContext = require('loopback-context'); - -module.exports = function(Self) { - Self.setup = function() { - Self.super_.setup.call(this); - }; - - Self.observe('before save', async function(ctx) { - ctx.options.httpCtx = LoopBackContext.getCurrentContext(); - }); - - Self.observe('before delete', async function(ctx) { - ctx.options.httpCtx = LoopBackContext.getCurrentContext(); - }); -}; -- 2.40.1 From f5f2896cbf3be60d1c70d4eb1f850143d1eb0153 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 28 Nov 2023 08:12:16 +0100 Subject: [PATCH 029/100] refs 5666 feat: replace Role model by VnRole model --- back/models/dms-type.json | 4 ++-- back/models/image-collection.json | 5 ++--- back/models/notificationAcl.json | 4 ++-- back/models/vn-user.json | 2 +- modules/account/back/models/role-inherit.json | 4 ++-- modules/account/back/models/role-role.json | 4 ++-- modules/claim/back/models/claim-state.json | 2 +- modules/client/back/models/client-credit-limit.json | 4 ++-- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/back/models/dms-type.json b/back/models/dms-type.json index de3d564b4..8d7195132 100644 --- a/back/models/dms-type.json +++ b/back/models/dms-type.json @@ -29,12 +29,12 @@ "relations": { "readRole": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "readRoleFk" }, "writeRole": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "writeRoleFk" } }, diff --git a/back/models/image-collection.json b/back/models/image-collection.json index 186ab0208..ae0e0adcd 100644 --- a/back/models/image-collection.json +++ b/back/models/image-collection.json @@ -46,12 +46,12 @@ }, "readRole": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "readRoleFk" }, "writeRole": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "writeRoleFk" } }, @@ -64,4 +64,3 @@ } ] } - \ No newline at end of file diff --git a/back/models/notificationAcl.json b/back/models/notificationAcl.json index a20187961..9ab85530f 100644 --- a/back/models/notificationAcl.json +++ b/back/models/notificationAcl.json @@ -24,8 +24,8 @@ }, "role": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "roleFk" } } -} \ No newline at end of file +} diff --git a/back/models/vn-user.json b/back/models/vn-user.json index bda0a6ec3..cf5796123 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -66,7 +66,7 @@ "relations": { "role": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "roleFk" }, "roles": { diff --git a/modules/account/back/models/role-inherit.json b/modules/account/back/models/role-inherit.json index 4b69ffdc2..a89f47b77 100644 --- a/modules/account/back/models/role-inherit.json +++ b/modules/account/back/models/role-inherit.json @@ -15,12 +15,12 @@ "relations": { "owner": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "role" }, "inherits": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "inheritsFrom" } } diff --git a/modules/account/back/models/role-role.json b/modules/account/back/models/role-role.json index 77df7a920..e59351c59 100644 --- a/modules/account/back/models/role-role.json +++ b/modules/account/back/models/role-role.json @@ -14,12 +14,12 @@ "relations": { "owner": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "role" }, "inherits": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "inheritsFrom" } } diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index f5bde4168..3ee932f16 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -32,7 +32,7 @@ "relations": { "writeRole": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "roleFk" } }, diff --git a/modules/client/back/models/client-credit-limit.json b/modules/client/back/models/client-credit-limit.json index 740f0cf53..922d4d14b 100644 --- a/modules/client/back/models/client-credit-limit.json +++ b/modules/client/back/models/client-credit-limit.json @@ -19,8 +19,8 @@ "relations": { "role": { "type": "belongsTo", - "model": "Role", + "model": "VnRole", "foreignKey": "roleFk" } } -} \ No newline at end of file +} -- 2.40.1 From 16001099b61adc0d297f88c204e0748e5c3ee57f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 30 Nov 2023 12:15:48 +0100 Subject: [PATCH 030/100] refs #5666 feat: update ACLs for role and vnRole --- db/changes/235001/00-updateACL_Role_VnRole.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/changes/235001/00-updateACL_Role_VnRole.sql diff --git a/db/changes/235001/00-updateACL_Role_VnRole.sql b/db/changes/235001/00-updateACL_Role_VnRole.sql new file mode 100644 index 000000000..0b1083991 --- /dev/null +++ b/db/changes/235001/00-updateACL_Role_VnRole.sql @@ -0,0 +1,8 @@ +-- Auto-generated SQL script #202311301038 +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) + VALUES ('VnRole','*','*','ALLOW','ROLE','$everyone'); +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) + VALUES ('VnRole','*','*','ALLOW','ROLE','employee'); + +-- Auto-generated SQL script #202311301203 +UPDATE `salix`.`ACL` SET permission='DENY' WHERE model='Role'; -- 2.40.1 From 01e713522415ac0710145f802eb0e8b9384cadbb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 30 Nov 2023 12:20:05 +0100 Subject: [PATCH 031/100] refs #5666 feat: replace Role by VnRole in front --- modules/account/front/acl/create/index.html | 4 ++-- modules/account/front/acl/search-panel/index.html | 6 +++--- modules/account/front/create/index.html | 2 +- modules/account/front/privileges/index.html | 2 +- modules/account/front/role/basic-data/index.html | 8 ++++---- modules/account/front/role/card/index.js | 2 +- modules/account/front/role/create/index.html | 6 +++--- modules/account/front/role/descriptor/index.js | 2 +- modules/account/front/role/main/index.html | 4 ++-- modules/account/front/role/subroles/index.html | 6 +++--- modules/account/front/role/summary/index.js | 2 +- modules/account/front/search-panel/index.html | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/account/front/acl/create/index.html b/modules/account/front/acl/create/index.html index 7f4fa9e46..14332f737 100644 --- a/modules/account/front/acl/create/index.html +++ b/modules/account/front/acl/create/index.html @@ -15,7 +15,7 @@ @@ -32,7 +32,7 @@ diff --git a/modules/account/front/acl/search-panel/index.html b/modules/account/front/acl/search-panel/index.html index b83b9c255..a3efab440 100644 --- a/modules/account/front/acl/search-panel/index.html +++ b/modules/account/front/acl/search-panel/index.html @@ -4,7 +4,7 @@ - \ No newline at end of file + diff --git a/modules/account/front/create/index.html b/modules/account/front/create/index.html index acc07d346..70a518885 100644 --- a/modules/account/front/create/index.html +++ b/modules/account/front/create/index.html @@ -30,7 +30,7 @@ + url="VnRoles"> diff --git a/modules/account/front/role/basic-data/index.html b/modules/account/front/role/basic-data/index.html index 749927186..a6d39f3e3 100644 --- a/modules/account/front/role/basic-data/index.html +++ b/modules/account/front/role/basic-data/index.html @@ -1,6 +1,6 @@ @@ -11,13 +11,13 @@ @@ -35,4 +35,4 @@ ng-click="watcher.loadOriginalData()"> - \ No newline at end of file + diff --git a/modules/account/front/role/card/index.js b/modules/account/front/role/card/index.js index 6f888211d..3c7c758ef 100644 --- a/modules/account/front/role/card/index.js +++ b/modules/account/front/role/card/index.js @@ -3,7 +3,7 @@ import ModuleCard from 'salix/components/module-card'; class Controller extends ModuleCard { reload() { - this.$http.get(`Roles/${this.$params.id}`) + this.$http.get(`VnRoles/${this.$params.id}`) .then(res => this.role = res.data); } } diff --git a/modules/account/front/role/create/index.html b/modules/account/front/role/create/index.html index 02900d580..b747f7d00 100644 --- a/modules/account/front/role/create/index.html +++ b/modules/account/front/role/create/index.html @@ -1,6 +1,6 @@ @@ -12,13 +12,13 @@ diff --git a/modules/account/front/role/descriptor/index.js b/modules/account/front/role/descriptor/index.js index a1b578133..17b585cb7 100644 --- a/modules/account/front/role/descriptor/index.js +++ b/modules/account/front/role/descriptor/index.js @@ -11,7 +11,7 @@ class Controller extends Descriptor { } onDelete() { - return this.$http.delete(`Roles/${this.id}`) + return this.$http.delete(`VnRoles/${this.id}`) .then(() => this.$state.go('account.role')) .then(() => this.vnApp.showSuccess(this.$t('Role removed'))); } diff --git a/modules/account/front/role/main/index.html b/modules/account/front/role/main/index.html index 9d7e6e053..cfef28e57 100644 --- a/modules/account/front/role/main/index.html +++ b/modules/account/front/role/main/index.html @@ -1,6 +1,6 @@ @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/modules/account/front/role/subroles/index.html b/modules/account/front/role/subroles/index.html index bc554b9f9..eba1002b0 100644 --- a/modules/account/front/role/subroles/index.html +++ b/modules/account/front/role/subroles/index.html @@ -33,14 +33,14 @@ ng-click="$ctrl.onAddClick()" fixed-bottom-right> - @@ -49,7 +49,7 @@ - this.$.summary = res.data); } diff --git a/modules/account/front/search-panel/index.html b/modules/account/front/search-panel/index.html index f80b537aa..a539d9657 100644 --- a/modules/account/front/search-panel/index.html +++ b/modules/account/front/search-panel/index.html @@ -19,7 +19,7 @@ vn-one label="Role" ng-model="filter.roleFk" - url="Roles" + url="VnRoles" value-field="id" show-field="name"> @@ -28,4 +28,4 @@ - \ No newline at end of file + -- 2.40.1 From 2fe631f078bf2ca596e083ede0c015e3c1aec2d5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:15:22 +0100 Subject: [PATCH 032/100] refs #5666 feat: change models permissions --- back/model-config.json | 12 ++++++------ db/changes/235001/00-updateACL_Role_VnRole.sql | 14 +++++++++----- loopback/server/model-config.json | 8 -------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/back/model-config.json b/back/model-config.json index 84dd9eebd..27a94498c 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -139,12 +139,6 @@ "Warehouse": { "dataSource": "vn" }, - "VnUser": { - "dataSource": "vn" - }, - "VnRole": { - "dataSource": "vn" - }, "OsTicket": { "dataSource": "osticket" }, @@ -159,6 +153,12 @@ }, "ViaexpressConfig": { "dataSource": "vn" + }, + "VnUser": { + "dataSource": "vn" + }, + "VnRole": { + "dataSource": "vn" } } diff --git a/db/changes/235001/00-updateACL_Role_VnRole.sql b/db/changes/235001/00-updateACL_Role_VnRole.sql index 0b1083991..6fbec02a6 100644 --- a/db/changes/235001/00-updateACL_Role_VnRole.sql +++ b/db/changes/235001/00-updateACL_Role_VnRole.sql @@ -1,8 +1,12 @@ -- Auto-generated SQL script #202311301038 -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('VnRole','*','*','ALLOW','ROLE','$everyone'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('VnRole','*','*','ALLOW','ROLE','employee'); +-- INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) +-- VALUES ('VnRole','*','*','ALLOW','ROLE','$everyone'); +-- INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) +-- VALUES ('VnRole','*','*','ALLOW','ROLE','employee'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES + ('VnRole','*','READ','ALLOW','ROLE','employee'), + ('VnRole','*','WRITE','ALLOW','ROLE','it'); -- Auto-generated SQL script #202311301203 -UPDATE `salix`.`ACL` SET permission='DENY' WHERE model='Role'; +DELETE FROM`salix`.`ACL` WHERE model='Role'; + diff --git a/loopback/server/model-config.json b/loopback/server/model-config.json index 33ef3797d..51874988d 100644 --- a/loopback/server/model-config.json +++ b/loopback/server/model-config.json @@ -25,14 +25,6 @@ "FieldAcl": { "dataSource": "vn" }, - "Role": { - "dataSource": "vn", - "options": { - "mysql": { - "table": "salix.Role" - } - } - }, "RoleMapping": { "dataSource": "vn", "options": { -- 2.40.1 From 57add7abf016602c15786d719efd3f46142a549a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:16:12 +0100 Subject: [PATCH 033/100] refs #5666 perf: replace Role by VnRole --- back/methods/vn-user/privileges.js | 2 +- back/methods/vn-user/specs/privileges.spec.js | 2 +- modules/account/back/models/ldap-config.js | 2 +- modules/ticket/back/methods/sale/specs/canEdit.spec.js | 4 ++-- .../back/methods/worker/specs/activeWithInheritedRole.spec.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/back/methods/vn-user/privileges.js b/back/methods/vn-user/privileges.js index 08cfaaae8..9f936c29b 100644 --- a/back/methods/vn-user/privileges.js +++ b/back/methods/vn-user/privileges.js @@ -68,7 +68,7 @@ module.exports = Self => { userToUpdate.hasGrant = hasGrant; if (roleFk) { - const role = await models.Role.findById(roleFk, {fields: ['name']}, myOptions); + const role = await models.VnRole.findById(roleFk, {fields: ['name']}, myOptions); const hasRole = await Self.hasRole(userId, role.name, myOptions); if (!hasRole) diff --git a/back/methods/vn-user/specs/privileges.spec.js b/back/methods/vn-user/specs/privileges.spec.js index 3d25eecf9..04d9c09ff 100644 --- a/back/methods/vn-user/specs/privileges.spec.js +++ b/back/methods/vn-user/specs/privileges.spec.js @@ -70,7 +70,7 @@ describe('VnUser privileges()', () => { const tx = await models.VnUser.beginTransaction({}); const options = {transaction: tx}; - const agency = await models.Role.findOne({ + const agency = await models.VnRole.findOne({ where: { name: 'agency' } diff --git a/modules/account/back/models/ldap-config.js b/modules/account/back/models/ldap-config.js index b557d243c..89f0add48 100644 --- a/modules/account/back/models/ldap-config.js +++ b/modules/account/back/models/ldap-config.js @@ -239,7 +239,7 @@ module.exports = Self => { // Prepare data - let roles = await $.Role.find({ + let roles = await $.VnRole.find({ fields: ['id', 'name', 'description'] }); let roleRoles = await $.RoleRole.find({ diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index eef9136a8..200ea24cc 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -102,7 +102,7 @@ describe('sale canEdit()', () => { try { const options = {transaction: tx}; - const role = await models.Role.findOne({ + const role = await models.VnRole.findOne({ where: { name: roleEnabled.principalId } @@ -159,7 +159,7 @@ describe('sale canEdit()', () => { try { const options = {transaction: tx}; - const role = await models.Role.findOne({ + const role = await models.VnRole.findOne({ where: { name: roleEnabled.principalId } diff --git a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js index da54f6adb..580e07351 100644 --- a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js +++ b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js @@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server'); describe('Worker activeWithInheritedRole', () => { let allRolesCount; beforeAll(async() => { - allRolesCount = await app.models.Role.count(); + allRolesCount = await app.models.VnRole.count(); }); it('should return the workers with an inherited role of salesPerson', async() => { -- 2.40.1 From b4f4714c0a9f6fae89c38b165e813582b37fc99f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:47:38 +0100 Subject: [PATCH 034/100] refs #5666 feat: remove loggable.json --- loopback/common/models/loggable.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 loopback/common/models/loggable.json diff --git a/loopback/common/models/loggable.json b/loopback/common/models/loggable.json deleted file mode 100644 index 62822d0af..000000000 --- a/loopback/common/models/loggable.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "Loggable", - "base": "VnModel", - "validateUpsert": true, - "mixins": { - "Loggable": true - } -} -- 2.40.1 From 1d92bbf4a21f24e30e4e51328e636b19ecc6a560 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:48:56 +0100 Subject: [PATCH 035/100] refs #5666 feat: replace base value and add mixins --- modules/claim/back/models/claim-beginning.json | 5 ++++- modules/claim/back/models/claim-development.json | 5 ++++- modules/claim/back/models/claim-dms.json | 5 ++++- modules/claim/back/models/claim-end.json | 5 ++++- modules/claim/back/models/claim-observation.json | 5 ++++- modules/claim/back/models/claim-state.json | 5 ++++- modules/claim/back/models/claim.json | 5 ++++- modules/client/back/models/address.json | 5 ++++- modules/client/back/models/client-contact.json | 5 ++++- modules/client/back/models/client-dms.json | 5 ++++- modules/client/back/models/client-informa.json | 5 ++++- modules/client/back/models/client-observation.json | 5 ++++- modules/client/back/models/client-sample.json | 5 ++++- modules/client/back/models/client.json | 5 ++++- modules/client/back/models/greuge.json | 5 ++++- modules/client/back/models/recovery.json | 5 ++++- modules/entry/back/models/buy.json | 5 ++++- modules/entry/back/models/entry-observation.json | 5 ++++- modules/entry/back/models/entry.json | 5 ++++- modules/invoiceIn/back/models/invoice-in-tax.json | 5 ++++- modules/invoiceIn/back/models/invoice-in.json | 5 ++++- modules/item/back/models/item-barcode.json | 5 ++++- modules/item/back/models/item-botanical.json | 5 ++++- modules/item/back/models/item-shelving.json | 5 ++++- modules/item/back/models/item-tag.json | 5 ++++- modules/item/back/models/item-tax-country.json | 5 ++++- modules/item/back/models/item.json | 5 ++++- modules/route/back/models/route.json | 5 ++++- modules/shelving/back/models/shelving.json | 5 ++++- modules/supplier/back/models/supplier-account.json | 5 ++++- modules/supplier/back/models/supplier-address.json | 5 ++++- modules/supplier/back/models/supplier-contact.json | 5 ++++- modules/supplier/back/models/supplier.json | 5 ++++- modules/ticket/back/models/expedition.json | 5 ++++- modules/ticket/back/models/sale.json | 5 ++++- modules/ticket/back/models/ticket-dms.json | 5 ++++- modules/ticket/back/models/ticket-observation.json | 5 ++++- modules/ticket/back/models/ticket-packaging.json | 5 ++++- modules/ticket/back/models/ticket-refund.json | 5 ++++- modules/ticket/back/models/ticket-request.json | 5 ++++- modules/ticket/back/models/ticket-service.json | 5 ++++- modules/ticket/back/models/ticket-tracking.json | 5 ++++- modules/ticket/back/models/ticket-weekly.json | 5 ++++- modules/ticket/back/models/ticket.json | 5 ++++- modules/travel/back/models/travel-thermograph.json | 5 ++++- modules/travel/back/models/travel.json | 5 ++++- modules/worker/back/models/device-production-user.json | 5 ++++- modules/worker/back/models/device-production.json | 5 ++++- modules/worker/back/models/worker-dms.json | 5 ++++- modules/worker/back/models/worker.json | 5 ++++- modules/zone/back/models/zone-event.json | 5 ++++- modules/zone/back/models/zone-exclusion.json | 5 ++++- modules/zone/back/models/zone-included.json | 5 ++++- modules/zone/back/models/zone-warehouse.json | 5 ++++- modules/zone/back/models/zone.json | 5 ++++- 55 files changed, 220 insertions(+), 55 deletions(-) diff --git a/modules/claim/back/models/claim-beginning.json b/modules/claim/back/models/claim-beginning.json index d355881e8..d224586da 100644 --- a/modules/claim/back/models/claim-beginning.json +++ b/modules/claim/back/models/claim-beginning.json @@ -1,6 +1,9 @@ { "name": "ClaimBeginning", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimBeginning" diff --git a/modules/claim/back/models/claim-development.json b/modules/claim/back/models/claim-development.json index b0f352f50..732955660 100644 --- a/modules/claim/back/models/claim-development.json +++ b/modules/claim/back/models/claim-development.json @@ -1,6 +1,9 @@ { "name": "ClaimDevelopment", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimDevelopment" diff --git a/modules/claim/back/models/claim-dms.json b/modules/claim/back/models/claim-dms.json index 26c90fd69..ed12c925b 100644 --- a/modules/claim/back/models/claim-dms.json +++ b/modules/claim/back/models/claim-dms.json @@ -1,6 +1,9 @@ { "name": "ClaimDms", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimDms" diff --git a/modules/claim/back/models/claim-end.json b/modules/claim/back/models/claim-end.json index 9f12ff93a..ef5477f50 100644 --- a/modules/claim/back/models/claim-end.json +++ b/modules/claim/back/models/claim-end.json @@ -1,6 +1,9 @@ { "name": "ClaimEnd", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimEnd" diff --git a/modules/claim/back/models/claim-observation.json b/modules/claim/back/models/claim-observation.json index 2d418b76e..1e4cb6a0f 100644 --- a/modules/claim/back/models/claim-observation.json +++ b/modules/claim/back/models/claim-observation.json @@ -1,6 +1,9 @@ { "name": "ClaimObservation", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimObservation" diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index 3ee932f16..c50fdebdf 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -1,6 +1,9 @@ { "name": "ClaimState", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claimState" diff --git a/modules/claim/back/models/claim.json b/modules/claim/back/models/claim.json index a7db1f3e1..b85b9e073 100644 --- a/modules/claim/back/models/claim.json +++ b/modules/claim/back/models/claim.json @@ -1,6 +1,9 @@ { "name": "Claim", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "claim" diff --git a/modules/client/back/models/address.json b/modules/client/back/models/address.json index 5f962677d..e8bf8d8a0 100644 --- a/modules/client/back/models/address.json +++ b/modules/client/back/models/address.json @@ -1,7 +1,10 @@ { "name": "Address", "description": "Client addresses", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "address" diff --git a/modules/client/back/models/client-contact.json b/modules/client/back/models/client-contact.json index 3f71ab79e..55cc9d436 100644 --- a/modules/client/back/models/client-contact.json +++ b/modules/client/back/models/client-contact.json @@ -1,7 +1,10 @@ { "name": "ClientContact", "description": "Client phone contacts", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientContact" diff --git a/modules/client/back/models/client-dms.json b/modules/client/back/models/client-dms.json index 14b19498e..6dbcd0140 100644 --- a/modules/client/back/models/client-dms.json +++ b/modules/client/back/models/client-dms.json @@ -1,6 +1,9 @@ { "name": "ClientDms", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientDms" diff --git a/modules/client/back/models/client-informa.json b/modules/client/back/models/client-informa.json index 0c652484e..5e536faff 100644 --- a/modules/client/back/models/client-informa.json +++ b/modules/client/back/models/client-informa.json @@ -1,6 +1,9 @@ { "name": "ClientInforma", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "log": { "model":"ClientLog", "relation": "client", diff --git a/modules/client/back/models/client-observation.json b/modules/client/back/models/client-observation.json index 95d00d374..b204ebeb4 100644 --- a/modules/client/back/models/client-observation.json +++ b/modules/client/back/models/client-observation.json @@ -1,7 +1,10 @@ { "name": "ClientObservation", "description": "Client notes", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientObservation" diff --git a/modules/client/back/models/client-sample.json b/modules/client/back/models/client-sample.json index a32f308ab..4cd55d9df 100644 --- a/modules/client/back/models/client-sample.json +++ b/modules/client/back/models/client-sample.json @@ -1,6 +1,9 @@ { "name": "ClientSample", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientSample" diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index f32915bb5..bfde05162 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -1,6 +1,9 @@ { "name": "Client", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "client" diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index 884cbd34e..f57744f8a 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -1,6 +1,9 @@ { "name": "Greuge", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "greuge" diff --git a/modules/client/back/models/recovery.json b/modules/client/back/models/recovery.json index 5ea89197d..89ec54494 100644 --- a/modules/client/back/models/recovery.json +++ b/modules/client/back/models/recovery.json @@ -1,6 +1,9 @@ { "name": "Recovery", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "recovery" diff --git a/modules/entry/back/models/buy.json b/modules/entry/back/models/buy.json index 30379eaf6..fa804f4d8 100644 --- a/modules/entry/back/models/buy.json +++ b/modules/entry/back/models/buy.json @@ -1,6 +1,9 @@ { "name": "Buy", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "buy" diff --git a/modules/entry/back/models/entry-observation.json b/modules/entry/back/models/entry-observation.json index cdf0c5e6e..6a1592037 100644 --- a/modules/entry/back/models/entry-observation.json +++ b/modules/entry/back/models/entry-observation.json @@ -1,6 +1,9 @@ { "name": "EntryObservation", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "entryObservation" diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index a7508b4e8..0f3e389b6 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -1,6 +1,9 @@ { "name": "Entry", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "entry" diff --git a/modules/invoiceIn/back/models/invoice-in-tax.json b/modules/invoiceIn/back/models/invoice-in-tax.json index 5bfbbe2a8..53b5548b6 100644 --- a/modules/invoiceIn/back/models/invoice-in-tax.json +++ b/modules/invoiceIn/back/models/invoice-in-tax.json @@ -1,6 +1,9 @@ { "name": "InvoiceInTax", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "invoiceInTax" diff --git a/modules/invoiceIn/back/models/invoice-in.json b/modules/invoiceIn/back/models/invoice-in.json index 5be55c851..59c179e76 100644 --- a/modules/invoiceIn/back/models/invoice-in.json +++ b/modules/invoiceIn/back/models/invoice-in.json @@ -1,6 +1,9 @@ { "name": "InvoiceIn", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "invoiceIn" diff --git a/modules/item/back/models/item-barcode.json b/modules/item/back/models/item-barcode.json index 12068a65f..6726900ea 100644 --- a/modules/item/back/models/item-barcode.json +++ b/modules/item/back/models/item-barcode.json @@ -1,6 +1,9 @@ { "name": "ItemBarcode", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemBarcode" diff --git a/modules/item/back/models/item-botanical.json b/modules/item/back/models/item-botanical.json index 8a8bba870..ff1410615 100644 --- a/modules/item/back/models/item-botanical.json +++ b/modules/item/back/models/item-botanical.json @@ -1,6 +1,9 @@ { "name": "ItemBotanical", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemBotanical" diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index bb1a141c4..f3be98fc4 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -1,6 +1,9 @@ { "name": "ItemShelving", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemShelving" diff --git a/modules/item/back/models/item-tag.json b/modules/item/back/models/item-tag.json index 0742f8d3f..5702cf6cf 100644 --- a/modules/item/back/models/item-tag.json +++ b/modules/item/back/models/item-tag.json @@ -1,6 +1,9 @@ { "name": "ItemTag", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemTag" diff --git a/modules/item/back/models/item-tax-country.json b/modules/item/back/models/item-tax-country.json index 002be97d8..795a1b950 100644 --- a/modules/item/back/models/item-tax-country.json +++ b/modules/item/back/models/item-tax-country.json @@ -1,6 +1,9 @@ { "name": "ItemTaxCountry", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemTaxCountry" diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 097fe7708..595fb537d 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -1,6 +1,9 @@ { "name": "Item", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "item" diff --git a/modules/route/back/models/route.json b/modules/route/back/models/route.json index cdb64dd71..f8be9023c 100644 --- a/modules/route/back/models/route.json +++ b/modules/route/back/models/route.json @@ -1,6 +1,9 @@ { "name": "Route", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "route" diff --git a/modules/shelving/back/models/shelving.json b/modules/shelving/back/models/shelving.json index 3103b5a4a..46fce31e8 100644 --- a/modules/shelving/back/models/shelving.json +++ b/modules/shelving/back/models/shelving.json @@ -1,6 +1,9 @@ { "name": "Shelving", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "shelving" diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index bc9cf0e24..460c435e2 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -1,6 +1,9 @@ { "name": "SupplierAccount", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "supplierAccount" diff --git a/modules/supplier/back/models/supplier-address.json b/modules/supplier/back/models/supplier-address.json index 001b3a31f..fcd599287 100644 --- a/modules/supplier/back/models/supplier-address.json +++ b/modules/supplier/back/models/supplier-address.json @@ -1,7 +1,10 @@ { "name": "SupplierAddress", "description": "Supplier addresses", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "supplierAddress" diff --git a/modules/supplier/back/models/supplier-contact.json b/modules/supplier/back/models/supplier-contact.json index f928cd204..4ea1b8c2a 100644 --- a/modules/supplier/back/models/supplier-contact.json +++ b/modules/supplier/back/models/supplier-contact.json @@ -1,6 +1,9 @@ { "name": "SupplierContact", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "supplierContact" diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index b6245ef32..59d23f106 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -1,6 +1,9 @@ { "name": "Supplier", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "supplier" diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 069c6e281..2dcca1e87 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,6 +1,9 @@ { "name": "Expedition", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "expedition" diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 72ca1f5e0..96a36bbc9 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -1,6 +1,9 @@ { "name": "Sale", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "sale" diff --git a/modules/ticket/back/models/ticket-dms.json b/modules/ticket/back/models/ticket-dms.json index 071999be7..a3e697506 100644 --- a/modules/ticket/back/models/ticket-dms.json +++ b/modules/ticket/back/models/ticket-dms.json @@ -1,6 +1,9 @@ { "name": "TicketDms", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketDms" diff --git a/modules/ticket/back/models/ticket-observation.json b/modules/ticket/back/models/ticket-observation.json index 64e49b217..26d6f7586 100644 --- a/modules/ticket/back/models/ticket-observation.json +++ b/modules/ticket/back/models/ticket-observation.json @@ -1,6 +1,9 @@ { "name": "TicketObservation", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketObservation" diff --git a/modules/ticket/back/models/ticket-packaging.json b/modules/ticket/back/models/ticket-packaging.json index 6c94c810e..0cf494809 100644 --- a/modules/ticket/back/models/ticket-packaging.json +++ b/modules/ticket/back/models/ticket-packaging.json @@ -1,6 +1,9 @@ { "name": "TicketPackaging", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketPackaging" diff --git a/modules/ticket/back/models/ticket-refund.json b/modules/ticket/back/models/ticket-refund.json index d344a3f1c..249270c8b 100644 --- a/modules/ticket/back/models/ticket-refund.json +++ b/modules/ticket/back/models/ticket-refund.json @@ -1,6 +1,9 @@ { "name": "TicketRefund", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketRefund" diff --git a/modules/ticket/back/models/ticket-request.json b/modules/ticket/back/models/ticket-request.json index f8407792e..2cfcd30a1 100644 --- a/modules/ticket/back/models/ticket-request.json +++ b/modules/ticket/back/models/ticket-request.json @@ -1,6 +1,9 @@ { "name": "TicketRequest", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketRequest" diff --git a/modules/ticket/back/models/ticket-service.json b/modules/ticket/back/models/ticket-service.json index f1dbede13..4dfbd2fbd 100644 --- a/modules/ticket/back/models/ticket-service.json +++ b/modules/ticket/back/models/ticket-service.json @@ -1,6 +1,9 @@ { "name": "TicketService", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketService" diff --git a/modules/ticket/back/models/ticket-tracking.json b/modules/ticket/back/models/ticket-tracking.json index 8b5ce0b64..472bdb966 100644 --- a/modules/ticket/back/models/ticket-tracking.json +++ b/modules/ticket/back/models/ticket-tracking.json @@ -1,6 +1,9 @@ { "name": "TicketTracking", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketTracking" diff --git a/modules/ticket/back/models/ticket-weekly.json b/modules/ticket/back/models/ticket-weekly.json index c5e485aa2..7494cac79 100644 --- a/modules/ticket/back/models/ticket-weekly.json +++ b/modules/ticket/back/models/ticket-weekly.json @@ -1,6 +1,9 @@ { "name": "TicketWeekly", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticketWeekly" diff --git a/modules/ticket/back/models/ticket.json b/modules/ticket/back/models/ticket.json index ec4193bed..c55cd82bb 100644 --- a/modules/ticket/back/models/ticket.json +++ b/modules/ticket/back/models/ticket.json @@ -1,6 +1,9 @@ { "name": "Ticket", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "ticket" diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index 08eec2847..cc8e60aaf 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -1,6 +1,9 @@ { "name": "TravelThermograph", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "travelThermograph" diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 95d458121..701894a76 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -1,6 +1,9 @@ { "name": "Travel", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "travel" diff --git a/modules/worker/back/models/device-production-user.json b/modules/worker/back/models/device-production-user.json index 3eeaae137..35a90fb50 100644 --- a/modules/worker/back/models/device-production-user.json +++ b/modules/worker/back/models/device-production-user.json @@ -1,6 +1,9 @@ { "name": "DeviceProductionUser", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "log": { "model": "DeviceProductionLog", "relation": "deviceProduction" diff --git a/modules/worker/back/models/device-production.json b/modules/worker/back/models/device-production.json index 35787cccc..f6e5105ad 100644 --- a/modules/worker/back/models/device-production.json +++ b/modules/worker/back/models/device-production.json @@ -1,6 +1,9 @@ { "name": "DeviceProduction", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "log": { "model": "DeviceProductionLog" }, diff --git a/modules/worker/back/models/worker-dms.json b/modules/worker/back/models/worker-dms.json index e9a9f1773..a5c0f30b2 100644 --- a/modules/worker/back/models/worker-dms.json +++ b/modules/worker/back/models/worker-dms.json @@ -1,6 +1,9 @@ { "name": "WorkerDms", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "workerDocument" diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 1a777fffe..ed430f133 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -1,7 +1,10 @@ { "name": "Worker", "description": "Company employees", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "worker" diff --git a/modules/zone/back/models/zone-event.json b/modules/zone/back/models/zone-event.json index e477dad6a..366bdec9d 100644 --- a/modules/zone/back/models/zone-event.json +++ b/modules/zone/back/models/zone-event.json @@ -1,6 +1,9 @@ { "name": "ZoneEvent", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "zoneEvent" diff --git a/modules/zone/back/models/zone-exclusion.json b/modules/zone/back/models/zone-exclusion.json index 00c9145cd..6e91a0a01 100644 --- a/modules/zone/back/models/zone-exclusion.json +++ b/modules/zone/back/models/zone-exclusion.json @@ -1,6 +1,9 @@ { "name": "ZoneExclusion", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "zoneExclusion" diff --git a/modules/zone/back/models/zone-included.json b/modules/zone/back/models/zone-included.json index deba73f34..a34e51091 100644 --- a/modules/zone/back/models/zone-included.json +++ b/modules/zone/back/models/zone-included.json @@ -1,6 +1,9 @@ { "name": "ZoneIncluded", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "zoneIncluded" diff --git a/modules/zone/back/models/zone-warehouse.json b/modules/zone/back/models/zone-warehouse.json index b222e95e7..c2cc989f0 100644 --- a/modules/zone/back/models/zone-warehouse.json +++ b/modules/zone/back/models/zone-warehouse.json @@ -1,6 +1,9 @@ { "name": "ZoneWarehouse", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "zoneWarehouse" diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index c86da3d3e..cf7371053 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -1,6 +1,9 @@ { "name": "Zone", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "zone" -- 2.40.1 From 6f32a588bbc9faacdb5182cf01477f779af19219 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:49:10 +0100 Subject: [PATCH 036/100] refs #5666 feat: add role relation to RoleMapping --- loopback/server/model-config.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/loopback/server/model-config.json b/loopback/server/model-config.json index 51874988d..56b5360e8 100644 --- a/loopback/server/model-config.json +++ b/loopback/server/model-config.json @@ -31,6 +31,13 @@ "mysql": { "table": "salix.RoleMapping" } + }, + "relations": { + "role": { + "type": "belongsTo", + "model": "VnRole", + "foreignKey": "roleId" + } } }, "Schema": { -- 2.40.1 From 7a63e527a5298b05028c7721eddbefcfe597f695 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 07:50:52 +0100 Subject: [PATCH 037/100] refs #5666 perf: remove comments --- db/changes/235001/00-updateACL_Role_VnRole.sql | 6 ------ 1 file changed, 6 deletions(-) diff --git a/db/changes/235001/00-updateACL_Role_VnRole.sql b/db/changes/235001/00-updateACL_Role_VnRole.sql index 6fbec02a6..b08a44138 100644 --- a/db/changes/235001/00-updateACL_Role_VnRole.sql +++ b/db/changes/235001/00-updateACL_Role_VnRole.sql @@ -1,12 +1,6 @@ --- Auto-generated SQL script #202311301038 --- INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) --- VALUES ('VnRole','*','*','ALLOW','ROLE','$everyone'); --- INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) --- VALUES ('VnRole','*','*','ALLOW','ROLE','employee'); INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES ('VnRole','*','READ','ALLOW','ROLE','employee'), ('VnRole','*','WRITE','ALLOW','ROLE','it'); --- Auto-generated SQL script #202311301203 DELETE FROM`salix`.`ACL` WHERE model='Role'; -- 2.40.1 From 035b31d878cb989e64f3dc06cd75ff539aad6f74 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 5 Dec 2023 12:00:31 +0100 Subject: [PATCH 038/100] refs #5666 test: fix e2e tests --- front/core/directives/rule.js | 6 +++++- modules/account/front/role/basic-data/index.html | 10 +++++++--- modules/account/front/role/create/index.html | 4 ++-- modules/account/front/role/descriptor/index.html | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/front/core/directives/rule.js b/front/core/directives/rule.js index f65efe176..d944e13ed 100644 --- a/front/core/directives/rule.js +++ b/front/core/directives/rule.js @@ -23,7 +23,7 @@ export function directive($translate, $window) { let rule = $attrs.rule.split('.'); let modelName = rule.shift(); let fieldName = rule.shift(); - + let modelAlias = $attrs.ruleAlias; let split = $attrs.ngModel.split('.'); if (!fieldName) fieldName = split.pop() || null; if (!modelName) modelName = firstUpper(split.pop() || ''); @@ -31,8 +31,12 @@ export function directive($translate, $window) { if (!modelName || !fieldName) throw new Error(`rule: Cannot retrieve model or field attribute`); + let modelValidations = vnValidations[modelName]; + if (!modelValidations) + modelValidations = vnValidations[modelAlias]; + if (!modelValidations) throw new Error(`rule: Model '${modelName}' doesn't exist`); diff --git a/modules/account/front/role/basic-data/index.html b/modules/account/front/role/basic-data/index.html index a6d39f3e3..46cb080b7 100644 --- a/modules/account/front/role/basic-data/index.html +++ b/modules/account/front/role/basic-data/index.html @@ -7,6 +7,7 @@
@@ -14,12 +15,15 @@ label="Name" ng-model="$ctrl.role.name" rule + rule-alias="VnRole" vn-focus> + label="Description" + ng-model="$ctrl.role.description" + rule + rule-alias="VnRole" + > diff --git a/modules/account/front/role/create/index.html b/modules/account/front/role/create/index.html index b747f7d00..ee43484d7 100644 --- a/modules/account/front/role/create/index.html +++ b/modules/account/front/role/create/index.html @@ -13,13 +13,13 @@ diff --git a/modules/account/front/role/descriptor/index.html b/modules/account/front/role/descriptor/index.html index 4cd4ac822..d8bf4857a 100644 --- a/modules/account/front/role/descriptor/index.html +++ b/modules/account/front/role/descriptor/index.html @@ -24,4 +24,4 @@ on-accept="$ctrl.onDelete()" question="Are you sure you want to continue?" message="Role will be removed"> - \ No newline at end of file + -- 2.40.1 From 920b38c9294af25055c3081060166280b6de89dc Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 7 Dec 2023 09:49:15 +0100 Subject: [PATCH 039/100] refs #5525 move sql --- db/changes/{233801 => 235001}/00-supplier.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename db/changes/{233801 => 235001}/00-supplier.sql (87%) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/235001/00-supplier.sql similarity index 87% rename from db/changes/233801/00-supplier.sql rename to db/changes/235001/00-supplier.sql index ad9ce892c..eebd8b4f2 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -1,7 +1,8 @@ ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; + CREATE TABLE `vn`.`supplierAccountI18n` ( - supplierAccountFk int(10) unsigned NOT NULL, + supplierAccountFk mediumint(8) unsigned NOT NULL, countryFk mediumint(8) unsigned NOT NULL, FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), FOREIGN KEY (countryFk) REFERENCES country(id) -- 2.40.1 From d1f0557923efb2fa1e774ad1b6a3a590fb94f27d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Dec 2023 12:40:16 +0100 Subject: [PATCH 040/100] refs #5666 perf: remove ruleAlias property --- front/core/directives/rule.js | 5 ----- modules/account/front/role/basic-data/index.html | 6 ++---- modules/account/front/role/card/index.spec.js | 4 ++-- modules/account/front/role/descriptor/index.spec.js | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/front/core/directives/rule.js b/front/core/directives/rule.js index d944e13ed..34781c2aa 100644 --- a/front/core/directives/rule.js +++ b/front/core/directives/rule.js @@ -23,7 +23,6 @@ export function directive($translate, $window) { let rule = $attrs.rule.split('.'); let modelName = rule.shift(); let fieldName = rule.shift(); - let modelAlias = $attrs.ruleAlias; let split = $attrs.ngModel.split('.'); if (!fieldName) fieldName = split.pop() || null; if (!modelName) modelName = firstUpper(split.pop() || ''); @@ -31,12 +30,8 @@ export function directive($translate, $window) { if (!modelName || !fieldName) throw new Error(`rule: Cannot retrieve model or field attribute`); - let modelValidations = vnValidations[modelName]; - if (!modelValidations) - modelValidations = vnValidations[modelAlias]; - if (!modelValidations) throw new Error(`rule: Model '${modelName}' doesn't exist`); diff --git a/modules/account/front/role/basic-data/index.html b/modules/account/front/role/basic-data/index.html index 46cb080b7..846f8b455 100644 --- a/modules/account/front/role/basic-data/index.html +++ b/modules/account/front/role/basic-data/index.html @@ -14,15 +14,13 @@ diff --git a/modules/account/front/role/card/index.spec.js b/modules/account/front/role/card/index.spec.js index f39840e5f..f02c08f28 100644 --- a/modules/account/front/role/card/index.spec.js +++ b/modules/account/front/role/card/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('component vnRoleCard', () => { +fdescribe('component vnRoleCard', () => { let controller; let $httpBackend; @@ -15,7 +15,7 @@ describe('component vnRoleCard', () => { it('should reload the controller data', () => { controller.$params.id = 1; - $httpBackend.expectGET('Roles/1').respond('foo'); + $httpBackend.expectGET('VnRoles/1').respond('foo'); controller.reload(); $httpBackend.flush(); diff --git a/modules/account/front/role/descriptor/index.spec.js b/modules/account/front/role/descriptor/index.spec.js index e2761c639..eafb96727 100644 --- a/modules/account/front/role/descriptor/index.spec.js +++ b/modules/account/front/role/descriptor/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('component vnRoleDescriptor', () => { +fdescribe('component vnRoleDescriptor', () => { let controller; let $httpBackend; @@ -18,7 +18,7 @@ describe('component vnRoleDescriptor', () => { controller.$state.go = jest.fn(); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectDELETE('Roles/1').respond(); + $httpBackend.expectDELETE('VnRoles/1').respond(); controller.onDelete(); $httpBackend.flush(); -- 2.40.1 From f817551a57f1e9b04682d642dfb4d5b7a926d84e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Dec 2023 12:59:02 +0100 Subject: [PATCH 041/100] refs #5666 perf: remove ruleAlias property --- modules/account/front/role/create/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/account/front/role/create/index.html b/modules/account/front/role/create/index.html index ee43484d7..77d6fc2c1 100644 --- a/modules/account/front/role/create/index.html +++ b/modules/account/front/role/create/index.html @@ -13,14 +13,14 @@ + ng-model="$ctrl.role.description" + rule="VnRole.description"> -- 2.40.1 From 556b403a5b3ee3a8f8a92846ec43ec2ab2ed134d Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 11:29:50 +0100 Subject: [PATCH 042/100] refs #5525 letter debtor st --- db/changes/235001/00-supplier.sql | 11 ++++---- .../letter-debtor-st/letter-debtor-st.js | 28 +++++++++++++++---- .../email/letter-debtor-st/sql/client.sql | 19 ++++++------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/db/changes/235001/00-supplier.sql b/db/changes/235001/00-supplier.sql index eebd8b4f2..704479130 100644 --- a/db/changes/235001/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -1,10 +1,9 @@ ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; -CREATE TABLE `vn`.`supplierAccountI18n` ( - supplierAccountFk mediumint(8) unsigned NOT NULL, - countryFk mediumint(8) unsigned NOT NULL, - FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), - FOREIGN KEY (countryFk) REFERENCES country(id) -); +ALTER TABLE `vn`.`supplierAccount` +ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL, +ADD CONSTRAINT `fk_supplierAccount_country` + FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE; + diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 5d0a11baf..76df43d70 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,12 +7,28 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk);`, - [this.id]); + SELECT sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? + ORDER BY co.id DESC + LIMIT 1; + `, [this.id]); + if (!this.debtor.length) { + this.debtor = await db.findOne(` + SELECT sa.iban, + be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN company co ON co.supplierAccountFk = sa.id + WHERE co.code = ?; + `, [this.companyCode]); + } }, data() { return { diff --git a/print/templates/email/letter-debtor-st/sql/client.sql b/print/templates/email/letter-debtor-st/sql/client.sql index d5da5d0d5..013a3b7d6 100644 --- a/print/templates/email/letter-debtor-st/sql/client.sql +++ b/print/templates/email/letter-debtor-st/sql/client.sql @@ -1,10 +1,9 @@ -SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName -FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk -WHERE c.id = ? AND cny.id = ? \ No newline at end of file +SELECT c.dueDay, + sa.iban, + be.name bankName + FROM client c + JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk + JOIN company cny + WHERE c.id = ? + AND cny.id = ? -- 2.40.1 From ea31d3bebb71923242cbf0ddf0818827ce65c9ba Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 11:46:48 +0100 Subject: [PATCH 043/100] refs #5525 debtor-nd --- .../letter-debtor-nd/letter-debtor-nd.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 2f4a25cfe..781cd21f4 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -7,12 +7,28 @@ module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, - [this.id]); + SELECT sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? + ORDER BY co.id DESC + LIMIT 1; + `, [this.id]); + if (!this.debtor.length) { + this.debtor = await db.findOne(` + SELECT sa.iban, + be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN company co ON co.supplierAccountFk = sa.id + WHERE co.code = ?; + `, [this.companyCode]); + } }, data() { return { -- 2.40.1 From 6416891918354820969fa2c0768b2a6a04976531 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 13:55:31 +0100 Subject: [PATCH 044/100] refs #6291 tinIsValid worker --- back/models/vn-user.js | 22 ------------------- .../08-route/03_create_and_clone.spec.js | 2 +- modules/worker/back/models/worker.js | 19 ++++++++++++++++ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/back/models/vn-user.js b/back/models/vn-user.js index 5ab0c755e..de5bf7b63 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -2,7 +2,6 @@ const vnModel = require('vn-loopback/common/models/vn-model'); const {Email} = require('vn-print'); const ForbiddenError = require('vn-loopback/util/forbiddenError'); const LoopBackContext = require('loopback-context'); -const validateTin = require('vn-loopback/util/validateTin'); module.exports = function(Self) { vnModel(Self); @@ -20,27 +19,6 @@ module.exports = function(Self) { // Validations - Self.validateAsync('fi', tinIsValid, { - message: 'Invalid TIN' - }); - - async function tinIsValid(err, done) { - if (!this.isTaxDataChecked) - return done(); - - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - const countryCode = this.fi?.toLowerCase().substring(0, 2); - - if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) - err(); - done(); - } - Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, diff --git a/e2e/paths/08-route/03_create_and_clone.spec.js b/e2e/paths/08-route/03_create_and_clone.spec.js index 0b8da98b4..31c0cfc18 100644 --- a/e2e/paths/08-route/03_create_and_clone.spec.js +++ b/e2e/paths/08-route/03_create_and_clone.spec.js @@ -26,7 +26,7 @@ describe('Route create path', () => { await page.waitToClick(selectors.createRouteView.submitButton); const message = await page.waitForSnackbar(); - expect(message.text).toContain('Access denied'); + expect(message.text).toContain('Access Denied'); }); }); diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 985d83e9f..48ff1da12 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -1,4 +1,5 @@ module.exports = Self => { + const validateTin = require('vn-loopback/util/validateTin'); require('../methods/worker/filter')(Self); require('../methods/worker/mySubordinates')(Self); require('../methods/worker/isSubordinate')(Self); @@ -23,4 +24,22 @@ module.exports = Self => { Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' }); + + Self.validateAsync('fi', tinIsValid, { + message: 'Invalid TIN' + }); + + async function tinIsValid(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + const countryCode = this.fi?.toLowerCase().substring(0, 2); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) + err(); + done(); + } }; -- 2.40.1 From 26a05a48401e1b493bdfb625b3e090bd637a5918 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 14 Dec 2023 09:14:21 +0100 Subject: [PATCH 045/100] fix: refs #3979 si se abona un abono sin almacen no falla --- modules/ticket/back/methods/sale/clone.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index a5ccb6de4..53a501844 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -109,7 +109,10 @@ module.exports = Self => { const newTicket = await models.Ticket.new(ctx, myOptions); - if (negative) { + const ticketRefund = await models.TicketRefund.findOne({ + where: {refundTicketFk: ticketId} + }, myOptions); + if (negative && (withWarehouse || !ticketRefund?.id)) { await models.TicketRefund.create({ originalTicketFk: ticketId, refundTicketFk: newTicket.id -- 2.40.1 From 22a9ffc1638d279a4d55d86c50f4b3a1f997342b Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 18 Dec 2023 12:33:04 +0100 Subject: [PATCH 046/100] refs #6291 dni --- db/dump/fixtures.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 499336243..44e6f9843 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2994,3 +2994,13 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) (1, 'Error in VAT calculation'), (2, 'Error in sales details'), (3, 'Error in customer data'); + +UPDATE `vn`.`client` + SET fi='65004204V' + WHERE id=1; + +UPDATE `vn`.`client` + SET fi='59328808D' + WHERE id=1106; + + -- 2.40.1 From 18e87a05c44ec4cc1dc7f344b016a8b4216dd69c Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 19 Dec 2023 10:07:17 +0100 Subject: [PATCH 047/100] refs #5525 st and nd --- db/changes/235001/00-supplier.sql | 3 +++ .../letter-debtor-nd/letter-debtor-nd.js | 27 +++++++++---------- .../email/letter-debtor-nd/locale/en.yml | 4 +-- .../email/letter-debtor-nd/sql/client.sql | 19 +++++++------ .../letter-debtor-st/letter-debtor-st.js | 27 +++++++++---------- .../templates/reports/sepa-core/locale/es.yml | 4 +-- .../templates/reports/sepa-core/locale/fr.yml | 16 +++++------ 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/db/changes/235001/00-supplier.sql b/db/changes/235001/00-supplier.sql index 704479130..e60707eca 100644 --- a/db/changes/235001/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -6,4 +6,7 @@ ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL, ADD CONSTRAINT `fk_supplierAccount_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE; +ALTER TABLE `vn`.`supplierAccount` +ADD UNIQUE KEY `uk_supplier_country` (`supplierFk`, `countryFk`); + diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 781cd21f4..41b6f1af8 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -7,27 +7,26 @@ module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, - be.name bankName, - sa.countryFk, - c.countryFk - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN company co ON co.supplierAccountFk = sa.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? - ORDER BY co.id DESC - LIMIT 1; + SELECT sa.id, + sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ?; `, [this.id]); - if (!this.debtor.length) { + if (!this.debtor) { this.debtor = await db.findOne(` SELECT sa.iban, be.name bankName FROM supplierAccount sa JOIN bankEntity be ON sa.bankEntityFk = be.id JOIN company co ON co.supplierAccountFk = sa.id - WHERE co.code = ?; - `, [this.companyCode]); + WHERE co.id = ?; + `, [this.companyId]); } }, data() { diff --git a/print/templates/email/letter-debtor-nd/locale/en.yml b/print/templates/email/letter-debtor-nd/locale/en.yml index 34b1c7b5f..9fb334339 100644 --- a/print/templates/email/letter-debtor-nd/locale/en.yml +++ b/print/templates/email/letter-debtor-nd/locale/en.yml @@ -6,12 +6,12 @@ sections: description: We are writing to you once again to inform you that your debt with our company remains unpaid, as you can verify in the attached statement. terms: Since the agreed payment deadlines have significantly passed, there should be no further delay in settling the outstanding amount. payMethod: - description: To do so, you have the following payment options: + description: To do so, you have the following payment options options: - Online payment through our website. - Deposit or transfer to the account number provided at the bottom of this letter, indicating your customer number. legalAction: - description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include: + description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include options: - Inclusion in negative credit and financial solvency records. - Legal proceedings. diff --git a/print/templates/email/letter-debtor-nd/sql/client.sql b/print/templates/email/letter-debtor-nd/sql/client.sql index d5da5d0d5..013a3b7d6 100644 --- a/print/templates/email/letter-debtor-nd/sql/client.sql +++ b/print/templates/email/letter-debtor-nd/sql/client.sql @@ -1,10 +1,9 @@ -SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName -FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk -WHERE c.id = ? AND cny.id = ? \ No newline at end of file +SELECT c.dueDay, + sa.iban, + be.name bankName + FROM client c + JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk + JOIN company cny + WHERE c.id = ? + AND cny.id = ? diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 76df43d70..b168f969f 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,27 +7,26 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, - be.name bankName, - sa.countryFk, - c.countryFk - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN company co ON co.supplierAccountFk = sa.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? - ORDER BY co.id DESC - LIMIT 1; + SELECT sa.id, + sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ?; `, [this.id]); - if (!this.debtor.length) { + if (!this.debtor) { this.debtor = await db.findOne(` SELECT sa.iban, be.name bankName FROM supplierAccount sa JOIN bankEntity be ON sa.bankEntityFk = be.id JOIN company co ON co.supplierAccountFk = sa.id - WHERE co.code = ?; - `, [this.companyCode]); + WHERE co.id = ?; + `, [this.companyId]); } }, data() { diff --git a/print/templates/reports/sepa-core/locale/es.yml b/print/templates/reports/sepa-core/locale/es.yml index ebb8dce1a..2737dc313 100644 --- a/print/templates/reports/sepa-core/locale/es.yml +++ b/print/templates/reports/sepa-core/locale/es.yml @@ -17,8 +17,6 @@ supplier: toCompleteBySupplier: A cumplimentar por el acreedor orderReference: Referencia de la orden de domiciliación identifier: Identificador del acreedor - iban: ES89000B97367486 - cif: B97367486-000 name: Nombre del acreedor street: Dirección location: CP - Población - Provincia @@ -47,4 +45,4 @@ instructions: title: Instrucciones accountFields: Rellenar los campos relativos a la cuenta bancaria signDocument: Firmar y sellar el documento. Para que tenga validez, en el sello debe aparecer el CIF/NIF. De no ser así, deberá acompañarse la solicitud de un certificado de titularidad de la cuenta. - thanks: ¡Gracias por su colaboración! \ No newline at end of file + thanks: ¡Gracias por su colaboración! diff --git a/print/templates/reports/sepa-core/locale/fr.yml b/print/templates/reports/sepa-core/locale/fr.yml index 3f39d18d4..355b880a1 100644 --- a/print/templates/reports/sepa-core/locale/fr.yml +++ b/print/templates/reports/sepa-core/locale/fr.yml @@ -1,11 +1,11 @@ reportName: direct-debit title: Direct Debit -description: En signant ce formulaire de mandat, vous autorisez VERDNATURA LEVANTE SL - à envoyer des instructions à votre banque pour débiter votre compte, et (B) votre banque - à débiter votre compte conformément aux instructions de VERDNATURA LEVANTE SL. - Vous bénéficiez d’un droit au remboursement par votre banque selon les conditions décrites - dans la convention que vous avez passée avec elle. Toute demande de remboursement doit être - présentée dans les 8 semaines suivant la date de débit de votre compte. +description: En signant ce formulaire de mandat, vous autorisez VERDNATURA LEVANTE SL + à envoyer des instructions à votre banque pour débiter votre compte, et (B) votre banque + à débiter votre compte conformément aux instructions de VERDNATURA LEVANTE SL. + Vous bénéficiez d’un droit au remboursement par votre banque selon les conditions décrites + dans la convention que vous avez passée avec elle. Toute demande de remboursement doit être + présentée dans les 8 semaines suivant la date de débit de votre compte. Votre banque peut vous renseigner au sujet de vos droits relatifs à ce mandat. documentCopy: Veuillez dater, signer et retourner ce document à votre banque. mandatoryFields: TOUS LES CHAMPS DOIVENT ÊTRE REINSEGNÉS IMPÉRATIVEMENT. @@ -13,8 +13,6 @@ sendOrder: APRÈS SIGNATURA, RENVOYER AU CRÉANCIER ET AU VOTRE ÉTABLISSEMENT F supplier: toCompleteBySupplier: Á compléter pour le créancier orderReference: Numéro de référence du mandat - iban: FR7630003012690002801121597 - cif: B97367486-000 identifier: Identifiant créancier name: Nom du céancier street: Adresse @@ -44,4 +42,4 @@ instructions: title: instructions accountFields: Remplissez les champs relatifs au compte bancaire signDocument: Signez et scellez le document. Pour être valide, le CIF / NIF doit apparaître sur le cachet. Sinon, la demande de certificat de propriété du compte doit être jointe. - thanks: Merci de votre collaboration! \ No newline at end of file + thanks: Merci de votre collaboration! -- 2.40.1 From acb0ec508f4aa76f21060fabdf5b287441047c81 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Dec 2023 12:09:01 +0100 Subject: [PATCH 048/100] refs #5499 feat: claimObservation --- back/methods/chat/spec/send.spec.js | 2 +- back/methods/chat/spec/sendQueued.spec.js | 2 +- back/methods/vn-user/specs/sign-in.spec.js | 2 +- db/dump/fixtures.sql | 3 + .../back/methods/claim/claimObservation.js | 70 +++++++++++++++++++ .../claim/specs/claimObservation.spec.js | 25 +++++++ modules/claim/back/models/claim.js | 10 +++ modules/claim/front/note/create/index.html | 4 +- 8 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 modules/claim/back/methods/claim/claimObservation.js create mode 100644 modules/claim/back/methods/claim/specs/claimObservation.spec.js diff --git a/back/methods/chat/spec/send.spec.js b/back/methods/chat/spec/send.spec.js index e910f3fab..084dc5aeb 100644 --- a/back/methods/chat/spec/send.spec.js +++ b/back/methods/chat/spec/send.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -describe('Chat send()', () => { +fdescribe('Chat send()', () => { it('should return true as response', async() => { let ctx = {req: {accessToken: {userId: 1}}}; let response = await models.Chat.send(ctx, '@salesPerson', 'I changed something'); diff --git a/back/methods/chat/spec/sendQueued.spec.js b/back/methods/chat/spec/sendQueued.spec.js index 67cd47f4a..155877067 100644 --- a/back/methods/chat/spec/sendQueued.spec.js +++ b/back/methods/chat/spec/sendQueued.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('Chat sendCheckingPresence()', () => { +fdescribe('Chat sendCheckingPresence()', () => { const today = Date.vnNew(); today.setHours(6, 0); const chatModel = models.Chat; diff --git a/back/methods/vn-user/specs/sign-in.spec.js b/back/methods/vn-user/specs/sign-in.spec.js index 1c4b4af51..bff844534 100644 --- a/back/methods/vn-user/specs/sign-in.spec.js +++ b/back/methods/vn-user/specs/sign-in.spec.js @@ -20,7 +20,7 @@ describe('VnUser Sign-in()', () => { let ctx = {req: {accessToken: accessToken}}; let signInLog = await SignInLog.find({where: {token: accessToken.id}}); - expect(signInLog.length).toEqual(1); + expect(signInLog.length).toEqual(0); expect(signInLog[0].userFk).toEqual(accessToken.userId); expect(signInLog[0].owner).toEqual(true); expect(login.token).toBeDefined(); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c94433e61..817838439 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3009,3 +3009,6 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) (1, 'Error in VAT calculation'), (2, 'Error in sales details'), (3, 'Error in customer data'); +-- Auto-generated SQL script #202312201041 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Claim','claimObservation','WRITE','ALLOW','ROLE','employee'); diff --git a/modules/claim/back/methods/claim/claimObservation.js b/modules/claim/back/methods/claim/claimObservation.js new file mode 100644 index 000000000..d6b758bcf --- /dev/null +++ b/modules/claim/back/methods/claim/claimObservation.js @@ -0,0 +1,70 @@ +module.exports = Self => { + Self.remoteMethod('claimObservation', { + description: 'Update a claim with privileges', + accessType: 'WRITE', + accepts: [{ + arg: 'ctx', + type: 'object', + http: {source: 'context'} + }, + { + arg: 'data', + type: 'object', + http: {source: 'body'} + }], + returns: { + type: 'object', + root: true + }, + http: { + verb: 'post', + path: `/claimObservation` + } + }); + + Self.claimObservation = async(ctx, data, options) => { + const {claimFk: id} = data; + const {models} = Self.app; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + try { + const claim = await models.Claim.findById(id, { + include: { + relation: 'client', + scope: { + include: { + relation: 'salesPersonUser' + } + } + } + }, myOptions); + // Get sales person from claim client + const salesPerson = claim.client().salesPersonUser(); + const message = { + body: data.text + }; + // await notifyClaimObservation(ctx, claim.workerFk, claim, newState.code); + await models.Chat.send(ctx, salesPerson.username, message); + + return updatedClaim; + } catch (e) { + + } + }; + + // async function notifyClaimObservation(ctx, from, to, claim, observation) { + // const models = Self.app.models; + // const url = await models.Url.getUrl(); + // const $t = ctx.req.__; // $translate + + // const message = $t(`Claim state has changed to ${state}`, { + // claimId: claim.id, + // clientName: claim.client().name, + // claimUrl: `${url}claim/${claim.id}/summary` + // }); + // await models.Chat.sendQueue(ctx, workerId, message); + // } +}; diff --git a/modules/claim/back/methods/claim/specs/claimObservation.spec.js b/modules/claim/back/methods/claim/specs/claimObservation.spec.js new file mode 100644 index 000000000..ea7b638e1 --- /dev/null +++ b/modules/claim/back/methods/claim/specs/claimObservation.spec.js @@ -0,0 +1,25 @@ +const {models} = require('vn-loopback/server/server'); + +fdescribe('Claim observation()', () => { + it('should save observation', async() => { + let ctx = {req: {accessToken: {userId: 1}}}; + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; + const data = { + claimFk: 9, + workerFk: 9, + text: 'test' + }; + try { + let response = await models.Claim.claimObservation(ctx, data, options); + + if (tx) await tx.commit(); + + expect(response).not.toBeUndefined(); + } catch (error) { + expect(error).toBeUndefined(); + if (tx) await tx.rollback(); + throw new Error(e); + } + }); +}); diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index 8e652f9fb..6e9a422f4 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -5,10 +5,20 @@ module.exports = Self => { require('../methods/claim/updateClaim')(Self); require('../methods/claim/regularizeClaim')(Self); require('../methods/claim/uploadFile')(Self); + require('../methods/claim/claimObservation')(Self); require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/updateClaimDestination')(Self); require('../methods/claim/downloadFile')(Self); require('../methods/claim/claimPickupPdf')(Self); require('../methods/claim/claimPickupEmail')(Self); require('../methods/claim/logs')(Self); + + Self.observe('after save', ctx => { + if (ctx.isNewInstance) return; + const changes = ctx.data || ctx.instance; + const orgData = ctx.currentInstance; + const loopBackContext = LoopBackContext.getCurrentContext(); + const accessToken = {req: loopBackContext.active}; + throw new Error(''); + }); }; diff --git a/modules/claim/front/note/create/index.html b/modules/claim/front/note/create/index.html index 304a8c004..c1666553b 100644 --- a/modules/claim/front/note/create/index.html +++ b/modules/claim/front/note/create/index.html @@ -1,6 +1,6 @@ - \ No newline at end of file + -- 2.40.1 From 5c5be788c1c09932b9b4e774bf62892ef2add3ff Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Dec 2023 14:08:11 +0100 Subject: [PATCH 049/100] refs #5499 feat: trigger for all changes --- loopback/locale/es.json | 5 ++-- modules/claim/back/models/claim.js | 37 +++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 01384efb4..c9ba1fb6d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -329,5 +329,6 @@ "The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima", "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima", "Cannot past travels with entries": "No se pueden pasar envíos con entradas", - "It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}" -} \ No newline at end of file + "It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}", + "This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada" +} diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index 6e9a422f4..65a1998cf 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -1,4 +1,6 @@ +const LoopBackContext = require('loopback-context'); module.exports = Self => { + let cache = {}; require('../methods/claim/filter')(Self); require('../methods/claim/getSummary')(Self); require('../methods/claim/createFromSales')(Self); @@ -13,12 +15,35 @@ module.exports = Self => { require('../methods/claim/claimPickupEmail')(Self); require('../methods/claim/logs')(Self); - Self.observe('after save', ctx => { + Self.observe('before save', async ctx => { if (ctx.isNewInstance) return; - const changes = ctx.data || ctx.instance; - const orgData = ctx.currentInstance; - const loopBackContext = LoopBackContext.getCurrentContext(); - const accessToken = {req: loopBackContext.active}; - throw new Error(''); + const {data, currentInstance} = ctx; + let changes = {}; + for (const [key, value] of Object.entries(data)) { + const change = currentInstance[key]; + if (change !== value) + changes[key] = value; + } + cache[currentInstance.id] = changes; }); + Self.observe('after save', async ctx => { + const changes = cache[ctx.instance.id]; + if (ctx.isNewInstance) return; + if (Object.keys(changes).length > 0) await sendMessage(ctx, changes); + + delete cache[ctx.instance.id]; + }); + async function sendMessage(ctx, changes) { + const loopBackContext = LoopBackContext.getCurrentContext(); + const {http} = loopBackContext.active; + + const message = buildMessage(http.req.__, ctx.instance, changes); + const instance = ctx.instance.client(); + await Self.app.models.Chat.send({...http}, instance.salesPersonUser().username, message); + } + + function buildMessage($t, instance, changes) { + let message = $t('This claim has been updated', {claimId: instance.id}); + return message; + } }; -- 2.40.1 From c4ff4c198420b1565075b931a4635a9182838f7e Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 21 Dec 2023 15:07:03 +0100 Subject: [PATCH 050/100] refs #6291 tin valid --- modules/worker/back/models/worker.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 48ff1da12..841b610ea 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -34,12 +34,17 @@ module.exports = Self => { fields: ['code'], where: {id: this.countryFk} }; + const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; - const countryCode = this.fi?.toLowerCase().substring(0, 2); + const client = (await Self.findById(this.id, { + include: {relation: 'client'}}))?.client(); + if (client) { + const countryCode = client.fi?.toLowerCase().substring(0, 2); - if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) - err(); + if (!client.fi || !validateTin(client.fi, code) || countryCode == code) + err(); + } done(); } }; -- 2.40.1 From 27a369bef4aa176fc4d43c5efb2a7f20239995ec Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 21 Dec 2023 18:34:22 +0100 Subject: [PATCH 051/100] refactor(ticketSms): refs #6259 merge ticksms to clientsms --- db/changes/235201/00-ticketSmsToClientSms.sql | 25 +++++++++++++++++ db/dump/fixtures.sql | 14 ++++++++++ modules/client/back/model-config.json | 3 -- modules/client/back/models/client-sms.json | 5 ++++ modules/client/back/models/ticket-sms.json | 28 ------------------- modules/ticket/back/methods/ticket/sendSms.js | 4 ++- .../back/methods/ticket/specs/sendSms.spec.js | 4 +-- 7 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 db/changes/235201/00-ticketSmsToClientSms.sql delete mode 100644 modules/client/back/models/ticket-sms.json diff --git a/db/changes/235201/00-ticketSmsToClientSms.sql b/db/changes/235201/00-ticketSmsToClientSms.sql new file mode 100644 index 000000000..f2aa73863 --- /dev/null +++ b/db/changes/235201/00-ticketSmsToClientSms.sql @@ -0,0 +1,25 @@ +ALTER TABLE `vn`.`clientSms` ADD `ticketFk` int(11) NULL; +ALTER TABLE `vn`.`clientSms` ADD CONSTRAINT `clientSms_FK_2` FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +INSERT INTO`vn`.`clientSms` (`clientFk`, `smsFk`, `ticketFk`) + SELECT `t`.`clientFk`, `s`.`smsFk`, `s`.`ticketFk` + FROM `vn`.`clientSms` `s` + JOIN `vn`.`ticket` `t` ON `t`.`id` = `s`.`ticketFk`; + +RENAME TABLE `vn`.`ticketSms` TO `vn`.`ticketSms__`; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSms_beforeInsert` + BEFORE INSERT ON `clientSms` + FOR EACH ROW +BEGIN + DECLARE vTicketOwner INT; + + SELECT clientFk INTO vTicketOwner + FROM ticket + WHERE id = NEW.ticketFk; + + IF NOT NEW.clientFk = vTicketOwner THEN + CALL util.throw('Unable to send an SMS ticket to a client who is not the owner'); + END IF; +END$$ \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8997e40b1..7ea766d61 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3009,3 +3009,17 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) (1, 'Error in VAT calculation'), (2, 'Error in sales details'), (3, 'Error in customer data'); + +INSERT INTO `vn`.`sms` (`id`, `senderFk`, `sender`, `destination`, `message`, `statusCode`, `status`, `created`) + VALUES (1, 66, '111111111', '0001111111111', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()), + (2, 66, '222222222', '0002222222222', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'PENDING', util.VN_CURDATE()), + (3, 66, '333333333', '0003333333333', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'ERROR', util.VN_CURDATE()), + (4, 66, '444444444', '0004444444444', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()); + +INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) + VALUES(1, 1103, 1, NULL), + (2, 1103, 2, NULL), + (3, 1103, 3, 32), + (4, 1103, 4, 32), + (13, 1101, 1, NULL), + (14, 1101, 4, 27); \ No newline at end of file diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index a21407732..fc1254dd8 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -113,9 +113,6 @@ "SageTransactionType": { "dataSource": "vn" }, - "TicketSms": { - "dataSource": "vn" - }, "TpvError": { "dataSource": "vn" }, diff --git a/modules/client/back/models/client-sms.json b/modules/client/back/models/client-sms.json index b2244ebbb..df1b58737 100644 --- a/modules/client/back/models/client-sms.json +++ b/modules/client/back/models/client-sms.json @@ -21,6 +21,11 @@ "type": "belongsTo", "model": "Sms", "foreignKey": "smsFk" + }, + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" } } } diff --git a/modules/client/back/models/ticket-sms.json b/modules/client/back/models/ticket-sms.json deleted file mode 100644 index 03f592f51..000000000 --- a/modules/client/back/models/ticket-sms.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "TicketSms", - "base": "VnModel", - "options": { - "mysql": { - "table": "ticketSms" - } - }, - "properties": { - "smsFk": { - "type": "number", - "id": true, - "description": "Identifier" - } - }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "sms": { - "type": "belongsTo", - "model": "Sms", - "foreignKey": "smsFk" - } - } -} diff --git a/modules/ticket/back/methods/ticket/sendSms.js b/modules/ticket/back/methods/ticket/sendSms.js index ffc95c6b4..36e52fe3d 100644 --- a/modules/ticket/back/methods/ticket/sendSms.js +++ b/modules/ticket/back/methods/ticket/sendSms.js @@ -33,7 +33,9 @@ module.exports = Self => { Self.sendSms = async(ctx, id, destination, message) => { const models = Self.app.models; const sms = await models.Sms.send(ctx, destination, message); - await models.TicketSms.create({ + const {clientFk} = await models.Ticket.findById(id); + await models.ClientSms.create({ + clientFk, ticketFk: id, smsFk: sms.id }); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index 3f93198d1..43507ec56 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -17,9 +17,9 @@ describe('ticket sendSms()', () => { const filter = { ticketFk: id }; - const ticketSms = await models.TicketSms.findOne(filter, options); + const clientSms = await models.ClientSms.findOne(filter, options); - expect(ticketSms.ticketFk).toEqual(id); + expect(clientSms.ticketFk).toEqual(id); await tx.rollback(); } catch (e) { -- 2.40.1 From 5a1c4ddea02f52c6e836246b70c1a5d0d459e082 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 26 Dec 2023 08:20:13 +0100 Subject: [PATCH 052/100] refactor(ticketSms): refs #6259 ticketSmsToClientSms --- .../00-ticketSmsToClientSms.sql | 16 ---------------- .../back/methods/ticket/specs/sendSms.spec.js | 8 ++++---- 2 files changed, 4 insertions(+), 20 deletions(-) rename db/changes/{240001 => 240201}/00-ticketSmsToClientSms.sql (52%) diff --git a/db/changes/240001/00-ticketSmsToClientSms.sql b/db/changes/240201/00-ticketSmsToClientSms.sql similarity index 52% rename from db/changes/240001/00-ticketSmsToClientSms.sql rename to db/changes/240201/00-ticketSmsToClientSms.sql index f2aa73863..cd3cf7dd3 100644 --- a/db/changes/240001/00-ticketSmsToClientSms.sql +++ b/db/changes/240201/00-ticketSmsToClientSms.sql @@ -7,19 +7,3 @@ INSERT INTO`vn`.`clientSms` (`clientFk`, `smsFk`, `ticketFk`) JOIN `vn`.`ticket` `t` ON `t`.`id` = `s`.`ticketFk`; RENAME TABLE `vn`.`ticketSms` TO `vn`.`ticketSms__`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSms_beforeInsert` - BEFORE INSERT ON `clientSms` - FOR EACH ROW -BEGIN - DECLARE vTicketOwner INT; - - SELECT clientFk INTO vTicketOwner - FROM ticket - WHERE id = NEW.ticketFk; - - IF NOT NEW.clientFk = vTicketOwner THEN - CALL util.throw('Unable to send an SMS ticket to a client who is not the owner'); - END IF; -END$$ \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index 43507ec56..afc1ada54 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -14,10 +14,10 @@ describe('ticket sendSms()', () => { await models.Ticket.sendSms(ctx, id, destination, message, options); - const filter = { - ticketFk: id - }; - const clientSms = await models.ClientSms.findOne(filter, options); + const clientSms = await models.ClientSms.findOne( + {where: {ticketFk: id}}, + options + ); expect(clientSms.ticketFk).toEqual(id); -- 2.40.1 From c77715d865713bcc8aa77692e1813397b60738cf Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 26 Dec 2023 15:03:10 +0100 Subject: [PATCH 053/100] refs #6291 validation original --- db/dump/fixtures.sql | 2 +- modules/worker/back/models/worker.js | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a63a7d314..2b339e191 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3014,7 +3014,7 @@ UPDATE `vn`.`client` SET fi='65004204V' WHERE id=1; -UPDATE `vn`.`client` +UPDATE `vn`.`worker` SET fi='59328808D' WHERE id=1106; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 841b610ea..712f2b09d 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -34,17 +34,12 @@ module.exports = Self => { fields: ['code'], where: {id: this.countryFk} }; - const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; - const client = (await Self.findById(this.id, { - include: {relation: 'client'}}))?.client(); - if (client) { - const countryCode = client.fi?.toLowerCase().substring(0, 2); + const countryCode = this.fi?.toLowerCase().substring(0, 2); - if (!client.fi || !validateTin(client.fi, code) || countryCode == code) - err(); - } + if (!this.fi || !validateTin(this.fi, code) || countryCode == code) + err(); done(); } }; -- 2.40.1 From df1c9e3d9f087d8aa59b8c5f147ad01bddd34e3b Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 27 Dec 2023 17:46:46 +0100 Subject: [PATCH 054/100] refs #5525 suppliercif --- print/templates/reports/sepa-core/sepa-core.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index efc9ed7ed..96c512a9d 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -8,7 +8,6 @@ module.exports = { this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); this.checkMainEntity(this.client); this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); - console.log(this.supplier); }, props: { id: { @@ -26,9 +25,9 @@ module.exports = { return db.findOne(` SELECT sa.iban, s.nif FROM supplierAccount sa - INNER JOIN supplier s ON sa.supplierFk = s.id - WHERE s.countryFk = ? - LIMIT 1`), [this.countryFk]; + JOIN company co ON co.supplierAccountFk = sa.id + JOIN supplier s ON sa.supplierFk = s.id + WHERE co.id = ?`) [this.companyId]; } } -- 2.40.1 From bfb31ad7c3f80d56530fed86e48cdfb46f56c4f2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 28 Dec 2023 11:46:34 +0100 Subject: [PATCH 055/100] refs #5525 supplier --- modules/supplier/back/models/supplier-account.json | 3 +++ print/templates/reports/sepa-core/sql/supplier.sql | 1 + 2 files changed, 4 insertions(+) diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index bc9cf0e24..9f9ad70c5 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -17,6 +17,9 @@ }, "beneficiary": { "type": "string" + }, + "supplierFk": { + "type": "string" } }, "relations": { diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index d93175118..72f950213 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -8,6 +8,7 @@ SELECT sp.name AS province, s.nif, sa.iban, + sa.supplierFk, be.name AS bankName FROM client c -- 2.40.1 From bbf1bb50e978318cb9ea2b8f9692615c49cb5055 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 28 Dec 2023 13:27:38 +0100 Subject: [PATCH 056/100] refs #5525 fix sql supplier for sepacore --- print/templates/reports/sepa-core/sql/supplier.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index 72f950213..ade4b048e 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -17,9 +17,11 @@ FROM LEFT JOIN country sc ON sc.id = s.countryFk LEFT JOIN province sp ON sp.id = s.provinceFk LEFT JOIN province p ON p.id = c.provinceFk - LEFT JOIN bankEntity be ON sa.supplierFk = s.id - LEFT JOIN supplierAccount sa ON sa.bankEntityFk = be.id - WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk) - ORDER BY - m.created DESC - LIMIT 1; + LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id +WHERE + (m.companyFk = ? OR m.companyFk IS NULL) + AND (c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)) +ORDER BY + m.created DESC +LIMIT 1; -- 2.40.1 From 1b8461034e12fce15f4918e517f9cbe7ff40a896 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Dec 2023 12:40:48 +0100 Subject: [PATCH 057/100] using hasAnyNegative: refs #6515 --- .../back/methods/invoiceOut/createManualInvoice.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 18e6903d6..043dfbead 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -85,7 +85,7 @@ module.exports = Self => { throw new UserError(`A ticket with an amount of zero can't be invoiced`); // Validates ticket nagative base - const hasNegativeBase = await getNegativeBase(ticketId, myOptions); + const hasNegativeBase = await getNegativeBase(maxShipped, clientId, companyId, myOptions); if (hasNegativeBase && company.code == 'VNL') throw new UserError(`A ticket with a negative base can't be invoiced`); } else { @@ -162,10 +162,13 @@ module.exports = Self => { return result.invoiceable; } - async function getNegativeBase(ticketId, options) { + async function getNegativeBase(maxShipped, clientId, companyId, options) { const models = Self.app.models; - const query = 'SELECT vn.hasSomeNegativeBase(?) AS base'; - const [result] = await models.InvoiceOut.rawSql(query, [ticketId], options); + await models.InvoiceOut.rawSql('CALL invoiceOut_exportationFromClient(?,?,?)', + [maxShipped, clientId, companyId], options + ); + const query = 'SELECT vn.hasAnyNegativeBase() AS base'; + const [result] = await models.InvoiceOut.rawSql(query, [], options); return result.base; } -- 2.40.1 From ccf5387e045c2f1deae0b7b8c83af29e175954e8 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 29 Dec 2023 12:44:24 +0100 Subject: [PATCH 058/100] refactor(state): refs #6366 unifyTicketChangeState --- .../methods/ticket-tracking/setDelivered.js | 2 +- modules/ticket/back/methods/ticket/state.js | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/ticket-tracking/setDelivered.js b/modules/ticket/back/methods/ticket-tracking/setDelivered.js index d3cdb192f..eded63d11 100644 --- a/modules/ticket/back/methods/ticket-tracking/setDelivered.js +++ b/modules/ticket/back/methods/ticket-tracking/setDelivered.js @@ -49,7 +49,7 @@ module.exports = Self => { for (const id of ticketIds) { const promise = await models.Ticket.state(ctx, { stateFk: state.id, - workerFk: worker.id, + userFk: worker.id, ticketFk: id }, myOptions); promises.push(promise); diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 3d9ca60e6..3b22fac3f 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -7,7 +7,6 @@ module.exports = Self => { accepts: [ { arg: 'data', - description: 'Model instance data', type: 'Object', required: true, http: {source: 'body'} @@ -37,21 +36,21 @@ module.exports = Self => { } try { - const {userId} = ctx.req.accessToken; - if (!params.stateFk && !params.code) throw new UserError('State cannot be blank'); if (params.stateFk) { const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions); params.code = code; + } else { + const {id} = await models.State.findOne({where: {code: params.code}}, myOptions); + params.stateFk = id; } if (!params.userFk) { const worker = await models.Worker.findOne({ - where: {id: userId} + where: {id: ctx.req.accessToken.userId} }, myOptions); - params.userFk = worker.id; } @@ -59,9 +58,10 @@ module.exports = Self => { fields: ['stateFk'] }, myOptions); - let oldStateAllowed; - if (ticketState) - oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions); + const oldStateAllowed = ticketState ? + await models.State.isEditable(ctx, ticketState.stateFk, myOptions) : + false; + const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions); if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true)) @@ -75,8 +75,7 @@ module.exports = Self => { limit: 1 }, myOptions); - if (params.workerFk) - await ticketTracking.updateAttribute('workerFk', params.workerFk, myOptions); + await ticketTracking.updateAttribute('userFk', params.userFk, myOptions); if (tx) await tx.commit(); -- 2.40.1 From c116bc56c3e23d52cff1ba6cda4eb396cd0aeaad Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 2 Jan 2024 19:37:51 +0100 Subject: [PATCH 059/100] refactor(clientSms): refs #6259 redirect to lilium --- modules/client/front/sms/index.html | 42 ++--------------------------- modules/client/front/sms/index.js | 28 ++++--------------- 2 files changed, 7 insertions(+), 63 deletions(-) diff --git a/modules/client/front/sms/index.html b/modules/client/front/sms/index.html index e2bc0785e..7fb3b870e 100644 --- a/modules/client/front/sms/index.html +++ b/modules/client/front/sms/index.html @@ -1,40 +1,2 @@ - - - - - - - - Sender - Destination - Message - Status - Created - - - - - - - {{::clientSms.sms.sender.name}} - - - {{::clientSms.sms.destination}} - {{::clientSms.sms.message}} - {{::clientSms.sms.status}} - {{::clientSms.sms.created | date:'dd/MM/yyyy HH:mm'}} - - - - - - - + + diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js index 6ad64282e..8fa130248 100644 --- a/modules/client/front/sms/index.js +++ b/modules/client/front/sms/index.js @@ -1,32 +1,14 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -export default class Controller extends Section { +class Controller extends Section { constructor($element, $) { super($element, $); + } - this.filter = { - fields: ['id', 'smsFk'], - include: { - relation: 'sms', - scope: { - fields: [ - 'senderFk', - 'sender', - 'destination', - 'message', - 'statusCode', - 'status', - 'created'], - include: { - relation: 'sender', - scope: { - fields: ['name'] - } - } - } - } - }; + async $onInit() { + this.$state.go('client.card.summary', {id: this.$params.id}); + window.location.href = await this.vnApp.getUrl(`Customer/${this.$params.id}/sms`); } } -- 2.40.1 From 3fbead7473e79bfd01e519f4113309d2365f2112 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 3 Jan 2024 13:44:20 +0100 Subject: [PATCH 060/100] refs #6291 fix tinIsValid --- modules/worker/back/models/worker.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 712f2b09d..b475bf26e 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -36,9 +36,8 @@ module.exports = Self => { }; const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; - const countryCode = this.fi?.toLowerCase().substring(0, 2); - if (!this.fi || !validateTin(this.fi, code) || countryCode == code) + if (!this.fi || !validateTin(this.fi, code)) err(); done(); } -- 2.40.1 From ab341b9b5e2e2b8b8584c755bdb74a97153f24ce Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 3 Jan 2024 15:36:39 +0100 Subject: [PATCH 061/100] test: refs #3979 test de clone --- modules/ticket/back/methods/sale/clone.js | 2 +- .../back/methods/sale/specs/clone.spec.js | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 modules/ticket/back/methods/sale/specs/clone.spec.js diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index 53a501844..233d114cf 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -43,7 +43,7 @@ module.exports = Self => { } for (const sale of sales) { - const newTicketId = mappedTickets.get(sale.ticketFk); + const newTicketId = group ? ticketsIds : mappedTickets.get(sale.ticketFk); const createdSale = await models.Sale.create({ ticketFk: newTicketId, diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js new file mode 100644 index 000000000..b12a7e982 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -0,0 +1,92 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('Ticket cloning - clone function', () => { + let ctx; + let options; + let tx; + + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.commit(); + }); + + it('should create new tickets with cloned sales with warehouse', async() => { + const salesIds = [1, 2, 3]; + const servicesIds = []; + const withWarehouse = true; + const group = false; + const negative = false; + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, group, negative, options); + + expect(newTickets).toBeDefined(); + expect(newTickets.length).toBeGreaterThan(0); + }); + + it('should handle negative quantities correctly', async() => { + const negative = true; + const salesIds = [7, 8]; + const newTickets = await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + + // Verify that the cloned sales have negative quantities + for (const ticket of newTickets) { + const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options); + sales.forEach(sale => { + expect(sale.quantity).toBeLessThan(0); + }); + } + }); + + it('should group sales into a single ticket if group is true', async() => { + const salesIds = [1, 2, 3, 4, 5]; + const group = true; + const newTickets = await models.Sale.clone(ctx, salesIds, [], false, group, false, options); + + expect(newTickets.length).toEqual(1); + // Additional assertions for ticket grouping + }); + + it('should create new components and services for cloned tickets', async() => { + const servicesIds = [2]; + const salesIds = [5]; + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, false, options); + + // Verify that components and services are created for each new ticket + for (const ticket of newTickets) { + const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options); + const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options); + const services = await models.TicketService.find({where: {ticketFk: ticket.id}}, options); + + expect(components.length).toBeGreaterThan(0); + expect(services.length).toBeGreaterThan(0); + } + }); + + it('should handle transaction rollback on error', async() => { + const negative = true; + const salesIds = [1, 2, 3, 4, 5]; + try { + await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + fail('Expected error was not thrown'); + } catch (error) { + expect(error).toBeDefined(); + } + }); +}); -- 2.40.1 From 2a65ad6b31d3055e6d13e345c5e86811ddf32ab9 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 4 Jan 2024 08:22:01 +0100 Subject: [PATCH 062/100] refs #6635 build: new version --- CHANGELOG.md | 7 +++++++ db/changes/240401/.gitkeep | 0 package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 db/changes/240401/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index 1907f46bd..69e93a309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2404.01] - 2024-01-25 + +### Added +### Changed +### Fixed + + ## [2402.01] - 2024-01-11 ### Added diff --git a/db/changes/240401/.gitkeep b/db/changes/240401/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package-lock.json b/package-lock.json index 012fb50e7..36e11dc8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "salix-back", - "version": "24.02.01", + "version": "24.04.01", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "salix-back", - "version": "24.02.01", + "version": "24.04.01", "license": "GPL-3.0", "dependencies": { "axios": "^1.2.2", diff --git a/package.json b/package.json index ab3d99e19..f13c44162 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.02.01", + "version": "24.04.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", -- 2.40.1 From 4cb82524cb96021c7527f652b0dfc8ebad3170b3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 4 Jan 2024 08:37:34 +0100 Subject: [PATCH 063/100] test: refs #3979 quito clone parametro group porque no se usa --- .../methods/invoiceOut/transferInvoice.js | 2 +- modules/ticket/back/methods/sale/clone.js | 6 ++--- modules/ticket/back/methods/sale/refund.js | 1 - .../back/methods/sale/specs/clone.spec.js | 24 ++++++------------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index dde535c99..2d77705e7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -78,7 +78,7 @@ module.exports = Self => { const sales = await models.Sale.find(filterTicket, myOptions); const salesIds = sales.map(sale => sale.id); - const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, false, myOptions); + const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, myOptions); const clonedTicketIds = []; for (const clonedTicket of clonedTickets) { diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index 233d114cf..661b656df 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, group, negative, options) => { + Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -28,8 +28,6 @@ module.exports = Self => { const mappedTickets = new Map(); - if (group) ticketsIds = [ticketsIds[0]]; - for (let ticketId of ticketsIds) { const newTicket = await createTicket( ctx, @@ -43,7 +41,7 @@ module.exports = Self => { } for (const sale of sales) { - const newTicketId = group ? ticketsIds : mappedTickets.get(sale.ticketFk); + const newTicketId = mappedTickets.get(sale.ticketFk); const createdSale = await models.Sale.create({ ticketFk: newTicketId, diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index 17b70f12b..c5d0415c0 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -47,7 +47,6 @@ module.exports = Self => { salesIds, servicesIds, withWarehouse, - false, true, myOptions ); diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index b12a7e982..095f94cad 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -25,16 +25,15 @@ describe('Ticket cloning - clone function', () => { }); afterEach(async() => { - await tx.commit(); + await tx.rollback(); }); it('should create new tickets with cloned sales with warehouse', async() => { const salesIds = [1, 2, 3]; const servicesIds = []; const withWarehouse = true; - const group = false; const negative = false; - const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, group, negative, options); + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, negative, options); expect(newTickets).toBeDefined(); expect(newTickets.length).toBeGreaterThan(0); @@ -43,9 +42,9 @@ describe('Ticket cloning - clone function', () => { it('should handle negative quantities correctly', async() => { const negative = true; const salesIds = [7, 8]; - const newTickets = await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + const servicesIds = []; + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options); - // Verify that the cloned sales have negative quantities for (const ticket of newTickets) { const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options); sales.forEach(sale => { @@ -54,21 +53,11 @@ describe('Ticket cloning - clone function', () => { } }); - it('should group sales into a single ticket if group is true', async() => { - const salesIds = [1, 2, 3, 4, 5]; - const group = true; - const newTickets = await models.Sale.clone(ctx, salesIds, [], false, group, false, options); - - expect(newTickets.length).toEqual(1); - // Additional assertions for ticket grouping - }); - it('should create new components and services for cloned tickets', async() => { const servicesIds = [2]; const salesIds = [5]; - const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, false, options); + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, options); - // Verify that components and services are created for each new ticket for (const ticket of newTickets) { const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options); const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options); @@ -82,8 +71,9 @@ describe('Ticket cloning - clone function', () => { it('should handle transaction rollback on error', async() => { const negative = true; const salesIds = [1, 2, 3, 4, 5]; + const servicesIds = []; try { - await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options); fail('Expected error was not thrown'); } catch (error) { expect(error).toBeDefined(); -- 2.40.1 From 767c6a6ac82f9650b96148a0b7f9eb9a1045472b Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 4 Jan 2024 15:01:56 +0100 Subject: [PATCH 064/100] test: refs #3979 fixtures arregladas para que los abonos sean negativos --- db/dump/fixtures.sql | 3 +-- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 2 +- modules/ticket/back/methods/sale/specs/clone.spec.js | 12 ------------ .../back/methods/ticket/specs/setDeleted.spec.js | 3 +-- modules/ticket/back/models/specs/sale.spec.js | 2 +- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 6e676f3e6..d341d628f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2910,8 +2910,7 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (1, 12), - (8, 10); + (24, 7); INSERT INTO `vn`.`deviceProductionModels` (`code`) VALUES diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 5e82306cc..471c19b7a 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -236,7 +236,7 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.accessToSearchResult('16'); + await page.accessToSearchResult('6'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); await page.waitToClick(selectors.globalItems.acceptButton); diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index 095f94cad..26506485a 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -67,16 +67,4 @@ describe('Ticket cloning - clone function', () => { expect(services.length).toBeGreaterThan(0); } }); - - it('should handle transaction rollback on error', async() => { - const negative = true; - const salesIds = [1, 2, 3, 4, 5]; - const servicesIds = []; - try { - await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options); - fail('Expected error was not thrown'); - } catch (error) { - expect(error).toBeDefined(); - } - }); }); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index b2e70697a..43bc2c2d9 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -3,7 +3,6 @@ const LoopBackContext = require('loopback-context'); describe('ticket setDeleted()', () => { const userId = 1106; - const employeeUser = 1110; const activeCtx = { accessToken: {userId: userId}, }; @@ -118,7 +117,7 @@ describe('ticket setDeleted()', () => { return value; }; - const ticketId = 12; + const ticketId = 7; await models.Ticket.setDeleted(ctx, ticketId, options); await tx.rollback(); diff --git a/modules/ticket/back/models/specs/sale.spec.js b/modules/ticket/back/models/specs/sale.spec.js index 4af44c991..d078dc8e2 100644 --- a/modules/ticket/back/models/specs/sale.spec.js +++ b/modules/ticket/back/models/specs/sale.spec.js @@ -132,7 +132,7 @@ describe('sale model ', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(9)); const tx = await models.Sale.beginTransaction({}); - const saleId = 13; + const saleId = 32; const newQuantity = -10; try { -- 2.40.1 From 71937a4df306f8b9105df452458255fe37f59d93 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 4 Jan 2024 15:17:16 +0100 Subject: [PATCH 065/100] refs #5499 feat: send RocketMessage when change state --- back/tests.js | 2 +- loopback/locale/en.json | 1 + loopback/locale/es.json | 1 + .../methods/claim/specs/updateClaim.spec.js | 91 ++++++++++++++++++- .../claim/back/methods/claim/updateClaim.js | 19 ++-- 5 files changed, 99 insertions(+), 15 deletions(-) diff --git a/back/tests.js b/back/tests.js index efade4d7d..c313df172 100644 --- a/back/tests.js +++ b/back/tests.js @@ -59,9 +59,9 @@ async function test() { const JunitReporter = require('jasmine-reporters'); jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); - jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; jasmine.exitOnCompletion = true; } + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000; const backSpecs = [ './back/**/*[sS]pec.js', diff --git a/loopback/locale/en.json b/loopback/locale/en.json index c5e8d4fcf..69f4b8e08 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -68,6 +68,7 @@ "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", "Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", + "Claim state has changed to": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*", "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", "Claim state has changed to canceled": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *canceled*", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9c26e7856..fc5b8ba0b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -135,6 +135,7 @@ "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", "Change quantity": "{{concept}} cambia de {{oldQuantity}} a {{newQuantity}}", "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "Claim state has changed to": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *{{newState}}*", "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", "Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 85ada869a..0922c0953 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,8 +1,9 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); - -describe('Update Claim', () => { +const i18n = require('i18n'); +fdescribe('Update Claim', () => { let url; + let claimStatesMap = {}; beforeAll(async() => { url = await app.models.Url.getUrl(); const activeCtx = { @@ -16,6 +17,8 @@ describe('Update Claim', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); + const claimStates = await app.models.ClaimState.find(); + claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); }); const newDate = Date.vnNew(); const originalData = { @@ -29,7 +32,7 @@ describe('Update Claim', () => { observation: 'observation' }; - it(`should throw an error as the user doesn't have rights`, async() => { + fit(`should throw an error as the user doesn't have rights`, async() => { const tx = await app.models.Claim.beginTransaction({}); let error; @@ -62,7 +65,7 @@ describe('Update Claim', () => { expect(error.message).toEqual(`You don't have enough privileges to change that field`); }); - it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { + fit(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); try { @@ -103,6 +106,86 @@ describe('Update Claim', () => { } }); + it(`should success to update the claimState to 'pending' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const pendingState = claimStatesMap.pending; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: pendingState, + hasToPickUp: false + } + }; + ctx.req.__ = i18n; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const incompleteState = 5; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: incompleteState, + hasToPickUp: false + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index d99528413..488410633 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -96,12 +96,10 @@ module.exports = Self => { // When claimState has been changed if (args.claimStateFk) { const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); - if (newState.hasToNotify) { - if (newState.code == 'incomplete') - await notifyStateChange(ctx, salesPerson.id, claim, newState.code); - if (newState.code == 'canceled') - await notifyStateChange(ctx, claim.workerFk, claim, newState.code); - } + // if (newState.code == 'incomplete') + await notifyStateChange(ctx, salesPerson.id, claim, newState.code); + if (newState.code == 'canceled') + await notifyStateChange(ctx, claim.workerFk, claim, newState.code); } if (tx) await tx.commit(); @@ -113,17 +111,18 @@ module.exports = Self => { } }; - async function notifyStateChange(ctx, workerId, claim, state) { + async function notifyStateChange(ctx, id, claim, state) { const models = Self.app.models; const url = await models.Url.getUrl(); const $t = ctx.req.__; // $translate - const message = $t(`Claim state has changed to ${state}`, { + const message = $t(`Claim state has changed to`, { claimId: claim.id, clientName: claim.client().name, - claimUrl: `${url}claim/${claim.id}/summary` + claimUrl: `${url}claim/${claim.id}/summary`, + newState: state }); - await models.Chat.sendCheckingPresence(ctx, workerId, message); + await models.Chat.sendCheckingPresence(ctx, id, message); } async function notifyPickUp(ctx, workerId, claim) { -- 2.40.1 From 8ee6cfb01517bc9184b3a5807653f6021c8e461e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 4 Jan 2024 15:36:35 +0100 Subject: [PATCH 066/100] refs #5499 feat: send RocketMessage when change state --- back/methods/chat/spec/send.spec.js | 2 +- back/methods/chat/spec/sendQueued.spec.js | 2 +- .../back/methods/claim/claimObservation.js | 70 ------ .../claim/specs/claimObservation.spec.js | 25 -- .../methods/claim/specs/updateClaim.spec.js | 213 ++++++++++-------- modules/claim/back/models/claim.js | 35 --- 6 files changed, 124 insertions(+), 223 deletions(-) delete mode 100644 modules/claim/back/methods/claim/claimObservation.js delete mode 100644 modules/claim/back/methods/claim/specs/claimObservation.spec.js diff --git a/back/methods/chat/spec/send.spec.js b/back/methods/chat/spec/send.spec.js index 084dc5aeb..e910f3fab 100644 --- a/back/methods/chat/spec/send.spec.js +++ b/back/methods/chat/spec/send.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('Chat send()', () => { +describe('Chat send()', () => { it('should return true as response', async() => { let ctx = {req: {accessToken: {userId: 1}}}; let response = await models.Chat.send(ctx, '@salesPerson', 'I changed something'); diff --git a/back/methods/chat/spec/sendQueued.spec.js b/back/methods/chat/spec/sendQueued.spec.js index 155877067..67cd47f4a 100644 --- a/back/methods/chat/spec/sendQueued.spec.js +++ b/back/methods/chat/spec/sendQueued.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('Chat sendCheckingPresence()', () => { +describe('Chat sendCheckingPresence()', () => { const today = Date.vnNew(); today.setHours(6, 0); const chatModel = models.Chat; diff --git a/modules/claim/back/methods/claim/claimObservation.js b/modules/claim/back/methods/claim/claimObservation.js deleted file mode 100644 index d6b758bcf..000000000 --- a/modules/claim/back/methods/claim/claimObservation.js +++ /dev/null @@ -1,70 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('claimObservation', { - description: 'Update a claim with privileges', - accessType: 'WRITE', - accepts: [{ - arg: 'ctx', - type: 'object', - http: {source: 'context'} - }, - { - arg: 'data', - type: 'object', - http: {source: 'body'} - }], - returns: { - type: 'object', - root: true - }, - http: { - verb: 'post', - path: `/claimObservation` - } - }); - - Self.claimObservation = async(ctx, data, options) => { - const {claimFk: id} = data; - const {models} = Self.app; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - try { - const claim = await models.Claim.findById(id, { - include: { - relation: 'client', - scope: { - include: { - relation: 'salesPersonUser' - } - } - } - }, myOptions); - // Get sales person from claim client - const salesPerson = claim.client().salesPersonUser(); - const message = { - body: data.text - }; - // await notifyClaimObservation(ctx, claim.workerFk, claim, newState.code); - await models.Chat.send(ctx, salesPerson.username, message); - - return updatedClaim; - } catch (e) { - - } - }; - - // async function notifyClaimObservation(ctx, from, to, claim, observation) { - // const models = Self.app.models; - // const url = await models.Url.getUrl(); - // const $t = ctx.req.__; // $translate - - // const message = $t(`Claim state has changed to ${state}`, { - // claimId: claim.id, - // clientName: claim.client().name, - // claimUrl: `${url}claim/${claim.id}/summary` - // }); - // await models.Chat.sendQueue(ctx, workerId, message); - // } -}; diff --git a/modules/claim/back/methods/claim/specs/claimObservation.spec.js b/modules/claim/back/methods/claim/specs/claimObservation.spec.js deleted file mode 100644 index ea7b638e1..000000000 --- a/modules/claim/back/methods/claim/specs/claimObservation.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -fdescribe('Claim observation()', () => { - it('should save observation', async() => { - let ctx = {req: {accessToken: {userId: 1}}}; - const tx = await models.Supplier.beginTransaction({}); - const options = {transaction: tx}; - const data = { - claimFk: 9, - workerFk: 9, - text: 'test' - }; - try { - let response = await models.Claim.claimObservation(ctx, data, options); - - if (tx) await tx.commit(); - - expect(response).not.toBeUndefined(); - } catch (error) { - expect(error).toBeUndefined(); - if (tx) await tx.rollback(); - throw new Error(e); - } - }); -}); diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 0922c0953..e2d5fcfeb 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); const i18n = require('i18n'); -fdescribe('Update Claim', () => { +describe('Update Claim', () => { let url; let claimStatesMap = {}; beforeAll(async() => { @@ -32,7 +32,7 @@ fdescribe('Update Claim', () => { observation: 'observation' }; - fit(`should throw an error as the user doesn't have rights`, async() => { + it(`should throw an error as the user doesn't have rights`, async() => { const tx = await app.models.Claim.beginTransaction({}); let error; @@ -65,47 +65,6 @@ fdescribe('Update Claim', () => { expect(error.message).toEqual(`You don't have enough privileges to change that field`); }); - fit(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { - const tx = await app.models.Claim.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const newClaim = await app.models.Claim.create(originalData, options); - - const chatModel = app.models.Chat; - spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); - - const canceledState = 4; - const claimManagerId = 72; - const ctx = { - req: { - accessToken: {userId: claimManagerId}, - headers: {origin: url} - }, - args: { - observation: 'valid observation', - claimStateFk: canceledState, - hasToPickUp: false - } - }; - ctx.req.__ = (value, params) => { - return params.nickname; - }; - await app.models.Claim.updateClaim(ctx, newClaim.id, options); - - let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); - - expect(updatedClaim.observation).toEqual(ctx.args.observation); - expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - it(`should success to update the claimState to 'pending' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); @@ -130,7 +89,124 @@ fdescribe('Update Claim', () => { hasToPickUp: false } }; - ctx.req.__ = i18n; + ctx.req.__ = i18n.__; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'managed' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const managedState = claimStatesMap.managed; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: managedState, + hasToPickUp: false + } + }; + ctx.req.__ = i18n.__; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'resolved' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const resolvedState = claimStatesMap.resolved; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: resolvedState, + hasToPickUp: false + } + }; + ctx.req.__ = i18n.__; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const canceledState = claimStatesMap.canceled; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: canceledState, + hasToPickUp: false + } + }; + ctx.req.__ = i18n.__; await app.models.Claim.updateClaim(ctx, newClaim.id, options); let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); @@ -169,50 +245,7 @@ fdescribe('Update Claim', () => { hasToPickUp: false } }; - ctx.req.__ = (value, params) => { - return params.nickname; - }; - await app.models.Claim.updateClaim(ctx, newClaim.id, options); - - let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); - - expect(updatedClaim.observation).toEqual(ctx.args.observation); - expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { - const tx = await app.models.Claim.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const newClaim = await app.models.Claim.create(originalData, options); - - const chatModel = app.models.Chat; - spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); - - const incompleteState = 5; - const claimManagerId = 72; - const ctx = { - req: { - accessToken: {userId: claimManagerId}, - headers: {origin: url} - }, - args: { - observation: 'valid observation', - claimStateFk: incompleteState, - hasToPickUp: false - } - }; - ctx.req.__ = (value, params) => { - return params.nickname; - }; + ctx.req.__ = i18n.__; await app.models.Claim.updateClaim(ctx, newClaim.id, options); let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); @@ -251,9 +284,7 @@ fdescribe('Update Claim', () => { hasToPickUp: true } }; - ctx.req.__ = (value, params) => { - return params.nickname; - }; + ctx.req.__ = i18n.__; await app.models.Claim.updateClaim(ctx, newClaim.id, options); let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index 65a1998cf..8e652f9fb 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -1,49 +1,14 @@ -const LoopBackContext = require('loopback-context'); module.exports = Self => { - let cache = {}; require('../methods/claim/filter')(Self); require('../methods/claim/getSummary')(Self); require('../methods/claim/createFromSales')(Self); require('../methods/claim/updateClaim')(Self); require('../methods/claim/regularizeClaim')(Self); require('../methods/claim/uploadFile')(Self); - require('../methods/claim/claimObservation')(Self); require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/updateClaimDestination')(Self); require('../methods/claim/downloadFile')(Self); require('../methods/claim/claimPickupPdf')(Self); require('../methods/claim/claimPickupEmail')(Self); require('../methods/claim/logs')(Self); - - Self.observe('before save', async ctx => { - if (ctx.isNewInstance) return; - const {data, currentInstance} = ctx; - let changes = {}; - for (const [key, value] of Object.entries(data)) { - const change = currentInstance[key]; - if (change !== value) - changes[key] = value; - } - cache[currentInstance.id] = changes; - }); - Self.observe('after save', async ctx => { - const changes = cache[ctx.instance.id]; - if (ctx.isNewInstance) return; - if (Object.keys(changes).length > 0) await sendMessage(ctx, changes); - - delete cache[ctx.instance.id]; - }); - async function sendMessage(ctx, changes) { - const loopBackContext = LoopBackContext.getCurrentContext(); - const {http} = loopBackContext.active; - - const message = buildMessage(http.req.__, ctx.instance, changes); - const instance = ctx.instance.client(); - await Self.app.models.Chat.send({...http}, instance.salesPersonUser().username, message); - } - - function buildMessage($t, instance, changes) { - let message = $t('This claim has been updated', {claimId: instance.id}); - return message; - } }; -- 2.40.1 From e9773b3885094080e432f0263f023a140fe2dd80 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 4 Jan 2024 18:56:31 +0100 Subject: [PATCH 067/100] refactor(state): refs #6366 simplify if condition --- modules/ticket/back/methods/ticket/saveSign.js | 2 -- modules/ticket/back/methods/ticket/state.js | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 9f953cb1a..e062e6f84 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -136,8 +136,6 @@ module.exports = Self => { code: 'DELIVERED' } }, options); - if (!deliveryState) - throw new UserError('The DELIVERED state does not exist'); await models.Ticket.state(ctx, { ticketFk: ticketId, diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 3b22fac3f..fea9475f8 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -58,13 +58,10 @@ module.exports = Self => { fields: ['stateFk'] }, myOptions); - const oldStateAllowed = ticketState ? - await models.State.isEditable(ctx, ticketState.stateFk, myOptions) : - false; - + const oldStateAllowed = ticketState && await models.State.isEditable(ctx, ticketState.stateFk, myOptions); const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions); - if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true)) + if ((ticketState && !oldStateAllowed) || !newStateAllowed) throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); -- 2.40.1 From c72311860bbdf54186ca4962ff2d0f905c324281 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 8 Jan 2024 09:06:22 +0100 Subject: [PATCH 068/100] refs #647 remove e2e --- .../vn/ticket_componentMakeUpdate.spec.js | 123 ------------------ e2e/paths/03-worker/04_time_control.spec.js | 57 -------- .../05-ticket/01-sale/02_edit_sale.spec.js | 11 -- e2e/paths/05-ticket/11_diary.spec.js | 31 ----- e2e/paths/06-claim/02_detail.spec.js | 114 ---------------- .../10-travel/02_basic_data_and_log.spec.js | 13 -- front/core/components/treeview/index.spec.js | 12 -- .../methods/boxing/specs/getVideo.spec.js | 40 ------ 8 files changed, 401 deletions(-) delete mode 100644 db/tests/vn/ticket_componentMakeUpdate.spec.js delete mode 100644 e2e/paths/05-ticket/11_diary.spec.js delete mode 100644 e2e/paths/06-claim/02_detail.spec.js delete mode 100644 modules/ticket/back/methods/boxing/specs/getVideo.spec.js diff --git a/db/tests/vn/ticket_componentMakeUpdate.spec.js b/db/tests/vn/ticket_componentMakeUpdate.spec.js deleted file mode 100644 index a059f1060..000000000 --- a/db/tests/vn/ticket_componentMakeUpdate.spec.js +++ /dev/null @@ -1,123 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -// 2277 solucionar problema al testear procedimiento con start transaction / rollback -xdescribe('ticket_componentMakeUpdate()', () => { - it('should recalculate the ticket components without make modifications', async() => { - let stmts = []; - let stmt; - - let params = { - ticketId: 11, - clientId: 1102, - agencyModeId: 2, - addressId: 122, - zoneId: 3, - warehouseId: 1, - companyId: 442, - isDeleted: 0, - hasToBeUnrouted: 0, - componentOption: 1 - }; - - stmts.push('START TRANSACTION'); - - stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [ - params.ticketId - ]); - stmts.push(stmt); - - let originalTicketIndex = stmts.push(stmt) - 1; - - stmt = new ParameterizedSQL('CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, DATE_ADD(CURDATE(), INTERVAL +1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY), ?, ?, ?)', [ - params.ticketId, - params.clientId, - params.agencyModeId, - params.addressId, - params.zoneId, - params.warehouseId, - params.companyId, - params.isDeleted, - params.hasToBeUnrouted, - params.componentOption - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [ - params.ticketId - ]); - stmts.push(stmt); - - let updatedTicketIndex = stmts.push(stmt) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let originalTicketData = result[originalTicketIndex]; - let updatedTicketData = result[updatedTicketIndex]; - - expect(originalTicketData[0].isDeleted).toEqual(updatedTicketData[0].isDeleted); - expect(originalTicketData[0].routeFk).toEqual(updatedTicketData[0].routeFk); - }); - - it('should delete and unroute a ticket and recalculate the components', async() => { - let stmts = []; - let stmt; - - let params = { - ticketId: 11, - clientId: 1102, - agencyModeId: 2, - addressId: 122, - zoneId: 3, - warehouseId: 1, - companyId: 442, - isDeleted: 1, - hasToBeUnrouted: 1, - componentOption: 1 - }; - - stmts.push('START TRANSACTION'); - - stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [ - params.ticketId - ]); - stmts.push(stmt); - - let originalTicketIndex = stmts.push(stmt) - 1; - - stmt = new ParameterizedSQL('CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, DATE_ADD(CURDATE(), INTERVAL +1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY), ?, ?, ?)', [ - params.ticketId, - params.clientId, - params.agencyModeId, - params.addressId, - params.zoneId, - params.warehouseId, - params.companyId, - params.isDeleted, - params.hasToBeUnrouted, - params.componentOption - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT * FROM vn.ticket WHERE id = ?', [ - params.ticketId - ]); - stmts.push(stmt); - - let updatedTicketIndex = stmts.push(stmt) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let originalTicketData = result[originalTicketIndex]; - let updatedTicketData = result[updatedTicketIndex]; - - expect(originalTicketData[0].isDeleted).not.toEqual(updatedTicketData[0].isDeleted); - expect(originalTicketData[0].routeFk).not.toEqual(updatedTicketData[0].routeFk); - }); -}); diff --git a/e2e/paths/03-worker/04_time_control.spec.js b/e2e/paths/03-worker/04_time_control.spec.js index 5f64aa6ce..c6589d2e3 100644 --- a/e2e/paths/03-worker/04_time_control.spec.js +++ b/e2e/paths/03-worker/04_time_control.spec.js @@ -56,63 +56,6 @@ describe('Worker time control path', () => { expect(result).toContain(month); }); - it(`should return error when insert 'out' of first entry`, async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton); - await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm); - await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out'); - await page.respondToDialog('accept'); - const message = await page.waitForSnackbar(); - - expect(message.text).toBeDefined(); - }); - - it(`should insert 'in' monday`, async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton); - await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm); - await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in'); - await page.respondToDialog('accept'); - const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText'); - - expect(result).toEqual(eightAm); - }); - - it(`should insert 'out' monday`, async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton); - await page.pickTime(selectors.workerTimeControl.dialogTimeInput, fourPm); - await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out'); - await page.respondToDialog('accept'); - const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfMonday, 'innerText'); - - expect(result).toEqual(fourPm); - }); - - it(`should check Hank Pym worked 8:20 hours`, async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - await page.waitForTextInElement(selectors.workerTimeControl.mondayWorkedHours, '08:20 h.'); - await page.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '08:20 h.'); - }); - - it('should remove first entry of monday', async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - await page.waitForTextInElement(selectors.workerTimeControl.firstEntryOfMonday, eightAm); - await page.waitForTextInElement(selectors.workerTimeControl.secondEntryOfMonday, fourPm); - await page.waitToClick(selectors.workerTimeControl.firstEntryOfMondayDelete); - await page.respondToDialog('accept'); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Entry removed'); - }); - - it(`should be the 'out' the first entry of monday`, async() => { - pending('https://redmine.verdnatura.es/issues/4707'); - const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText'); - - expect(result).toEqual(fourPm); - }); - it('should change week of month', async() => { await page.click(selectors.workerTimeControl.thrirdWeekDay); const result = await page.getProperty(selectors.workerTimeControl.mondayWorkedHours, 'innerText'); diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 5e82306cc..b74f81253 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -188,17 +188,6 @@ describe('Ticket Edit sale path', () => { expect(result).toContain('22.50'); }); - it('should check in the history that logs has been added', async() => { - pending('https://redmine.verdnatura.es/issues/5455'); - await page.reload({waitUntil: ['networkidle0', 'domcontentloaded']}); - await page.waitToClick(selectors.ticketSales.firstSaleHistoryButton); - await page.waitForSelector(selectors.ticketSales.firstSaleHistory); - const result = await page.countElement(selectors.ticketSales.firstSaleHistory); - - expect(result).toBeGreaterThan(0); - await page.waitToClick(selectors.ticketSales.closeHistory); - }); - it('should recalculate price of sales', async() => { await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); await page.waitToClick(selectors.ticketSales.secondSaleCheckbox); diff --git a/e2e/paths/05-ticket/11_diary.spec.js b/e2e/paths/05-ticket/11_diary.spec.js deleted file mode 100644 index e4c63855a..000000000 --- a/e2e/paths/05-ticket/11_diary.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -import selectors from '../../helpers/selectors.js'; -import getBrowser from '../../helpers/puppeteer'; - -// #2221 Local MySQL8 crashes when rest method Items/getBalance is called -xdescribe('Ticket diary path', () => { - let page; - - beforeAll(async() => { - page = (await getBrowser()).page; - await page.loginAndModule('employee', 'ticket'); - }); - - afterAll(async() => { - await page.browser().close(); - }); - - it(`should navigate to item diary from ticket sale and check the lines`, async() => { - await page.accessToSearchResult('1'); - await page.waitToClick(selectors.ticketSummary.firstSaleItemId); - await page.waitToClick(selectors.ticketSummary.popoverDiaryButton); - await page.waitForState('item.card.diary'); - - const secondIdClass = await page.getClassName(selectors.itemDiary.secondTicketId); - const fourthBalanceClass = await page.getClassName(selectors.itemDiary.fourthBalance); - const firstBalanceClass = await page.getClassName(selectors.itemDiary.firstBalance); - - expect(secondIdClass).toContain('message'); - expect(fourthBalanceClass).toContain('message'); - expect(firstBalanceClass).toContain('balance'); - }); -}); diff --git a/e2e/paths/06-claim/02_detail.spec.js b/e2e/paths/06-claim/02_detail.spec.js deleted file mode 100644 index eb4ac5d71..000000000 --- a/e2e/paths/06-claim/02_detail.spec.js +++ /dev/null @@ -1,114 +0,0 @@ -import selectors from '../../helpers/selectors.js'; -import getBrowser from '../../helpers/puppeteer.js'; - -// #1528 e2e claim/detail -xdescribe('Claim detail', () => { - let browser; - let page; - - beforeAll(async() => { - browser = await getBrowser(); - page = browser.page; - await page.loginAndModule('salesPerson', 'claim'); - await page.accessToSearchResult('1'); - await page.accessToSection('claim.card.detail'); - }); - - afterAll(async() => { - await browser.close(); - }); - - it('should add the first claimable item from ticket to the claim', async() => { - await page.waitToClick(selectors.claimDetail.addItemButton); - await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should confirm the claim contains now two items', async() => { - const result = await page.countElement(selectors.claimDetail.claimDetailLine); - - expect(result).toEqual(2); - }); - - it('should edit de first item claimed quantity', async() => { - await page.clearInput(selectors.claimDetail.firstItemQuantityInput); // selector deleted, find new upon fixes - await page.write(selectors.claimDetail.firstItemQuantityInput, '4'); // selector deleted, find new upon fixes - await page.keyboard.press('Enter'); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should confirm the first item quantity, and the claimed total were correctly edited', async() => { - const claimedQuantity = page - .waitToGetProperty(selectors.claimDetail.firstItemQuantityInput, 'value'); // selector deleted, find new upon fixes - - const totalClaimed = page - .waitToGetProperty(selectors.claimDetail.totalClaimed, 'innerText'); - - expect(claimedQuantity).toEqual('4'); - expect(totalClaimed).toContain('€47.62'); - }); - - it('should login as salesAssistant and navigate to the claim.detail section', async() => { - await page.loginAndModule('salesAssistant', 'claim'); - await page.accessToSearchResult('1'); - await page.accessToSection('claim.card.detail'); - let url = await page.expectURL('/detail'); // replace with waitForState - - expect(url).toBe(true); - }); - - it('should edit de second item claimed discount', async() => { - await page.waitToClick(selectors.claimDetail.secondItemDiscount); - await page.write(selectors.claimDetail.discount, '100'); - await page.keyboard.press('Enter'); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should check the mana is the expected one', async() => { - await page.waitToClick(selectors.claimDetail.secondItemDiscount); - const result = await page.waitToGetProperty(selectors.claimDetail.discoutPopoverMana, 'innerText'); - - expect(result).toContain('MANÁ: €106'); - }); - - it('should delete the second item from the claim', async() => { - await page.waitToClick(selectors.claimDetail.secondItemDeleteButton); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it('should confirm the claim contains now one item', async() => { - const result = await page.countElement(selectors.claimDetail.claimDetailLine); - - expect(result).toEqual(1); - }); - - it('should add the deleted ticket from to the claim', async() => { - await page.waitToClick(selectors.claimDetail.addItemButton); - await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Data saved!'); - }); - - it(`should have been redirected to the next section in claims`, async() => { - let url = await page.expectURL('development'); // replace with waitForState - - expect(url).toBe(true); - }); - - it('should navigate back to claim.detail to confirm the claim contains now two items', async() => { - await page.accessToSection('claim.card.detail'); - await page.waitForSelector(selectors.claimDetail.claimDetailLine); - const result = await page.countElement(selectors.claimDetail.claimDetailLine); - - expect(result).toEqual(2); - }); -}); diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index 0079e8023..e6c601d7d 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -105,17 +105,4 @@ describe('Travel basic data path', () => { it(`should check the received checkbox was saved even tho it doesn't make sense`, async() => { await page.waitForClassPresent(selectors.travelBasicData.received, 'checked'); }); - - it('should navigate to the travel logs', async() => { - pending('https://redmine.verdnatura.es/issues/5455'); - await page.accessToSection('travel.card.log'); - await page.waitForState('travel.card.log'); - }); - - it('should check the 1st log contains details from the changes made', async() => { - pending('https://redmine.verdnatura.es/issues/5455'); - const result = await page.waitToGetProperty(selectors.travelLog.firstLogFirstTD, 'innerText'); - - expect(result).toContain('new reference!'); - }); }); diff --git a/front/core/components/treeview/index.spec.js b/front/core/components/treeview/index.spec.js index 9277f3ee4..1979d517f 100644 --- a/front/core/components/treeview/index.spec.js +++ b/front/core/components/treeview/index.spec.js @@ -33,18 +33,6 @@ describe('Component vnTreeview', () => { $element.remove(); }); - // See how to test DOM element in Jest - xdescribe('undrop()', () => { - it(`should reset all drop events and properties`, () => { - controller.dropping = angular.element(``); - jest.spyOn(controller.dropping.classList, 'remove'); - - controller.undrop(); - - expect(controller.dropping).toBeNull(); - }); - }); - describe('dragOver()', () => { it(`should set the dragClientY property`, () => { const event = new Event('dragover'); diff --git a/modules/ticket/back/methods/boxing/specs/getVideo.spec.js b/modules/ticket/back/methods/boxing/specs/getVideo.spec.js deleted file mode 100644 index 8e8cdc5b9..000000000 --- a/modules/ticket/back/methods/boxing/specs/getVideo.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -const models = require('vn-loopback/server/server').models; -const https = require('https'); - -xdescribe('boxing getVideo()', () => { - it('should return data', async() => { - const tx = await models.PackingSiteConfig.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const id = 1; - const video = 'video.mp4'; - - const response = { - pipe: () => {}, - on: () => {}, - end: () => {}, - }; - - const req = { - headers: 'apiHeader', - data: { - pipe: () => {}, - on: () => {}, - } - }; - - spyOn(https, 'request').and.returnValue(response); - - const result = await models.Boxing.getVideo(id, video, req, null, options); - - expect(result[0]).toEqual(response.data.videos[0].filename); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); -- 2.40.1 From f4062ab47b58702c42dab08fd990fd8551ada9cf Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 8 Jan 2024 09:13:01 +0100 Subject: [PATCH 069/100] remove(traduction): refs #6366 remove unused traduction --- loopback/locale/es.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 89d12d8db..e2b90983b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -296,7 +296,6 @@ "Invalid NIF for VIES": "Invalid NIF for VIES", "Ticket does not exist": "Este ticket no existe", "Ticket is already signed": "Este ticket ya ha sido firmado", - "The DELIVERED state does not exist": "El estado DELIVERED no existe", "Authentication failed": "Autenticación fallida", "You can't use the same password": "No puedes usar la misma contraseña", "You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono", -- 2.40.1 From d5ca47ea2a28a41409994f8ef973e0ad93f07b1c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jan 2024 09:51:12 +0100 Subject: [PATCH 070/100] refactor: refs #6410 Deleted dmsType.path --- back/models/dms-type.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/back/models/dms-type.json b/back/models/dms-type.json index 8d7195132..d3e96a986 100644 --- a/back/models/dms-type.json +++ b/back/models/dms-type.json @@ -17,10 +17,6 @@ "type": "string", "required": true }, - "path": { - "type": "string", - "required": true - }, "code": { "type": "string", "required": true -- 2.40.1 From ea5483e8476300e65fb3dc059a42bb4250826248 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jan 2024 10:50:37 +0100 Subject: [PATCH 071/100] refs #6222 refactor: sale_calculateComponent --- db/changes/240201/00-saleComponent.sql | 589 ++++++++++++++++++ .../back/methods/ticket/componentUpdate.js | 4 +- .../ticket/specs/componentUpdate.spec.js | 10 +- .../front/basic-data/step-two/index.html | 2 +- .../ticket/front/basic-data/step-two/index.js | 9 +- .../methods/worker-time-control/getClockIn.js | 2 +- 6 files changed, 600 insertions(+), 16 deletions(-) create mode 100644 db/changes/240201/00-saleComponent.sql diff --git a/db/changes/240201/00-saleComponent.sql b/db/changes/240201/00-saleComponent.sql new file mode 100644 index 000000000..44f9d172c --- /dev/null +++ b/db/changes/240201/00-saleComponent.sql @@ -0,0 +1,589 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN +/** + * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id de la venta + * @param vOption indica en que componente pone el descuadre, NULL en casos habituales + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) +BEGIN +/** + * Comprueba que las ventas creadas entre un rango de fechas tienen componentes + * + * @param vCreatedFrom inicio del rango + * @param vCreatedTo fin del rango + */ + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vSaleFk INTEGER; + DECLARE vTicketFk INTEGER; + DECLARE vConcept VARCHAR(50); + DECLARE vCur CURSOR FOR + SELECT s.id + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo + AND c.id IS NULL + AND t.agencyModeFk IS NOT NULL + AND t.isDeleted IS FALSE + AND t.warehouseFk = 60 + AND ic.merchandise != FALSE + GROUP BY s.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + CREATE TEMPORARY TABLE tmp.coste + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT s.id + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 + WHERE s.created >= vCreatedFrom + AND ic.merchandise != FALSE; + + OPEN vCur; + + l: LOOP + SET v_done = FALSE; + FETCH vCur INTO vSaleFk; + + IF v_done THEN + LEAVE l; + END IF; + + SELECT ticketFk, concept + INTO vTicketFk, vConcept + FROM sale + WHERE id = vSaleFk; + + CALL sale_calculateComponent(vSaleFk, 'renewPrices'); + END LOOP; + + CLOSE vCur; + DROP TEMPORARY TABLE tmp.coste; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) +proc: BEGIN +/** + * Este procedimiento recalcula los componentes de un conjunto de sales, + * eliminando los componentes existentes e insertandolos de nuevo + * + * @param vOption si no se quiere forzar llamar con NULL + * @table tmp.recalculateSales (id) + */ + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vTicketFk INT; + DECLARE vLanded DATE; + DECLARE vIsEditable BOOLEAN; + DECLARE vZoneFk INTEGER; + DECLARE vDone BOOL DEFAULT FALSE; + + DECLARE vCur CURSOR FOR + SELECT DISTINCT s.ticketFk + FROM tmp.recalculateSales rs + JOIN vn.sale s ON s.id = rs.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, + t.landed + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, + vLanded + FROM ticket t + LEFT JOIN ticketState ts ON t.id = ts.ticket + LEFT JOIN alertLevel al ON al.id = ts.alertLevel + WHERE t.id = vTicketFk; + + CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); + + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN + CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); + END IF; + + IF vLanded IS NULL OR vZoneFk IS NULL THEN + + UPDATE ticket t + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + WHERE t.id = vTicketFk AND t.landed IS NULL; + + IF vZoneFk IS NULL THEN + SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; + UPDATE ticket t + SET t.zoneFk = vZoneFk + WHERE t.id = vTicketFk AND t.zoneFk IS NULL; + END IF; + + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetLanded; + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) ENGINE = MEMORY + SELECT s.id saleFk, vWarehouseFk warehouseFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + WHERE s.ticketFk = vTicketFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY s.itemFk; + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + IF vOption IS NULL THEN + SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); + END IF; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE tmp.sale; + + END LOOP; + CLOSE vCur; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) +BEGIN +/* + * Recalcula los componentes un ticket clonado, + * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta + * @param vTicketNew nuevo ticket clonado + * @param vTicketOld icket original, a partir del qual se clonara el nuevo +*/ + + REPLACE INTO orderTicket(orderFk,ticketFk) + SELECT orderFk, vTicketNew + FROM orderTicket + WHERE ticketFk = vTicketOld; + + -- Bionizamos lineas con Preu = 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price = 0; + + CALL sale_recalcComponent('renewPrices'); + + -- Bionizamos lineas con Preu > 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price > 0; + + CALL sale_recalcComponent('imbalance'); + + DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + END IF; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + COMMIT; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) +BEGIN +/** + * A partir de la tabla tmp.sale, crea los Movimientos_componentes + * y modifica el campo Preu de la tabla Movimientos + * + * @param i_option integer tipo de actualizacion + * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk + **/ + DECLARE vComponentFk INT; + + IF vCode <> 'renewPrices' THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; + END IF; + + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN `component` c ON c.id = sc.componentFk + WHERE c.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); + + -- Añadir componente venta por paquete + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT t.id, t.componentFk, t.cost + FROM ( + SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN vn.buy b ON b.id = buy_id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + LEFT JOIN ( + SELECT s.id + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk + JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' + ) tp ON tp.id = s.id + WHERE tp.id IS NULL + HAVING resto <> 0) t; + + IF vCode <> 'renewPrices' THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue / ((100 - s.discount) / 100) + WHERE it.code != 'PRT' ; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN `component` c ON c.id = sc.componentFk + JOIN componentType ct on ct.id = c.typeFk AND ct.isBase + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, s.price + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) +BEGIN + +/** + * Comprueba que los tickets entre un rango de fechas tienen componentes + * y recalcula sus componentes + * + * @param vShippedFrom rango inicial de fecha + * @param vShippedTo rango final de fecha + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.coste + (primary key (id)) ENGINE = MEMORY + SELECT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo + AND ic.merchandise; + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (primary key (id)) ENGINE = MEMORY + SELECT DISTINCT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo + AND c.id IS NULL + AND ic.merchandise; + + CALL sale_recalcComponent('renewPrices'); + + DROP TEMPORARY TABLE tmp.recalculateSales; + DROP TEMPORARY TABLE tmp.coste; + END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( + vTicketFk INT, + vClientFk INT, + vNickname VARCHAR(50), + vAgencyModeFk INT, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk INT, + vCompanyFk INT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + /** + * Modifica en el ticket los campos que se le pasan por parámetro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ + + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.nickname = vNickname, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + + DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN + +/** + * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id del ticket + * @param vOption si no se quiere forzar llamar con NULL + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.ticketFk = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +TRUNCATE TABLE `vn`.`ticketUpdateAction`; +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrice'); +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 3acd68cfb..0786b72c8 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -74,8 +74,8 @@ module.exports = Self => { }, { arg: 'option', - type: 'number', - description: 'Action id' + type: 'string', + description: 'Action code' }, { arg: 'isWithoutNegatives', diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 40be4161c..c9a13b4cc 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -60,7 +60,7 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false }; @@ -110,7 +110,7 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false }; @@ -176,7 +176,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: true }; @@ -235,7 +235,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false, keepPrice: true }; @@ -288,7 +288,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false, keepPrice: false }; diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index fc57a354a..528971154 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -76,7 +76,7 @@ + val={{::action.code}}> diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index 8c8a3a079..9717d1ea4 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -25,12 +25,7 @@ class Controller extends Component { loadDefaultTicketAction() { const isSalesAssistant = this.aclService.hasAny(['salesAssistant']); - const defaultOption = isSalesAssistant ? 'turnInMana' : 'changePrice'; - const filter = {where: {code: defaultOption}}; - - this.$http.get(`TicketUpdateActions`, {filter}).then(response => { - return this.ticket.option = response.data[0].id; - }); + this.ticket.option = isSalesAssistant ? 'mana' : 'buyerDiscount'; } onStepChange() { @@ -112,7 +107,7 @@ class Controller extends Component { shipped: this.ticket.shipped, landed: this.ticket.landed, isDeleted: this.ticket.isDeleted, - option: parseInt(this.ticket.option), + option: this.ticket.option, isWithoutNegatives: this.ticket.withoutNegatives, withWarningAccept: this.ticket.withWarningAccept, keepPrice: false diff --git a/modules/worker/back/methods/worker-time-control/getClockIn.js b/modules/worker/back/methods/worker-time-control/getClockIn.js index 470700643..458cadafb 100644 --- a/modules/worker/back/methods/worker-time-control/getClockIn.js +++ b/modules/worker/back/methods/worker-time-control/getClockIn.js @@ -5,7 +5,7 @@ module.exports = Self => { accepts: [ { arg: 'workerFk', - type: 'int', + type: 'number', required: true, }, -- 2.40.1 From 676d95563b3052c5eb1e6eb94db5614d03fa445b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 9 Jan 2024 12:53:58 +0100 Subject: [PATCH 072/100] refs #6322 importe --- .../240401/00-ticket_canbePostponed.sql | 74 +++++++++++++++++++ .../back/methods/ticket/getTicketsFuture.js | 10 ++- modules/ticket/front/future/index.html | 11 +++ modules/ticket/front/future/index.js | 16 ++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 db/changes/240401/00-ticket_canbePostponed.sql diff --git a/db/changes/240401/00-ticket_canbePostponed.sql b/db/changes/240401/00-ticket_canbePostponed.sql new file mode 100644 index 000000000..e0fbb99cf --- /dev/null +++ b/db/changes/240401/00-ticket_canbePostponed.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +$$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vWarehouseFk INT) +BEGIN +/** + * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro + * + * @param vOriginDated Fecha en cuestión + * @param vFutureDated Fecha en el futuro a sondear + * @param vWarehouseFk Identificador de vn.warehouse + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.filter + (INDEX (id)) + SELECT sv.ticketFk id, + sub2.id futureId, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, + CAST(sum(litros) AS DECIMAL(10,0)) liters, + CAST(count(*) AS DECIMAL(10,0)) `lines`, + st.name state, + sub2.iptd futureIpt, + sub2.state futureState, + t.clientFk, + t.warehouseFk, + ts.alertLevel, + t.shipped, + t.totalWithVat, + sub2.shipped futureShipped, + t.workerFk, + st.code stateCode, + sub2.code futureStateCode, + st.classColor, + sub2.classColor futureClassColor + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = sv.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country c ON c.id = p.countryFk + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.alertLevel al ON al.id = ts.alertLevel + LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN ( + SELECT * + FROM ( + SELECT + t.addressFk, + t.id, + t.shipped, + st.name state, + st.code, + st.classColor, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd + FROM vn.ticket t + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + WHERE t.shipped BETWEEN vFutureDated + AND util.dayend(vFutureDated) + AND t.warehouseFk = vWarehouseFk + GROUP BY t.id + ) sub + GROUP BY sub.addressFk + ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id + WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) + AND t.warehouseFk = vWarehouseFk + AND al.code = 'FREE' + AND tp.ticketFk IS NULL + GROUP BY sv.ticketFk + HAVING futureId; +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index fa24cc379..ba64999a7 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -74,6 +74,12 @@ module.exports = Self => { description: 'Destination state', required: false }, + { + arg: 'totalWithVat', + type: 'string', + description: 'Total price with vat', + required: false + }, { arg: 'problems', type: 'boolean', @@ -84,7 +90,7 @@ module.exports = Self => { arg: 'filter', type: 'object', description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string` - } + }, ], returns: { type: ['object'], @@ -132,6 +138,8 @@ module.exports = Self => { return {'f.stateCode': {like: `%${value}%`}}; case 'futureState': return {'f.futureStateCode': {like: `%${value}%`}}; + case 'totalWithVat': + return {'t.totalWithVat': value}; } }); diff --git a/modules/ticket/front/future/index.html b/modules/ticket/front/future/index.html index 5119d103b..d6d0d96a2 100644 --- a/modules/ticket/front/future/index.html +++ b/modules/ticket/front/future/index.html @@ -61,6 +61,9 @@ Liters + + Import + Available Lines @@ -76,6 +79,7 @@ State + @@ -148,6 +152,13 @@ {{::ticket.liters}} + + + {{::(ticket.totalWithVat ? ticket.totalWithVat : 0) | currency: 'EUR': 2}} + + {{::ticket.lines}} 0 && parseInt(totalWithVat) < 50); + } exprBuilder(param, value) { switch (param) { @@ -145,6 +159,8 @@ export default class Controller extends Section { return {'ipt': {like: `%${value}%`}}; case 'futureIpt': return {'futureIpt': {like: `%${value}%`}}; + case 'totalWithVat': + return {'totalWithVat': value}; } } } -- 2.40.1 From bf44f82f4f3ab943f72b76ce133d1a1c8e18ccc1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 9 Jan 2024 13:16:14 +0100 Subject: [PATCH 073/100] refs #6322 fix code --- modules/ticket/back/methods/ticket/getTicketsFuture.js | 8 -------- modules/ticket/front/future/index.html | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index ba64999a7..ab5071be4 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -74,12 +74,6 @@ module.exports = Self => { description: 'Destination state', required: false }, - { - arg: 'totalWithVat', - type: 'string', - description: 'Total price with vat', - required: false - }, { arg: 'problems', type: 'boolean', @@ -138,8 +132,6 @@ module.exports = Self => { return {'f.stateCode': {like: `%${value}%`}}; case 'futureState': return {'f.futureStateCode': {like: `%${value}%`}}; - case 'totalWithVat': - return {'t.totalWithVat': value}; } }); diff --git a/modules/ticket/front/future/index.html b/modules/ticket/front/future/index.html index d6d0d96a2..cceca266f 100644 --- a/modules/ticket/front/future/index.html +++ b/modules/ticket/front/future/index.html @@ -61,7 +61,7 @@ Liters - + Import -- 2.40.1 From 1bd6751d560cae74583158772ea27811b67b5543 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 10 Jan 2024 07:46:11 +0100 Subject: [PATCH 074/100] refs #5499 revert --- back/tests.js | 2 +- db/dump/fixtures.sql | 3 --- modules/claim/front/note/create/index.html | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/back/tests.js b/back/tests.js index c313df172..2678f6744 100644 --- a/back/tests.js +++ b/back/tests.js @@ -60,8 +60,8 @@ async function test() { jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); jasmine.exitOnCompletion = true; + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000; } - jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000; const backSpecs = [ './back/**/*[sS]pec.js', diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0bd47fe78..8997e40b1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3009,6 +3009,3 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) (1, 'Error in VAT calculation'), (2, 'Error in sales details'), (3, 'Error in customer data'); --- Auto-generated SQL script #202312201041 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Claim','claimObservation','WRITE','ALLOW','ROLE','employee'); diff --git a/modules/claim/front/note/create/index.html b/modules/claim/front/note/create/index.html index c1666553b..8a882a4f5 100644 --- a/modules/claim/front/note/create/index.html +++ b/modules/claim/front/note/create/index.html @@ -1,6 +1,6 @@ Date: Wed, 10 Jan 2024 07:50:29 +0100 Subject: [PATCH 075/100] refs #5499 code: remove unused translations --- loopback/locale/en.json | 2 -- loopback/locale/es.json | 2 -- 2 files changed, 4 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index f6d3ae504..611c409ca 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -70,8 +70,6 @@ "Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", "Claim state has changed to": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*", - "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", - "Claim state has changed to canceled": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *canceled*", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 0f68117b5..5555ef8b0 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -137,8 +137,6 @@ "Change quantity": "{{concept}} cambia de {{oldQuantity}} a {{newQuantity}}", "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", "Claim state has changed to": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *{{newState}}*", - "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", - "Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", -- 2.40.1 From 877dc718a7f9b856a5e460dc0e215c2eb4b2ae5e Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 10 Jan 2024 08:57:19 +0100 Subject: [PATCH 076/100] refs #6353 remove rating --- modules/order/front/catalog-view/index.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index 5d60211ed..081ce05a0 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -37,11 +37,6 @@ value="{{::item.value7}}"> - - - - @@ -54,7 +49,6 @@ {{::item.minQuantity}} -