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 1/4] 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 000000000..4b8320450 --- /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 d8b9d309b..726e455ab 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 000000000..1582b82c5 --- /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 000000000..9a9f2a93e --- /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 000000000..f7e7ffab4 --- /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 000000000..c7408f114 --- /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 000000000..ff2073b64 --- /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 2/4] 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 b01c07461..24496098d 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 bc48ec360..296b5e6a7 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 be2d258f9..be543393d 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 3a0c3d9c1..a892b05d2 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 726e455ab..d6efd9961 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 a662cb318..b9084d8d2 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 f7e7ffab4..cd29f5ddb 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 3/4] 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 4b8320450..000000000 --- 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 4/4] 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 b9084d8d2..9d638ecf4 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 c7408f114..11c18f2c9 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 ff2073b64..c40cf25fd 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}