From c5fb565484532e955e30cd7b1f3e54dc3fceaf85 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 15 Nov 2022 10:25:33 +0100 Subject: [PATCH 01/10] refs #4503 message added --- back/methods/chat/sendCheckingPresence.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 3bc022429..075591969 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -43,6 +43,9 @@ module.exports = Self => { if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); + if (process.env.NODE_ENV == 'test') + message = `[Test:Environment to user ${userId}] ` + message; + await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, From c54844f7ffe38685a5dce8438b79e002fceaad23 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 1 Dec 2022 14:32:05 +0100 Subject: [PATCH 02/10] removed pending from working test --- .../invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js index 536fa07a0..08f049783 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js @@ -30,7 +30,6 @@ describe('InvoiceOut downloadZip()', () => { }); it('should return an error if the size of the files is too large', async() => { - pending('https://redmine.verdnatura.es/issues/4875'); const tx = await models.InvoiceOut.beginTransaction({}); let error; From 95967a29dbb13869aabc76cdb5fa265830dcb150 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 13 Dec 2022 11:50:17 +0100 Subject: [PATCH 03/10] refs #4928 email template added and proc modified --- db/changes/224702/00-notificationProc.sql | 7 +-- db/changes/225001/.gitkeep | 1 - .../225001/00-supplier_beforeUpdate.sql | 48 +++++++++++++++++++ .../assets/css/import.js | 11 +++++ .../supplier-pay-method-update/locale/en.yml | 3 ++ .../supplier-pay-method-update/locale/es.yml | 3 ++ .../supplier-pay-method-update.html | 8 ++++ .../supplier-pay-method-update.js | 23 +++++++++ 8 files changed, 97 insertions(+), 7 deletions(-) delete mode 100644 db/changes/225001/.gitkeep create mode 100644 db/changes/225001/00-supplier_beforeUpdate.sql create mode 100644 print/templates/email/supplier-pay-method-update/assets/css/import.js create mode 100644 print/templates/email/supplier-pay-method-update/locale/en.yml create mode 100644 print/templates/email/supplier-pay-method-update/locale/es.yml create mode 100644 print/templates/email/supplier-pay-method-update/supplier-pay-method-update.html create mode 100755 print/templates/email/supplier-pay-method-update/supplier-pay-method-update.js diff --git a/db/changes/224702/00-notificationProc.sql b/db/changes/224702/00-notificationProc.sql index 475b2e389..2cf11b4f1 100644 --- a/db/changes/224702/00-notificationProc.sql +++ b/db/changes/224702/00-notificationProc.sql @@ -12,14 +12,9 @@ BEGIN * @param vAuthorFk The notification author or %NULL if there is no author * @return The notification id */ - DECLARE vNotificationFk INT; - - SELECT id INTO vNotificationFk - FROM `notification` - WHERE `name` = vNotificationName; INSERT INTO notificationQueue - SET notificationFk = vNotificationFk, + SET notificationFk = vNotificationName, params = vParams, authorFk = vAuthorFk; diff --git a/db/changes/225001/.gitkeep b/db/changes/225001/.gitkeep deleted file mode 100644 index 7a4187c02..000000000 --- a/db/changes/225001/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Delete this file diff --git a/db/changes/225001/00-supplier_beforeUpdate.sql b/db/changes/225001/00-supplier_beforeUpdate.sql new file mode 100644 index 000000000..857d3206f --- /dev/null +++ b/db/changes/225001/00-supplier_beforeUpdate.sql @@ -0,0 +1,48 @@ +DROP TRIGGER IF EXISTS vn.supplier_beforeUpdate; +USE vn; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate` + BEFORE UPDATE ON `supplier` + FOR EACH ROW +BEGIN + DECLARE vHasChange BOOL DEFAULT FALSE; + DECLARE vPayMethodHasVerified BOOL; + DECLARE vParams JSON; + DECLARE vOldPayMethodName VARCHAR(20); + DECLARE vNewPayMethodName VARCHAR(20); + + SELECT hasVerified INTO vPayMethodHasVerified + FROM payMethod + WHERE id = NEW.payMethodFk; + + SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk); + + IF !vHasChange THEN + SELECT name INTO vOldPayMethodName + FROM payMethod + WHERE id = OLD.payMethodFk; + SELECT name INTO vNewPayMethodName + FROM payMethod + WHERE id = NEW.payMethodFk; + SET vParams = JSON_OBJECT( + 'name', NEW.name, + 'oldPayMethod', vOldPayMethodName, + 'newPayMethod', vNewPayMethodName + ); + SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id; + END IF; + + SET vHasChange = (NEW.payDemFk <=> OLD.payDemFk) OR (NEW.payDay <=> OLD.payDay); + + IF vPayMethodHasVerified AND !vHasChange THEN + SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk); + END IF; + + IF vHasChange THEN + SET NEW.isPayMethodChecked = FALSE; + END IF; + +END$$ +DELIMITER ; diff --git a/print/templates/email/supplier-pay-method-update/assets/css/import.js b/print/templates/email/supplier-pay-method-update/assets/css/import.js new file mode 100644 index 000000000..4b4bb7086 --- /dev/null +++ b/print/templates/email/supplier-pay-method-update/assets/css/import.js @@ -0,0 +1,11 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`]) + .mergeStyles(); diff --git a/print/templates/email/supplier-pay-method-update/locale/en.yml b/print/templates/email/supplier-pay-method-update/locale/en.yml new file mode 100644 index 000000000..f04ccc5ce --- /dev/null +++ b/print/templates/email/supplier-pay-method-update/locale/en.yml @@ -0,0 +1,3 @@ +subject: Pay method updated +title: Pay method updated +description: The pay method of the supplier {0} has been updated from {1} to {2} diff --git a/print/templates/email/supplier-pay-method-update/locale/es.yml b/print/templates/email/supplier-pay-method-update/locale/es.yml new file mode 100644 index 000000000..59ee0e02f --- /dev/null +++ b/print/templates/email/supplier-pay-method-update/locale/es.yml @@ -0,0 +1,3 @@ +subject: Método de pago actualizado +title: Método de pago actualizado +description: Se ha actualizado el método de pago del proveedor {0} de {1} a {2} diff --git a/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.html b/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.html new file mode 100644 index 000000000..df8543cd9 --- /dev/null +++ b/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.html @@ -0,0 +1,8 @@ + +
+
+

{{ $t('title') }}

+

+
+
+
diff --git a/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.js b/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.js new file mode 100755 index 000000000..283b2689c --- /dev/null +++ b/print/templates/email/supplier-pay-method-update/supplier-pay-method-update.js @@ -0,0 +1,23 @@ +const Component = require(`vn-print/core/component`); +const emailBody = new Component('email-body'); + +module.exports = { + name: 'supplier-pay-method-update', + components: { + 'email-body': emailBody.build(), + }, + props: { + name: { + type: String, + required: true + }, + oldPayMethod: { + type: String, + required: true + }, + newPayMethod: { + type: String, + required: true + } + } +}; From f00fdcff7cb20524141e9a704473c62ac2ea5abb Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 14 Dec 2022 08:06:02 +0100 Subject: [PATCH 04/10] refactor sql --- .../225001/00-supplier_beforeUpdate.sql | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/db/changes/225001/00-supplier_beforeUpdate.sql b/db/changes/225001/00-supplier_beforeUpdate.sql index 857d3206f..08af8666b 100644 --- a/db/changes/225001/00-supplier_beforeUpdate.sql +++ b/db/changes/225001/00-supplier_beforeUpdate.sql @@ -1,5 +1,5 @@ -DROP TRIGGER IF EXISTS vn.supplier_beforeUpdate; -USE vn; +DROP TRIGGER IF EXISTS `vn`.`supplier_beforeUpdate`; +USE `vn`; DELIMITER $$ $$ @@ -7,7 +7,8 @@ CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate` BEFORE UPDATE ON `supplier` FOR EACH ROW BEGIN - DECLARE vHasChange BOOL DEFAULT FALSE; + DECLARE vHasChange BOOL; + DECLARE vPayMethodChanged BOOL; DECLARE vPayMethodHasVerified BOOL; DECLARE vParams JSON; DECLARE vOldPayMethodName VARCHAR(20); @@ -17,15 +18,16 @@ BEGIN FROM payMethod WHERE id = NEW.payMethodFk; - SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk); + SET vPayMethodChanged = NOT(NEW.payMethodFk <=> OLD.payMethodFk); - IF !vHasChange THEN + IF vPayMethodChanged THEN SELECT name INTO vOldPayMethodName FROM payMethod WHERE id = OLD.payMethodFk; SELECT name INTO vNewPayMethodName FROM payMethod WHERE id = NEW.payMethodFk; + SET vParams = JSON_OBJECT( 'name', NEW.name, 'oldPayMethod', vOldPayMethodName, @@ -34,13 +36,9 @@ BEGIN SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id; END IF; - SET vHasChange = (NEW.payDemFk <=> OLD.payDemFk) OR (NEW.payDay <=> OLD.payDay); + SET vHasChange = NOT(NEW.payDemFk <=> OLD.payDemFk AND NEW.payDay <=> OLD.payDay) OR vPayMethodChanged; - IF vPayMethodHasVerified AND !vHasChange THEN - SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk); - END IF; - - IF vHasChange THEN + IF vHasChange AND vPayMethodHasVerified THEN SET NEW.isPayMethodChecked = FALSE; END IF; From 33196acac6b4ed31400ce63c38f4a30314744a8d Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 15 Dec 2022 08:31:47 +0100 Subject: [PATCH 05/10] refs #4928 fixture notification, fix test supplier --- .../225001/00-supplier_beforeUpdate.sql | 3 + .../back/models/specs/supplier.spec.js | 127 +++++++++++------- 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/db/changes/225001/00-supplier_beforeUpdate.sql b/db/changes/225001/00-supplier_beforeUpdate.sql index 08af8666b..e87415659 100644 --- a/db/changes/225001/00-supplier_beforeUpdate.sql +++ b/db/changes/225001/00-supplier_beforeUpdate.sql @@ -44,3 +44,6 @@ BEGIN END$$ DELIMITER ; + +INSERT INTO `util`.`notification` (`id`, `name`,`description`) + VALUES (3, 'supplier-pay-method-update', 'A supplier pay method has been updated'); diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 3140981c3..effb70e35 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -2,13 +2,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('loopback model Supplier', () => { - let supplierOne; - let supplierTwo; - beforeAll(async() => { - supplierOne = await models.Supplier.findById(1); - supplierTwo = await models.Supplier.findById(442); - const activeCtx = { accessToken: {userId: 9}, http: { @@ -23,71 +17,112 @@ describe('loopback model Supplier', () => { }); }); - afterAll(async() => { - await supplierOne.updateAttribute('payMethodFk', supplierOne.payMethodFk); - await supplierTwo.updateAttribute('payMethodFk', supplierTwo.payMethodFk); - }); - describe('payMethodFk', () => { it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => { - let error; - const expectedError = 'You can not select this payment method without a registered bankery account'; - const supplier = await models.Supplier.findById(1); + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; - await supplier.updateAttribute('payMethodFk', 8) - .catch(e => { - error = e; + try { + let error; + const expectedError = 'You can not select this payment method without a registered bankery account'; + const supplier = await models.Supplier.findOne({where: {id: 1}}, options); - expect(error.message).toContain(expectedError); - }); + await supplier.updateAttribute('payMethodFk', 8, options) + .catch(e => { + error = e; - expect(error).toBeDefined(); + expect(error.message).toContain(expectedError); + }); + + expect(error).toBeDefined(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); it('should not throw if the payMethod id is valid', async() => { - let error; - const supplier = await models.Supplier.findById(442); - await supplier.updateAttribute('payMethodFk', 4) - .catch(e => { - error = e; - }); + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; - expect(error).not.toBeDefined(); + try { + let error; + const supplier = await models.Supplier.findOne({where: {id: 442}}, options); + await supplier.updateAttribute('payMethodFk', 4, options) + .catch(e => { + error = e; + }); + + expect(error).not.toBeDefined(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); it('should have checked isPayMethodChecked for payMethod hasVerfified is false', async() => { - const supplier = await models.Supplier.findById(442); - await supplier.updateAttribute('isPayMethodChecked', true); - await supplier.updateAttribute('payMethodFk', 5); + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; - const result = await models.Supplier.findById(442); + try { + const supplier = await models.Supplier.findOne({where: {id: 442}}, options); + await supplier.updateAttribute('isPayMethodChecked', true, options); + await supplier.updateAttribute('payMethodFk', 5, options); - expect(result.isPayMethodChecked).toEqual(true); + const result = await models.Supplier.findOne({where: {id: 442}}, options); + + expect(result.isPayMethodChecked).toEqual(true); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); it('should have unchecked isPayMethodChecked for payMethod hasVerfified is true', async() => { - const supplier = await models.Supplier.findById(442); - await supplier.updateAttribute('isPayMethodChecked', true); - await supplier.updateAttribute('payMethodFk', 2); + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; - const result = await models.Supplier.findById(442); + try { + const supplier = await models.Supplier.findOne({where: {id: 442}}, options); + await supplier.updateAttribute('isPayMethodChecked', true, options); + await supplier.updateAttribute('payMethodFk', 2, options); - expect(result.isPayMethodChecked).toEqual(false); + const result = await models.Supplier.findOne({where: {id: 442}}, options); + + expect(result.isPayMethodChecked).toEqual(false); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); it('should have unchecked isPayMethodChecked for payDay and peyDemFk', async() => { - const supplier = await models.Supplier.findById(442); + const tx = await models.Supplier.beginTransaction({}); + const options = {transaction: tx}; - await supplier.updateAttribute('isPayMethodChecked', true); - await supplier.updateAttribute('payDay', 5); - const firstResult = await models.Supplier.findById(442); + try { + const supplier = await models.Supplier.findOne({where: {id: 442}}, options); + await supplier.updateAttribute('payMethodFk', 2, options); - await supplier.updateAttribute('isPayMethodChecked', true); - await supplier.updateAttribute('payDemFk', 1); - const secondResult = await models.Supplier.findById(442); + await supplier.updateAttribute('isPayMethodChecked', true, options); + await supplier.updateAttribute('payDay', 5, options); + const firstResult = await models.Supplier.findOne({where: {id: 442}}, options); - expect(firstResult.isPayMethodChecked).toEqual(false); - expect(secondResult.isPayMethodChecked).toEqual(false); + await supplier.updateAttribute('isPayMethodChecked', true, options); + await supplier.updateAttribute('payDemFk', 1, options); + const secondResult = await models.Supplier.findOne({where: {id: 442}}, options); + + expect(firstResult.isPayMethodChecked).toEqual(false); + expect(secondResult.isPayMethodChecked).toEqual(false); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); }); }); From 522000cd04f06d05f19d3cc640df16960aaa77bb Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 15 Dec 2022 09:52:34 +0100 Subject: [PATCH 06/10] refs #4928 fix fixtures --- .../225001/00-supplier_beforeUpdate.sql | 3 -- db/dump/fixtures.sql | 4 ++- .../back/models/specs/supplier.spec.js | 33 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/db/changes/225001/00-supplier_beforeUpdate.sql b/db/changes/225001/00-supplier_beforeUpdate.sql index e87415659..08af8666b 100644 --- a/db/changes/225001/00-supplier_beforeUpdate.sql +++ b/db/changes/225001/00-supplier_beforeUpdate.sql @@ -44,6 +44,3 @@ BEGIN END$$ DELIMITER ; - -INSERT INTO `util`.`notification` (`id`, `name`,`description`) - VALUES (3, 'supplier-pay-method-update', 'A supplier pay method has been updated'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5b37338e4..68e2f7a8b 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2689,7 +2689,8 @@ INSERT INTO `util`.`notificationConfig` INSERT INTO `util`.`notification` (`id`, `name`, `description`) VALUES - (1, 'print-email', 'notification fixture one'); + (1, 'print-email', 'notification fixture one'), + (3, 'supplier-pay-method-update', 'A supplier pay method has been updated'); INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) VALUES @@ -2746,3 +2747,4 @@ INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) VALUES (1, 1); + diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index effb70e35..1e8efb4b1 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -2,7 +2,12 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('loopback model Supplier', () => { + let supplierOne; + let supplierTwo; + beforeAll(async() => { + supplierOne = await models.Supplier.findById(1); + supplierTwo = await models.Supplier.findById(442); const activeCtx = { accessToken: {userId: 9}, http: { @@ -25,9 +30,8 @@ describe('loopback model Supplier', () => { try { let error; const expectedError = 'You can not select this payment method without a registered bankery account'; - const supplier = await models.Supplier.findOne({where: {id: 1}}, options); - await supplier.updateAttribute('payMethodFk', 8, options) + await supplierOne.updateAttribute('payMethodFk', 8, options) .catch(e => { error = e; @@ -48,8 +52,7 @@ describe('loopback model Supplier', () => { try { let error; - const supplier = await models.Supplier.findOne({where: {id: 442}}, options); - await supplier.updateAttribute('payMethodFk', 4, options) + await supplierTwo.updateAttribute('payMethodFk', 4, options) .catch(e => { error = e; }); @@ -67,9 +70,8 @@ describe('loopback model Supplier', () => { const options = {transaction: tx}; try { - const supplier = await models.Supplier.findOne({where: {id: 442}}, options); - await supplier.updateAttribute('isPayMethodChecked', true, options); - await supplier.updateAttribute('payMethodFk', 5, options); + await supplierTwo.updateAttribute('isPayMethodChecked', true, options); + await supplierTwo.updateAttribute('payMethodFk', 5, options); const result = await models.Supplier.findOne({where: {id: 442}}, options); @@ -86,9 +88,8 @@ describe('loopback model Supplier', () => { const options = {transaction: tx}; try { - const supplier = await models.Supplier.findOne({where: {id: 442}}, options); - await supplier.updateAttribute('isPayMethodChecked', true, options); - await supplier.updateAttribute('payMethodFk', 2, options); + await supplierTwo.updateAttribute('isPayMethodChecked', true, options); + await supplierTwo.updateAttribute('payMethodFk', 2, options); const result = await models.Supplier.findOne({where: {id: 442}}, options); @@ -105,15 +106,13 @@ describe('loopback model Supplier', () => { const options = {transaction: tx}; try { - const supplier = await models.Supplier.findOne({where: {id: 442}}, options); - await supplier.updateAttribute('payMethodFk', 2, options); - - await supplier.updateAttribute('isPayMethodChecked', true, options); - await supplier.updateAttribute('payDay', 5, options); + await supplierTwo.updateAttribute('payMethodFk', 2, options); + await supplierTwo.updateAttribute('isPayMethodChecked', true, options); + await supplierTwo.updateAttribute('payDay', 5, options); const firstResult = await models.Supplier.findOne({where: {id: 442}}, options); - await supplier.updateAttribute('isPayMethodChecked', true, options); - await supplier.updateAttribute('payDemFk', 1, options); + await supplierTwo.updateAttribute('isPayMethodChecked', true, options); + await supplierTwo.updateAttribute('payDemFk', 1, options); const secondResult = await models.Supplier.findOne({where: {id: 442}}, options); expect(firstResult.isPayMethodChecked).toEqual(false); From 5cc8764a3f5f710e7c039ef42baa7b79d4811108 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 15 Dec 2022 13:54:17 +0100 Subject: [PATCH 07/10] acquireTimeout 10000 --- loopback/server/datasources.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 00f6bf624..1e8e4820b 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -15,7 +15,7 @@ "legacyUtcDateProcessing": false, "timezone": "local", "connectTimeout": 40000, - "acquireTimeout": 20000, + "acquireTimeout": 10000, "waitForConnections": true }, "osticket": { From bab6fa0c9d2644b9fedd20331e590d44758e8fab Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 15 Dec 2022 14:02:18 +0100 Subject: [PATCH 08/10] acquireTimeout: 60000 --- loopback/server/datasources.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 1e8e4820b..f5f277ffc 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -15,7 +15,7 @@ "legacyUtcDateProcessing": false, "timezone": "local", "connectTimeout": 40000, - "acquireTimeout": 10000, + "acquireTimeout": 60000, "waitForConnections": true }, "osticket": { From 2a8a928ac5cc8b74d5a775a3097858704f36d8d7 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 16 Dec 2022 10:36:18 +0100 Subject: [PATCH 09/10] feat: create invoiceIn --- db/changes/225001/00-invoiceInConfig.sql | 12 ++++ modules/invoiceIn/back/model-config.json | 5 +- .../back/models/invoice-in-config.json | 35 ++++++++++ modules/invoiceIn/front/descriptor/index.html | 11 +++- modules/invoiceIn/front/descriptor/index.js | 4 ++ .../invoiceOut/specs/downloadZip.spec.js | 1 + modules/ticket/front/descriptor-menu/index.js | 2 +- .../reports/entry-order/entry-order.html | 2 +- .../reports/entry-order/sql/entry.sql | 4 +- .../extra-community/extra-community.html | 2 +- .../reports/extra-community/sql/entries.sql | 4 +- .../reports/invoiceIn/invoiceIn.html | 65 ++++++++----------- .../templates/reports/invoiceIn/invoiceIn.js | 13 ++++ .../templates/reports/invoiceIn/locale/en.yml | 11 +++- .../templates/reports/invoiceIn/locale/es.yml | 11 +++- .../reports/invoiceIn/sql/defaultTax.sql | 5 ++ .../templates/reports/invoiceIn/sql/entry.sql | 2 +- .../reports/invoiceIn/sql/invoice.sql | 2 +- .../templates/reports/invoiceIn/sql/taxes.sql | 3 +- .../supplier-campaign-metrics/sql/entries.sql | 2 +- .../supplier-campaign-metrics.html | 2 +- 21 files changed, 140 insertions(+), 58 deletions(-) create mode 100644 db/changes/225001/00-invoiceInConfig.sql create mode 100644 modules/invoiceIn/back/models/invoice-in-config.json create mode 100644 print/templates/reports/invoiceIn/sql/defaultTax.sql diff --git a/db/changes/225001/00-invoiceInConfig.sql b/db/changes/225001/00-invoiceInConfig.sql new file mode 100644 index 000000000..a27b59440 --- /dev/null +++ b/db/changes/225001/00-invoiceInConfig.sql @@ -0,0 +1,12 @@ +CREATE TABLE `vn`.`invoiceInConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `retentionRate` int(3) NOT NULL, + `retentionName` varchar(25) NOT NULL, + `sageWithholdingFk` smallint(6) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `invoiceInConfig_sageWithholdingFk` FOREIGN KEY (`sageWithholdingFk`) REFERENCES `sage`.`TiposRetencion`(`CodigoRetencion`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`) + VALUES + (1, -2, 'Retención 2%', 2); diff --git a/modules/invoiceIn/back/model-config.json b/modules/invoiceIn/back/model-config.json index 6765ae81c..bd37b3bf1 100644 --- a/modules/invoiceIn/back/model-config.json +++ b/modules/invoiceIn/back/model-config.json @@ -2,7 +2,7 @@ "InvoiceIn": { "dataSource": "vn" }, - "InvoiceInTax": { + "InvoiceInConfig": { "dataSource": "vn" }, "InvoiceInDueDay": { @@ -13,5 +13,8 @@ }, "InvoiceInLog": { "dataSource": "vn" + }, + "InvoiceInTax": { + "dataSource": "vn" } } diff --git a/modules/invoiceIn/back/models/invoice-in-config.json b/modules/invoiceIn/back/models/invoice-in-config.json new file mode 100644 index 000000000..5cf0ed64c --- /dev/null +++ b/modules/invoiceIn/back/models/invoice-in-config.json @@ -0,0 +1,35 @@ +{ + "name": "InvoiceInConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "invoiceInConfig" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "retentionRate": { + "type": "number" + }, + "retentionName": { + "type": "string" + } + }, + "relations": { + "sageWithholding": { + "type": "belongsTo", + "model": "SageWithholding", + "foreignKey": "sageWithholdingFk" + } + }, + "acls": [{ + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} diff --git a/modules/invoiceIn/front/descriptor/index.html b/modules/invoiceIn/front/descriptor/index.html index a2b48b5cd..40f7dec18 100644 --- a/modules/invoiceIn/front/descriptor/index.html +++ b/modules/invoiceIn/front/descriptor/index.html @@ -1,3 +1,10 @@ + + Show agricultural invoice as PDF Send agricultural invoice as PDF diff --git a/modules/invoiceIn/front/descriptor/index.js b/modules/invoiceIn/front/descriptor/index.js index 5cd00d743..4dc89a459 100644 --- a/modules/invoiceIn/front/descriptor/index.js +++ b/modules/invoiceIn/front/descriptor/index.js @@ -110,6 +110,10 @@ class Controller extends Descriptor { recipientId: this.entity.supplier.id }); } + + isAgricultural() { + return this.invoiceIn.supplier.sageWithholdingFk == this.config[0].sageWithholdingFk; + } } ngModule.vnComponent('vnInvoiceInDescriptor', { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js index 536fa07a0..2c27e0990 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js @@ -13,6 +13,7 @@ describe('InvoiceOut downloadZip()', () => { }; it('should return part of link to dowloand the zip', async() => { + pending('https://redmine.verdnatura.es/issues/4875'); const tx = await models.InvoiceOut.beginTransaction({}); try { diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index f10e059ad..100d27cd0 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -256,7 +256,7 @@ class Controller extends Section { this.$http.post(`NotificationQueues`, { notificationFk: 'invoiceElectronic', authorFk: client.id, - }).then(a => { + }).then(() => { this.vnApp.showSuccess(this.$t('Invoice sent')); }); } diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index bdc4b0759..26294787b 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -20,7 +20,7 @@ {{$t('ref')}} - {{entry.ref}} + {{entry.invoiceNumber}} diff --git a/print/templates/reports/entry-order/sql/entry.sql b/print/templates/reports/entry-order/sql/entry.sql index 44feaae01..57b8d9293 100644 --- a/print/templates/reports/entry-order/sql/entry.sql +++ b/print/templates/reports/entry-order/sql/entry.sql @@ -1,10 +1,10 @@ SELECT e.id, - e.ref, + e.invoiceNumber, e.notes, c.code companyCode, t.landed FROM entry e JOIN travel t ON t.id = e.travelFk JOIN company c ON c.id = e.companyFk -WHERE e.id = ? \ No newline at end of file +WHERE e.id = ? diff --git a/print/templates/reports/extra-community/extra-community.html b/print/templates/reports/extra-community/extra-community.html index 42afedc76..6a46cc689 100644 --- a/print/templates/reports/extra-community/extra-community.html +++ b/print/templates/reports/extra-community/extra-community.html @@ -49,7 +49,7 @@ {{entry.supplierName}} - {{entry.ref}} + {{entry.reference}} {{entry.volumeKg | number($i18n.locale)}} {{entry.loadedKg | number($i18n.locale)}} {{entry.stickers}} diff --git a/print/templates/reports/extra-community/sql/entries.sql b/print/templates/reports/extra-community/sql/entries.sql index a90bf8b0b..84dc497c0 100644 --- a/print/templates/reports/extra-community/sql/entries.sql +++ b/print/templates/reports/extra-community/sql/entries.sql @@ -1,7 +1,7 @@ SELECT e.id, e.travelFk, - e.ref, + e.reference, s.name AS supplierName, SUM(b.stickers) AS stickers, CAST(SUM(b.weight * b.stickers) as DECIMAL(10,0)) as loadedKg, @@ -15,4 +15,4 @@ SELECT JOIN supplier s ON s.id = e.supplierFk JOIN vn.volumeConfig vc WHERE t.id IN(?) - GROUP BY e.id \ No newline at end of file + GROUP BY e.id diff --git a/print/templates/reports/invoiceIn/invoiceIn.html b/print/templates/reports/invoiceIn/invoiceIn.html index 69ce3d0f2..f101f7408 100644 --- a/print/templates/reports/invoiceIn/invoiceIn.html +++ b/print/templates/reports/invoiceIn/invoiceIn.html @@ -5,9 +5,8 @@
-
-
-

{{$t('title')}}

+
+
@@ -16,7 +15,7 @@ - + @@ -26,7 +25,7 @@
{{$t('invoiceId')}}{{invoice.id}}{{invoice.supplierRef}}
{{$t('date')}}
-
+
{{$t('invoiceData')}}
@@ -43,7 +42,7 @@
-

{{$t('invoiceId')}}

+

{{$t('entry')}}

@@ -64,7 +63,7 @@
- {{entry.ref}} + {{entry.reference}}
@@ -82,7 +81,7 @@ {{buy.name}} {{buy.quantity}} - {{buy.buyingValue}} + {{buy.buyingValue | currency('EUR', $i18n.locale)}} {{buyImport(buy) | currency('EUR', $i18n.locale)}} @@ -103,27 +102,31 @@
+
-
+
+
+
{{$t('payMethod')}}: {{invoice.payMethod}}
+
+
{{$t('signer.received')}}:
+
{{$t('signer.signed')}}:
+
+
+
+ +
- - - - - - - - - - + + @@ -150,28 +153,16 @@ -
-
-
-
{{$t('observations')}}
-
-
{{$t('payMethod')}}
-
{{invoice.payMethod}}
-
-
-
-
+ + + diff --git a/print/templates/reports/invoiceIn/invoiceIn.js b/print/templates/reports/invoiceIn/invoiceIn.js index 40dd25a5b..03549c276 100755 --- a/print/templates/reports/invoiceIn/invoiceIn.js +++ b/print/templates/reports/invoiceIn/invoiceIn.js @@ -9,6 +9,16 @@ module.exports = { this.invoice = await this.fetchInvoice(this.id); this.taxes = await this.fetchTaxes(this.id); + let defaultTax = await this.fetchDefaultTax(); + + if (defaultTax) { + defaultTax = Object.assign(defaultTax, { + taxableBase: 0, + vat: (this.taxTotal() * defaultTax.rate / 100) + }); + this.taxes.push(defaultTax); + } + if (!this.invoice) throw new Error('Something went wrong'); @@ -43,6 +53,9 @@ module.exports = { fetchBuy(id) { return this.rawSqlFromDef('buy', [id]); }, + fetchDefaultTax() { + return this.findOneFromDef('defaultTax'); + }, async fetchTaxes(id) { const taxes = await this.rawSqlFromDef(`taxes`, [id]); return this.taxVat(taxes); diff --git a/print/templates/reports/invoiceIn/locale/en.yml b/print/templates/reports/invoiceIn/locale/en.yml index 92d3b0c2d..5f41a9ceb 100644 --- a/print/templates/reports/invoiceIn/locale/en.yml +++ b/print/templates/reports/invoiceIn/locale/en.yml @@ -1,6 +1,6 @@ -reportName: invoice -title: Agricultural invoice -invoiceId: Agricultural invoice +reportName: agricultural receip +title: Agricultural receip +invoiceId: Agricultural receip supplierId: Proveedor invoiceData: Invoice data reference: Reference @@ -23,3 +23,8 @@ subtotal: Subtotal taxBreakdown: Tax breakdown observations: Observations payMethod: Pay method +entry: Entry +signer: + received: Received + signed: Signature +footer: Passive subject covered by the special agrarian regime. Please send this duly signed and sealed copy. Thanks. diff --git a/print/templates/reports/invoiceIn/locale/es.yml b/print/templates/reports/invoiceIn/locale/es.yml index f2fb28e64..90f7db6bd 100644 --- a/print/templates/reports/invoiceIn/locale/es.yml +++ b/print/templates/reports/invoiceIn/locale/es.yml @@ -1,6 +1,6 @@ -reportName: factura -title: Factura Agrícola -invoiceId: Factura Agrícola +reportName: recibo agrícola +title: Recibo Agrícola +invoiceId: Recibo Agrícola supplierId: Proveedor invoiceData: Datos de facturación reference: Referencia @@ -23,3 +23,8 @@ subtotal: Subtotal taxBreakdown: Desglose impositivo observations: Observaciones payMethod: Método de pago +entry: Entrada +signer: + received: Recibí + signed: Firma y sello +footer: Sujeto pasivo acogido al régimen especial agrario. Les rogamos remitan esta copia debidamente firmada y sellada. Gracias. diff --git a/print/templates/reports/invoiceIn/sql/defaultTax.sql b/print/templates/reports/invoiceIn/sql/defaultTax.sql new file mode 100644 index 000000000..25f8a7090 --- /dev/null +++ b/print/templates/reports/invoiceIn/sql/defaultTax.sql @@ -0,0 +1,5 @@ +SELECT + id, + retentionRate rate, + retentionName name + FROM invoiceInConfig; diff --git a/print/templates/reports/invoiceIn/sql/entry.sql b/print/templates/reports/invoiceIn/sql/entry.sql index 0b29cd81c..d81a81afb 100644 --- a/print/templates/reports/invoiceIn/sql/entry.sql +++ b/print/templates/reports/invoiceIn/sql/entry.sql @@ -1,7 +1,7 @@ SELECT e.id, t.landed, - e.ref + e.reference FROM entry e JOIN invoiceIn i ON i.id = e.invoiceInFk JOIN travel t ON t.id = e.travelFk diff --git a/print/templates/reports/invoiceIn/sql/invoice.sql b/print/templates/reports/invoiceIn/sql/invoice.sql index fe9ef1e9e..eea8e81a5 100644 --- a/print/templates/reports/invoiceIn/sql/invoice.sql +++ b/print/templates/reports/invoiceIn/sql/invoice.sql @@ -1,5 +1,5 @@ SELECT - i.id, + i.supplierRef, s.id supplierId, i.created, s.name, diff --git a/print/templates/reports/invoiceIn/sql/taxes.sql b/print/templates/reports/invoiceIn/sql/taxes.sql index 20df33f83..07b7be822 100644 --- a/print/templates/reports/invoiceIn/sql/taxes.sql +++ b/print/templates/reports/invoiceIn/sql/taxes.sql @@ -5,4 +5,5 @@ SELECT FROM invoiceIn ii JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk - WHERE ii.id = ?; + WHERE ii.id = ? + ORDER BY name DESC; diff --git a/print/templates/reports/supplier-campaign-metrics/sql/entries.sql b/print/templates/reports/supplier-campaign-metrics/sql/entries.sql index aa458dda0..b48e99c23 100644 --- a/print/templates/reports/supplier-campaign-metrics/sql/entries.sql +++ b/print/templates/reports/supplier-campaign-metrics/sql/entries.sql @@ -1,6 +1,6 @@ SELECT e.id, - e.ref, + e.reference, e.supplierFk, t.shipped FROM vn.entry e diff --git a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html index fd6ee5725..baff51bfe 100644 --- a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html +++ b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html @@ -39,7 +39,7 @@

{{$t('entry')}} {{entry.id}} {{$t('dated')}} {{entry.shipped | date('%d-%m-%Y')}} - {{$t('reference')}} {{entry.ref}} + {{$t('reference')}} {{entry.reference}}

{{$t('taxBreakdown')}}
{{$t('type')}}{{$t('taxBase')}}{{$t('tax')}}{{$t('fee')}}
{{tax.name}}{{tax.taxableBase | currency('EUR', $i18n.locale)}}{{tax.rate | percentage}}{{tax.taxableBase | currency('EUR', $i18n.locale)}} + {{(tax.rate / 100) | percentage}} {{tax.vat | currency('EUR', $i18n.locale)}}
From b72cb64bf8f4322284160cd9f241f7b9051fb5c0 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 16 Dec 2022 12:50:09 +0100 Subject: [PATCH 10/10] refs #4928 findById --- modules/supplier/back/models/specs/supplier.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 1e8efb4b1..f317f1fb9 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -73,7 +73,7 @@ describe('loopback model Supplier', () => { await supplierTwo.updateAttribute('isPayMethodChecked', true, options); await supplierTwo.updateAttribute('payMethodFk', 5, options); - const result = await models.Supplier.findOne({where: {id: 442}}, options); + const result = await models.Supplier.findById(442, null, options); expect(result.isPayMethodChecked).toEqual(true); await tx.rollback(); @@ -91,7 +91,7 @@ describe('loopback model Supplier', () => { await supplierTwo.updateAttribute('isPayMethodChecked', true, options); await supplierTwo.updateAttribute('payMethodFk', 2, options); - const result = await models.Supplier.findOne({where: {id: 442}}, options); + const result = await models.Supplier.findById(442, null, options); expect(result.isPayMethodChecked).toEqual(false); await tx.rollback(); @@ -109,11 +109,11 @@ describe('loopback model Supplier', () => { await supplierTwo.updateAttribute('payMethodFk', 2, options); await supplierTwo.updateAttribute('isPayMethodChecked', true, options); await supplierTwo.updateAttribute('payDay', 5, options); - const firstResult = await models.Supplier.findOne({where: {id: 442}}, options); + const firstResult = await models.Supplier.findById(442, null, options); await supplierTwo.updateAttribute('isPayMethodChecked', true, options); await supplierTwo.updateAttribute('payDemFk', 1, options); - const secondResult = await models.Supplier.findOne({where: {id: 442}}, options); + const secondResult = await models.Supplier.findById(442, null, options); expect(firstResult.isPayMethodChecked).toEqual(false); expect(secondResult.isPayMethodChecked).toEqual(false);