From fea0db14e2b1d135a84d81ea33a43fa83a4dfc3e Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 30 Aug 2023 13:35:51 +0200 Subject: [PATCH 1/6] fixes #6169 invoiceIn con valores predeterminados --- modules/invoiceIn/front/basic-data/index.js | 27 ++++++++++++-------- modules/invoiceIn/front/create/index.js | 1 + modules/invoiceIn/front/create/index.spec.js | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/invoiceIn/front/basic-data/index.js b/modules/invoiceIn/front/basic-data/index.js index 8747fc4f22..246f1b16fd 100644 --- a/modules/invoiceIn/front/basic-data/index.js +++ b/modules/invoiceIn/front/basic-data/index.js @@ -67,17 +67,22 @@ class Controller extends Section { } openCreateDialog() { - this.dms = { - reference: null, - warehouseId: null, - companyId: null, - dmsTypeId: null, - description: null, - hasFile: true, - hasFileAttached: true, - files: null - }; - this.$.dmsCreateDialog.show(); + const params = {filter: { + where: {code: 'invoiceIn'} + }}; + this.$http.get('DmsTypes/findOne', {params}).then(res => { + this.dms = { + reference: this.invoiceIn.supplierRef, + warehouseId: this.vnConfig.warehouseFk, + companyId: this.vnConfig.companyFk, + dmsTypeId: res.data.id, + description: this.invoiceIn.supplier.name, + hasFile: true, + hasFileAttached: true, + files: null + }; + this.$.dmsCreateDialog.show(); + }); } downloadFile(dmsId) { diff --git a/modules/invoiceIn/front/create/index.js b/modules/invoiceIn/front/create/index.js index 186f5d478e..885d55359b 100644 --- a/modules/invoiceIn/front/create/index.js +++ b/modules/invoiceIn/front/create/index.js @@ -6,6 +6,7 @@ class Controller extends Section { this.invoiceIn = {}; if (this.$params && this.$params.supplierFk) this.invoiceIn.supplierFk = this.$params.supplierFk; + this.invoiceIn.issued = Date.vnNew(); } get companyFk() { diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js index 93109346c2..1b6c903ce9 100644 --- a/modules/invoiceIn/front/create/index.spec.js +++ b/modules/invoiceIn/front/create/index.spec.js @@ -26,7 +26,7 @@ describe('InvoiceIn', () => { controller.$onInit(); - expect(controller.invoiceIn).toEqual({}); + expect(controller.invoiceIn).toBeDefined(); }); it(`should define invoiceIn and it's supplierFk when received via params`, () => { From 30c863722cf5d40f28cd7dc6e8fa2c5adde3e4c4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 30 Aug 2023 14:14:20 +0200 Subject: [PATCH 2/6] fixes #6169 no se necesita tests --- modules/invoiceIn/front/create/index.spec.js | 52 -------------------- 1 file changed, 52 deletions(-) delete mode 100644 modules/invoiceIn/front/create/index.spec.js diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js deleted file mode 100644 index 1b6c903ce9..0000000000 --- a/modules/invoiceIn/front/create/index.spec.js +++ /dev/null @@ -1,52 +0,0 @@ -import './index.js'; -import watcher from 'core/mocks/watcher'; - -describe('InvoiceIn', () => { - describe('Component vnInvoiceInCreate', () => { - let controller; - let $element; - - beforeEach(ngModule('invoiceIn')); - - beforeEach(inject(($componentController, $rootScope) => { - const $scope = $rootScope.$new(); - $scope.watcher = watcher; - $element = angular.element(''); - controller = $componentController('vnInvoiceInCreate', {$element, $scope}); - controller.$params = {}; - })); - - afterEach(() => { - $element.remove(); - }); - - describe('onInit()', () => { - it(`should defined the controller's invoiceIn property`, () => { - expect(controller.invoiceIn).toBeUndefined(); - - controller.$onInit(); - - expect(controller.invoiceIn).toBeDefined(); - }); - - it(`should define invoiceIn and it's supplierFk when received via params`, () => { - controller.$params.supplierFk = 'supplierId'; - - controller.$onInit(); - - expect(controller.invoiceIn.supplierFk).toEqual('supplierId'); - }); - }); - - describe('onSubmit()', () => { - it(`should redirect to basic data by calling the $state.go function`, () => { - jest.spyOn(controller.$state, 'go'); - - controller.onSubmit(); - - expect(controller.$state.go).toHaveBeenCalledWith('invoiceIn.card.basicData', {id: 1234}); - }); - }); - }); -}); - From 40468b70e69815dfe847aabcc940c624d7eebb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 4 Sep 2023 11:59:55 +0200 Subject: [PATCH 3/6] refs #6176 book entry deleted --- .../233801/00-notificationBookEntry.sql | 14 +++++++++++ .../back/methods/invoiceOut/delete.js | 24 ++++++++++++++++--- .../book-entry-deleted/assets/css/import.js | 12 ++++++++++ .../book-entry-deleted.html | 8 +++++++ .../book-entry-deleted/book-entry-deleted.js | 19 +++++++++++++++ .../email/book-entry-deleted/locale/en.yml | 5 ++++ .../email/book-entry-deleted/locale/es.yml | 5 ++++ 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 db/changes/233801/00-notificationBookEntry.sql create mode 100644 print/templates/email/book-entry-deleted/assets/css/import.js create mode 100644 print/templates/email/book-entry-deleted/book-entry-deleted.html create mode 100644 print/templates/email/book-entry-deleted/book-entry-deleted.js create mode 100644 print/templates/email/book-entry-deleted/locale/en.yml create mode 100644 print/templates/email/book-entry-deleted/locale/es.yml diff --git a/db/changes/233801/00-notificationBookEntry.sql b/db/changes/233801/00-notificationBookEntry.sql new file mode 100644 index 0000000000..4b8320450e --- /dev/null +++ b/db/changes/233801/00-notificationBookEntry.sql @@ -0,0 +1,14 @@ + +INSERT IGNORE INTO util.`notification` (id, `name`, description) + SELECT MAX(id) + 1, 'book-entry-deleted', 'accounting entries deleted' + FROM util.`notification`; + +INSERT IGNORE INTO util.`notificationAcl` (notificationFk, roleFk) + VALUES( + (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'), + (SELECT id FROM vn.`role` r WHERE `name` = 'administrative')); + +INSERT IGNORE INTO util.`notificationSubscription` (notificationFk, userFk) + VALUES( + (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'), + (SELECT id FROM account.`user` WHERE `name` = 'admon')); diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index d8b9d309b4..726e455ab7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -1,5 +1,4 @@ - -module.exports = Self => { +export default Self => { Self.remoteMethod('delete', { description: 'Delete a invoiceOut', accessType: 'WRITE', @@ -37,7 +36,12 @@ module.exports = Self => { const tickets = await Self.app.models.Ticket.find({ where: {refFk: invoiceOut.ref} }, myOptions); - + const bookEntry = await Self.app.models.XDiario.find({ + where: { + SERIE: invoiceOut.ref[0], + FACTURA: invoiceOut.miCadena.slice(1) + } + }, myOptions); const promises = []; for (let ticket of tickets) @@ -47,6 +51,20 @@ module.exports = Self => { await invoiceOut.destroy(myOptions); + if (bookEntry) { + const params = { + bookEntries: bookEntry.ASIEN, + invoiceOutRef: invoiceOut.ref + }; + + await Self.rawSql('SELECT util.notification_send(?, ?, NULL)', + 'book-entry-deleted', + params, + myOptions); + + await bookEntry.destroy(myOptions); + } + if (tx) await tx.commit(); return tickets; diff --git a/print/templates/email/book-entry-deleted/assets/css/import.js b/print/templates/email/book-entry-deleted/assets/css/import.js new file mode 100644 index 0000000000..1582b82c50 --- /dev/null +++ b/print/templates/email/book-entry-deleted/assets/css/import.js @@ -0,0 +1,12 @@ +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/book-entry-deleted/book-entry-deleted.html b/print/templates/email/book-entry-deleted/book-entry-deleted.html new file mode 100644 index 0000000000..9a9f2a93e3 --- /dev/null +++ b/print/templates/email/book-entry-deleted/book-entry-deleted.html @@ -0,0 +1,8 @@ + +
+
+

{{ $t('title') }}

+

+
+
+
diff --git a/print/templates/email/book-entry-deleted/book-entry-deleted.js b/print/templates/email/book-entry-deleted/book-entry-deleted.js new file mode 100644 index 0000000000..f7e7ffab49 --- /dev/null +++ b/print/templates/email/book-entry-deleted/book-entry-deleted.js @@ -0,0 +1,19 @@ +const Component = require(`vn-print/core/component`); +const emailBody = new Component(); + +module.exports = { + name: 'book-entries-deleted', + components: { + 'email-body': emailBody.build(), + }, + props: { + bookEntries: { + type: Number, + required: true + }, + invoiceOutRef: { + type: String, + required: true + } + } +}; diff --git a/print/templates/email/book-entry-deleted/locale/en.yml b/print/templates/email/book-entry-deleted/locale/en.yml new file mode 100644 index 0000000000..c7408f1149 --- /dev/null +++ b/print/templates/email/book-entry-deleted/locale/en.yml @@ -0,0 +1,5 @@ +Subject: Linked Accounting Entry Deleted +Title: Linked Accounting Entry Deleted +Description: The linked accounting entry that was associated with SAGE has been deleted.

+Entry No. {0}

+This entry has been deleted because the associated invoice {0} has been removed. diff --git a/print/templates/email/book-entry-deleted/locale/es.yml b/print/templates/email/book-entry-deleted/locale/es.yml new file mode 100644 index 0000000000..ff2073b640 --- /dev/null +++ b/print/templates/email/book-entry-deleted/locale/es.yml @@ -0,0 +1,5 @@ +subject: Asiento contable enlazado eliminado +title: Asiento contable enlazado eliminado +description: Se ha borrado el asiento contable que se encuentraba enlazado a SAGE

+ Asientos nº {0}

+ Este asiento se ha borrado porque se ha eliminado la factura asociada {0} From 0d2db7749f5a1c8a9f5825c41a73bd50f79ad91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 6 Sep 2023 21:22:10 +0200 Subject: [PATCH 4/6] refs #6176 book entry deleted --- db/dump/fixtures.sql | 20 ++- modules/client/back/model-config.json | 3 + modules/client/back/models/XDiario.json | 13 +- modules/entry/back/locale/entry/es.yml | 6 +- .../back/methods/invoiceOut/delete.js | 31 +++-- .../methods/invoiceOut/specs/delete.spec.js | 122 +++++++++++++++++- .../book-entry-deleted/book-entry-deleted.js | 4 +- 7 files changed, 166 insertions(+), 33 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b01c074616..24496098d1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2776,11 +2776,13 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) (2, 'invoice-electronic', 'A electronic invoice has been generated'), (3, 'not-main-printer-configured', 'A printer distinct than main has been configured'), (4, 'supplier-pay-method-update', 'A supplier pay method has been updated'), - (5, 'modified-entry', 'An entry has been modified'); + (5, 'modified-entry', 'An entry has been modified'), + (6, 'book-entry-deleted', 'accounting entries deleted'); INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) VALUES - (1, 9); + (1, 9), + (6, 9); INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) VALUES @@ -2793,8 +2795,9 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) (1, 1109), (1, 1110), (2, 1109), - (1,9), - (1,3); + (1, 9), + (1, 3), + (6, 9); INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) @@ -2958,3 +2961,12 @@ INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `t INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) VALUES (1, 0, 0, 'marvel.com'); + +INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, BASEEURO, SERIE, FACTURA, IVA, RECEQUIV, CLAVE, CAMBIO, DEBEME, HABERME, AUXILIAR, MONEDAUSO, TIPOOPE, NFACTICK, TERIDNIF, TERNIF, TERNOM, OPBIENES, L340, enlazado, FECHA_EX, LRECT349, empresa_id, LDIFADUAN, METAL, METALIMP, CLIENTE, METALEJE, FECHA_OP, FACTURAEX, TIPOCLAVE, TIPOEXENCI, TIPONOSUJE, TIPOFACT, TIPORECTIF, SERIE_RT, FACTU_RT, BASEIMP_RT, BASEIMP_RF, RECTIFICA, FECHA_RT, FECREGCON, enlazadoSage) + VALUES + (1, 1.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T3333333', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (2, 1.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T3333333 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (3, 1.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T3333333 Tony Stark', NULL, 0.81, 8.07, 'T', '3333333', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (4, 2.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T4444444', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), + (5, 2.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T4444444 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), + (6, 2.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T4444444 Tony Stark', NULL, 0.81, 8.07, 'T', '4444444', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0); \ No newline at end of file diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index bc48ec360c..296b5e6a7b 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -136,5 +136,8 @@ }, "Incoterms": { "dataSource": "vn" + }, + "Xdiario": { + "dataSource": "vn" } } diff --git a/modules/client/back/models/XDiario.json b/modules/client/back/models/XDiario.json index be2d258f98..be543393de 100644 --- a/modules/client/back/models/XDiario.json +++ b/modules/client/back/models/XDiario.json @@ -1,5 +1,5 @@ { - "name": "XDiario", + "name": "Xdiario", "base": "VnModel", "options": { "mysql": { @@ -7,10 +7,12 @@ } }, "properties": { - "ASIEN": { + "id": { "type": "number", - "id": true, - "description": "Identifier" + "id": true + }, + "ASIEN": { + "type": "number" }, "FECHA": { "type": "date" @@ -71,6 +73,9 @@ }, "MONEDAUSO": { "type": "string" + }, + "enlazadoSage": { + "type": "boolean" } }, "relations": { diff --git a/modules/entry/back/locale/entry/es.yml b/modules/entry/back/locale/entry/es.yml index 3a0c3d9c18..a892b05d28 100644 --- a/modules/entry/back/locale/entry/es.yml +++ b/modules/entry/back/locale/entry/es.yml @@ -4,14 +4,14 @@ columns: dated: fecha reference: referencia invoiceNumber: número factura - isBooked: reservado + isBooked: contabilizado isExcludedFromAvailable: excluido del disponible notes: notas isConfirmed: confirmado isVirtual: virtual - isRaid: incursión + isRaid: redada commission: comisión - isOrdered: precio3 + isOrdered: pedida created: creado observation: observación isBlocked: bloqueado diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index 726e455ab7..d6efd99619 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -1,4 +1,4 @@ -export default Self => { +module.exports = Self => { Self.remoteMethod('delete', { description: 'Delete a invoiceOut', accessType: 'WRITE', @@ -33,13 +33,15 @@ export default Self => { try { const invoiceOut = await Self.findById(id, {}, myOptions); - const tickets = await Self.app.models.Ticket.find({ + const models = Self.app.models; + const tickets = await models.Ticket.find({ where: {refFk: invoiceOut.ref} }, myOptions); - const bookEntry = await Self.app.models.XDiario.find({ + + const [bookEntry] = await models.Xdiario.find({ where: { SERIE: invoiceOut.ref[0], - FACTURA: invoiceOut.miCadena.slice(1) + FACTURA: invoiceOut.ref.slice(1) } }, myOptions); const promises = []; @@ -48,21 +50,22 @@ export default Self => { promises.push(ticket.updateAttribute('refFk', null, myOptions)); await Promise.all(promises); - await invoiceOut.destroy(myOptions); if (bookEntry) { - const params = { - bookEntries: bookEntry.ASIEN, - invoiceOutRef: invoiceOut.ref + if (bookEntry.enlazadoSage) { + const params = { + bookEntry: bookEntry.ASIEN, + invoiceOutRef: invoiceOut.ref + } + await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`, + [JSON.stringify(params)], + myOptions); }; - await Self.rawSql('SELECT util.notification_send(?, ?, NULL)', - 'book-entry-deleted', - params, - myOptions); - - await bookEntry.destroy(myOptions); + await models.Xdiario.destroyAll({ + ASIEN: bookEntry.ASIEN + }); } if (tx) await tx.commit(); diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js index a662cb318f..b9084d8d2c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js @@ -2,8 +2,8 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('invoiceOut delete()', () => { - const invoiceOutId = 2; - const userId = 1106; + const invoiceId = 2; + const userId = 106; const activeCtx = { accessToken: {userId: userId}, }; @@ -13,7 +13,7 @@ describe('invoiceOut delete()', () => { const options = {transaction: tx}; try { - const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options); + const invoiceOut = await models.InvoiceOut.findById(invoiceId, {}, options); const tickets = await models.Ticket.find({where: {refFk: invoiceOut.ref}}, options); expect(tickets.length).toEqual(1); @@ -35,11 +35,10 @@ describe('invoiceOut delete()', () => { active: activeCtx }); - await models.InvoiceOut.delete(invoiceOutId, options); - + await models.InvoiceOut.delete(invoiceId, options); const originalTicket = await models.Ticket.findById(3, {}, options); - const deletedInvoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options); + const deletedInvoiceOut = await models.InvoiceOut.findById(invoiceId, {}, options); expect(deletedInvoiceOut).toBeNull(); expect(originalTicket.refFk).toBeNull(); @@ -50,4 +49,115 @@ describe('invoiceOut delete()', () => { throw e; } }); + + it('should delete the corresponding bookEntry and not notify', async () => { + const tx = await models.InvoiceOut.beginTransaction({}); + const options = {transaction: tx}; + + try { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + + const filter = { + where: { + ASIEN: 2 + }, + fields: ['id', 'enlazadoSage'] + }; + + const [beforeXdiario] = await models.Xdiario.find(filter, options) + + const [beforeNotification] = await models.NotificationQueue.find({ + where: { + notificationFk: 'book-entry-deleted', + status: 'pending' + } + }, options); + + expect(beforeXdiario).toBeDefined(); + expect(beforeXdiario.enlazadoSage).toBeFalsy; + expect(beforeNotification).not.toBeDefined(); + + await models.InvoiceOut.delete(4, options); + + const [afterXdiario] = await models.Xdiario.find({ + where: { + ASIEN: 2 + } + }, options); + + const [afterNotification] = await models.NotificationQueue.find({ + where: { + notificationFk: 'book-entry-deleted', + params: '{"bookEntry":2,"invoiceOutRef":"T4444444"}', + status: 'pending' + } + }, options); + + expect(afterXdiario).not.toBeDefined(); + expect(afterNotification).not.toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should delete the corresponding bookEntry and notify', async () => { + const tx = await models.InvoiceOut.beginTransaction({}); + const options = {transaction: tx}; + + try { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + + const filter = { + where: { + ASIEN: 1 + }, + fields: ['id', 'enlazadoSage'] + }; + + const [beforeXdiario] = await models.Xdiario.find(filter, options) + + const [beforeNotification] = await models.NotificationQueue.find({ + where: { + notificationFk: 'book-entry-deleted', + status: 'pending' + } + }, options); + + expect(beforeXdiario).toBeDefined(); + expect(beforeXdiario.enlazadoSage).toBeTruthy(); + expect(beforeNotification).not.toBeDefined(); + + await models.InvoiceOut.delete(3, options); + + const [afterXdiario] = await models.Xdiario.find({ + where: { + ASIEN: 1 + } + }, options); + + const [afterNotification] = await models.NotificationQueue.find({ + where: { + notificationFk: 'book-entry-deleted', + params: '{"bookEntry":1,"invoiceOutRef":"T3333333"}', + status: 'pending' + } + }, options); + + expect(afterXdiario).not.toBeDefined(); + expect(afterNotification).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + }); diff --git a/print/templates/email/book-entry-deleted/book-entry-deleted.js b/print/templates/email/book-entry-deleted/book-entry-deleted.js index f7e7ffab49..cd29f5ddbf 100644 --- a/print/templates/email/book-entry-deleted/book-entry-deleted.js +++ b/print/templates/email/book-entry-deleted/book-entry-deleted.js @@ -2,12 +2,12 @@ const Component = require(`vn-print/core/component`); const emailBody = new Component(); module.exports = { - name: 'book-entries-deleted', + name: 'book-entry-deleted', components: { 'email-body': emailBody.build(), }, props: { - bookEntries: { + bookEntry: { type: Number, required: true }, From ea771cb910f5956dc9b28c74f224a3c301cd7e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 7 Sep 2023 11:30:01 +0200 Subject: [PATCH 5/6] refs #6176 book entry deleted --- db/changes/233801/00-notificationBookEntry.sql | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 db/changes/233801/00-notificationBookEntry.sql diff --git a/db/changes/233801/00-notificationBookEntry.sql b/db/changes/233801/00-notificationBookEntry.sql deleted file mode 100644 index 4b8320450e..0000000000 --- a/db/changes/233801/00-notificationBookEntry.sql +++ /dev/null @@ -1,14 +0,0 @@ - -INSERT IGNORE INTO util.`notification` (id, `name`, description) - SELECT MAX(id) + 1, 'book-entry-deleted', 'accounting entries deleted' - FROM util.`notification`; - -INSERT IGNORE INTO util.`notificationAcl` (notificationFk, roleFk) - VALUES( - (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'), - (SELECT id FROM vn.`role` r WHERE `name` = 'administrative')); - -INSERT IGNORE INTO util.`notificationSubscription` (notificationFk, userFk) - VALUES( - (SELECT id FROM util.`notification` WHERE `name` = 'book-entry-deleted'), - (SELECT id FROM account.`user` WHERE `name` = 'admon')); From 4784e71350d0d586b01bb5da90850b8a8bc583d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 7 Sep 2023 13:21:03 +0200 Subject: [PATCH 6/6] refs #6176 book entry deleted --- .../methods/invoiceOut/specs/delete.spec.js | 28 ++++++++----------- .../email/book-entry-deleted/locale/en.yml | 2 +- .../email/book-entry-deleted/locale/es.yml | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js index b9084d8d2c..9d638ecf4f 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js @@ -2,18 +2,24 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('invoiceOut delete()', () => { - const invoiceId = 2; + const invoiceOutId = 2; const userId = 106; const activeCtx = { accessToken: {userId: userId}, }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); it('should check that there is one ticket in the target invoiceOut', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; try { - const invoiceOut = await models.InvoiceOut.findById(invoiceId, {}, options); + const invoiceOut = await models.InvoiceOut.findById(invoiceOutId , {}, options); const tickets = await models.Ticket.find({where: {refFk: invoiceOut.ref}}, options); expect(tickets.length).toEqual(1); @@ -31,14 +37,10 @@ describe('invoiceOut delete()', () => { const options = {transaction: tx}; try { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - - await models.InvoiceOut.delete(invoiceId, options); + await models.InvoiceOut.delete(invoiceOutId, options); const originalTicket = await models.Ticket.findById(3, {}, options); - const deletedInvoiceOut = await models.InvoiceOut.findById(invoiceId, {}, options); + const deletedInvoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options); expect(deletedInvoiceOut).toBeNull(); expect(originalTicket.refFk).toBeNull(); @@ -54,11 +56,7 @@ describe('invoiceOut delete()', () => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; - try { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - + try { const filter = { where: { ASIEN: 2 @@ -110,10 +108,6 @@ describe('invoiceOut delete()', () => { const options = {transaction: tx}; try { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - const filter = { where: { ASIEN: 1 diff --git a/print/templates/email/book-entry-deleted/locale/en.yml b/print/templates/email/book-entry-deleted/locale/en.yml index c7408f1149..11c18f2c98 100644 --- a/print/templates/email/book-entry-deleted/locale/en.yml +++ b/print/templates/email/book-entry-deleted/locale/en.yml @@ -2,4 +2,4 @@ Subject: Linked Accounting Entry Deleted Title: Linked Accounting Entry Deleted Description: The linked accounting entry that was associated with SAGE has been deleted.

Entry No. {0}

-This entry has been deleted because the associated invoice {0} has been removed. +This entry has been deleted because the associated invoice {1} has been removed. diff --git a/print/templates/email/book-entry-deleted/locale/es.yml b/print/templates/email/book-entry-deleted/locale/es.yml index ff2073b640..c40cf25fd7 100644 --- a/print/templates/email/book-entry-deleted/locale/es.yml +++ b/print/templates/email/book-entry-deleted/locale/es.yml @@ -2,4 +2,4 @@ subject: Asiento contable enlazado eliminado title: Asiento contable enlazado eliminado description: Se ha borrado el asiento contable que se encuentraba enlazado a SAGE

Asientos nº {0}

- Este asiento se ha borrado porque se ha eliminado la factura asociada {0} + Este asiento se ha borrado porque se ha eliminado la factura asociada {1}