From 5a11e9ac768500ec56fff025084392316620cf38 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 5 Mar 2024 16:14:05 +0100 Subject: [PATCH 01/12] feat: refs #6942 toUnbook --- modules/client/back/models/XDiario.json | 8 +- .../back/methods/invoice-in/toUnbook.js | 78 +++++++++++++++++++ modules/invoiceIn/back/models/invoice-in.js | 1 + 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in/toUnbook.js diff --git a/modules/client/back/models/XDiario.json b/modules/client/back/models/XDiario.json index be543393d..e1eac2aa1 100644 --- a/modules/client/back/models/XDiario.json +++ b/modules/client/back/models/XDiario.json @@ -76,7 +76,13 @@ }, "enlazadoSage": { "type": "boolean" - } + }, + "enlazado": { + "type": "boolean" + }, + "CLAVE": { + "type": "number" + } }, "relations": { "company": { diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js new file mode 100644 index 000000000..4ba37330b --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -0,0 +1,78 @@ +module.exports = Self => { + Self.remoteMethodCtx('toUnbook', { + description: 'To unbook the invoiceIn', + accessType: 'WRITE', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'The invoiceIn id', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: '/:id/toUnbook', + verb: 'POST' + } + }); + + Self.toUnbook = async(ctx, id, options) => { + let tx; + const models = Self.app.models; + const myOptions = {userId: ctx.req.accessToken.userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + let isLinked; + let accountingEntries; + + let {'ASIEN': bookEntry} = await models.Xdiario.findOne({ + fields: ['ASIEN'], + where: { + and: [ + {'CLAVE': id}, + {enlazado: 0}, + {enlazadoSage: 0} + ] + } + }, myOptions); + + if (bookEntry) { + accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions); + + await models.Xdiario.destroyAll({where: {ASIEN: bookEntry}}, myOptions); + } else { + const linkedBookEntry = await models.Xdiario.findOne({ + fields: ['ASIEN'], + where: { + CLAVE: id, + and: [{or: [{enlazado: true, enlazadoSage: true}]}] + } + }, myOptions); + + bookEntry = linkedBookEntry?.ASIEN; + isLinked = true; + } + if (tx) await tx.commit(); + + return { + isLinked, + bookEntry, + accountingEntries + }; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index af5efbcdf..ffa285ce7 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -10,6 +10,7 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); require('../methods/invoice-in/corrective')(Self); + require('../methods/invoice-in/toUnbook')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn')) From 607f08b568238367a690fe1648e0b60dded5949f Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 6 Mar 2024 09:18:34 +0100 Subject: [PATCH 02/12] feat: refs #6942 xdiario fixtures --- db/dump/fixtures.before.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index aef0f13e3..3115fcbe3 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3012,7 +3012,8 @@ INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EU (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); + (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), + (7, 3.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T4444444 Tony Stark', NULL, 0.81, 8.07, 'T', '4444444', 10.00, NULL, 1, 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); INSERT INTO `vn`.`mistakeType` (`id`, `description`) VALUES From b5e8184489992af26092d73bc1c69a357f41c064 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 6 Mar 2024 09:56:22 +0100 Subject: [PATCH 03/12] fix: refs #6942 delete --- modules/invoiceIn/back/methods/invoice-in/toUnbook.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index 4ba37330b..77439d378 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -49,8 +49,7 @@ module.exports = Self => { if (bookEntry) { accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions); - - await models.Xdiario.destroyAll({where: {ASIEN: bookEntry}}, myOptions); + await models.Xdiario.destroyAll({ASIEN: bookEntry}, myOptions); } else { const linkedBookEntry = await models.Xdiario.findOne({ fields: ['ASIEN'], From f79435bd13b1579125049016f6cb509beba82e95 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 6 Mar 2024 13:41:56 +0100 Subject: [PATCH 04/12] feat: refs #6942 set false isBooed & ledger --- db/dump/fixtures.before.sql | 7 ++++--- modules/invoiceIn/back/methods/invoice-in/toUnbook.js | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 889533dc0..c2d6db362 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3009,8 +3009,7 @@ INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EU (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), - (7, 3.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T4444444 Tony Stark', NULL, 0.81, 8.07, 'T', '4444444', 10.00, NULL, 1, 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); + (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); INSERT INTO `vn`.`mistakeType` (`id`, `description`) VALUES @@ -3065,5 +3064,7 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns (2,'123456N','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',69,3,4,2,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (3,'123456B','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',567,5,6,69,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'); -UPDATE vn.department +UPDATE `vn`.`department` SET workerFk = null; + +INSERT INTO `vn`.`ledgerConfig` (lastBookEntry, maxTolerance) VALUES (2,0.01); \ No newline at end of file diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index 77439d378..1aa25ed0b 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -49,7 +49,9 @@ module.exports = Self => { if (bookEntry) { accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions); + await models.Xdiario.destroyAll({ASIEN: bookEntry}, myOptions); + await Self.updateAll({id}, {isBooked: false}, myOptions); } else { const linkedBookEntry = await models.Xdiario.findOne({ fields: ['ASIEN'], From 58635b5468c11ac99ac7b1a2640cc05c18b83707 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 11 Mar 2024 12:11:13 +0100 Subject: [PATCH 05/12] fix: refs #6942 add test & change column name --- modules/client/back/models/XDiario.json | 7 ++-- .../methods/invoice-in/specs/toUnbook.spec.js | 32 +++++++++++++++++++ .../back/methods/invoice-in/toUnbook.js | 18 +++++------ 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js diff --git a/modules/client/back/models/XDiario.json b/modules/client/back/models/XDiario.json index e1eac2aa1..5c277783a 100644 --- a/modules/client/back/models/XDiario.json +++ b/modules/client/back/models/XDiario.json @@ -80,8 +80,11 @@ "enlazado": { "type": "boolean" }, - "CLAVE": { - "type": "number" + "key": { + "type": "number", + "mysql": { + "columnName": "CLAVE" + } } }, "relations": { diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js new file mode 100644 index 000000000..b7d98e307 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/specs/toUnbook.spec.js @@ -0,0 +1,32 @@ +const models = require('vn-loopback/server/server').models; + +describe('invoiceIn toUnbook()', () => { + it('should check that invoiceIn is unbooked', async() => { + const userId = 1; + const ctx = { + req: { + + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; + const invoiceInId = 1; + const tx = await models.InvoiceIn.beginTransaction({}); + const options = {transaction: tx}; + + try { + await models.InvoiceIn.toBook(ctx, invoiceInId, options); + const bookEntry = await models.InvoiceIn.toUnbook(ctx, invoiceInId, options); + const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options); + + expect(bookEntry.accountingEntries).toEqual(4); + expect(bookEntry.isLinked).toBeFalsy(); + expect(invoiceIn.isBooked).toEqual(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index 1aa25ed0b..dca0d84dc 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -19,7 +19,7 @@ module.exports = Self => { } }); - Self.toUnbook = async(ctx, id, options) => { + Self.toUnbook = async(ctx, invoiceInId, options) => { let tx; const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; @@ -36,27 +36,27 @@ module.exports = Self => { let isLinked; let accountingEntries; - let {'ASIEN': bookEntry} = await models.Xdiario.findOne({ + let bookEntry = await models.Xdiario.findOne({ fields: ['ASIEN'], where: { and: [ - {'CLAVE': id}, + {key: invoiceInId}, {enlazado: 0}, {enlazadoSage: 0} ] } }, myOptions); - if (bookEntry) { - accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions); + if (bookEntry?.ASIEN) { + accountingEntries = await models.Xdiario.count({ASIEN: bookEntry.ASIEN}, myOptions); - await models.Xdiario.destroyAll({ASIEN: bookEntry}, myOptions); - await Self.updateAll({id}, {isBooked: false}, myOptions); + await models.Xdiario.destroyAll({ASIEN: bookEntry.ASIEN}, myOptions); + await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions); } else { const linkedBookEntry = await models.Xdiario.findOne({ fields: ['ASIEN'], where: { - CLAVE: id, + key: invoiceInId, and: [{or: [{enlazado: true, enlazadoSage: true}]}] } }, myOptions); @@ -68,7 +68,7 @@ module.exports = Self => { return { isLinked, - bookEntry, + bookEntry: bookEntry?.ASIEN, accountingEntries }; } catch (e) { From 798b4f9df0662548df39c2912e53ae4743f4b0d3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 23 May 2024 16:12:21 +0200 Subject: [PATCH 06/12] fix: refs #6942 toBook/toUnbook --- db/dump/fixtures.before.sql | 2 -- modules/invoiceIn/back/methods/invoice-in/toUnbook.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 1257d7407..672d06dd0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3799,5 +3799,3 @@ INSERT INTO `vn`.`ledgerCompany` SET INSERT INTO `vn`.`ledgerConfig` SET maxTolerance = 0.01; - -INSERT INTO `vn`.`ledgerConfig` (lastBookEntry, maxTolerance) VALUES (2,0.01); diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index dca0d84dc..617649488 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -41,8 +41,8 @@ module.exports = Self => { where: { and: [ {key: invoiceInId}, - {enlazado: 0}, - {enlazadoSage: 0} + {enlazado: false}, + {enlazadoSage: false} ] } }, myOptions); From cddc034adfaf81e224c3c052e23c7686daf0851a Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 23 May 2024 17:53:08 +0200 Subject: [PATCH 07/12] fix: refs #6942 revoke update isBooked --- .../00-modifyPrivilegesInvoiceIn.sql | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql diff --git a/db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql b/db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql new file mode 100644 index 000000000..90acd1745 --- /dev/null +++ b/db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql @@ -0,0 +1,24 @@ +REVOKE UPDATE ON vn. invoiceIn FROM administrative, hrBoss, buyer, logistic, grafana; +GRANT UPDATE (id, + serialNumber, + serial, + supplierFk, + issued, + supplierRef, + currencyFk, + created, + companyFk, + docFk, + booked, + operated, + siiTypeInvoiceInFk, + cplusRectificationTypeFk, + cplusSubjectOpFk, + cplusTaxBreakFk, + siiTrascendencyInvoiceInFk, + bookEntried, + isVatDeductible, + withholdingSageFk, + expenseFkDeductible, + editorFk +) ON vn.invoiceIn TO administrative, hrBoss, buyer, logistic, grafana; \ No newline at end of file From dc90ad65958748f4dedd4df147ba75db48788615 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 27 May 2024 10:48:32 +0200 Subject: [PATCH 08/12] fix: refs #6942 acls & back --- ...n.sql => 00-modifyInvoiceInPrivileges.sql} | 0 .../01-modifyInvoiceInAcls.sql | 22 ++++ .../methods/invoice-in/updateInvoiceIn.js | 104 ++++++++++++++++++ modules/invoiceIn/back/models/invoice-in.js | 1 + modules/invoiceIn/front/basic-data/index.html | 2 +- modules/item/back/models/expense.json | 2 +- 6 files changed, 129 insertions(+), 2 deletions(-) rename db/versions/11065-yellowChrysanthemum/{00-modifyPrivilegesInvoiceIn.sql => 00-modifyInvoiceInPrivileges.sql} (100%) create mode 100644 db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql create mode 100644 modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js diff --git a/db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql b/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql similarity index 100% rename from db/versions/11065-yellowChrysanthemum/00-modifyPrivilegesInvoiceIn.sql rename to db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql diff --git a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql new file mode 100644 index 000000000..50a6735c7 --- /dev/null +++ b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql @@ -0,0 +1,22 @@ +UPDATE salix.ACL + SET accessType = 'READ' + WHERE principalId IN ('administrative','buyer') + AND model = 'invoiceIn' + AND property = '*'; + +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES + ('InvoiceIn', 'updateInvoiceIn', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'toUnbook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'updateInvoiceIn', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'toUnbook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js new file mode 100644 index 000000000..92a1ba8ee --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -0,0 +1,104 @@ +module.exports = Self => { + Self.remoteMethodCtx('updateInvoiceIn', { + description: 'To update the invoiceIn attributes', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The invoiceIn id', + http: {source: 'path'} + }, { + arg: 'supplierFk', + type: 'number', + required: true + }, { + arg: 'supplierRef', + type: 'any', + }, { + arg: 'issued', + type: 'any', + }, { + arg: 'operated', + type: 'any', + }, { + arg: 'deductibleExpenseFk', + type: 'any', + }, { + arg: 'dmsFk', + type: 'any', + }, { + arg: 'bookEntried', + type: 'any', + }, { + arg: 'booked', + type: 'any', + }, { + arg: 'currencyFk', + type: 'number', + required: true + }, { + arg: 'companyFk', + type: 'any', + }, { + arg: 'withholdingSageFk', + type: 'any', + }, + ], + returns: { + type: 'object', + root: true + }, + http: { + path: '/:id/updateInvoiceIn', + verb: 'PATCH' + } + }); + + Self.updateInvoiceIn = async(ctx, + id, + supplierFk, + supplierRef, + issued, + operated, + deductibleExpenseFk, + dmsFk, + bookEntried, + booked, + currencyFk, + companyFk, + withholdingSageFk, + options + ) => { + let tx; + const myOptions = {userId: ctx.req.accessToken.userId}; + + if (typeof options == 'object') Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const invoiceIn = await Self.findById(id, null, myOptions); + invoiceIn.updateAttributes({supplierFk, + supplierRef, + issued, + operated, + deductibleExpenseFk, + dmsFk, + bookEntried, + booked, + currencyFk, + companyFk, + withholdingSageFk + }, myOptions); + if (tx) await tx.commit(); + return invoiceIn; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 6f57b36f9..1e69c0ef8 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -12,6 +12,7 @@ module.exports = Self => { require('../methods/invoice-in/corrective')(Self); require('../methods/invoice-in/exchangeRateUpdate')(Self); require('../methods/invoice-in/toUnbook')(Self); + require('../methods/invoice-in/updateInvoiceIn')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn')) diff --git a/modules/invoiceIn/front/basic-data/index.html b/modules/invoiceIn/front/basic-data/index.html index a22abbb33..fbb9b05a2 100644 --- a/modules/invoiceIn/front/basic-data/index.html +++ b/modules/invoiceIn/front/basic-data/index.html @@ -1,4 +1,4 @@ - + Date: Mon, 27 May 2024 12:03:07 +0200 Subject: [PATCH 09/12] fix: refs #6942 drop quotes --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ddb3f783a..f82f84e59 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3107,7 +3107,7 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns (2,'123456N','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',69,3,4,2,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (3,'123456B','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',567,5,6,69,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'); -UPDATE `vn`.`department` +UPDATE vn.department SET workerFk = null; INSERT INTO vn.packaging From c136f2783ae0283bfb754b1e767bd876fd2b330c Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 27 May 2024 12:34:27 +0200 Subject: [PATCH 10/12] refactor: refs #6942 toUnbook & drop buyer acls --- .../01-modifyInvoiceInAcls.sql | 3 +-- modules/invoiceIn/back/methods/invoice-in/toUnbook.js | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql index 50a6735c7..86542de1a 100644 --- a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql +++ b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql @@ -18,5 +18,4 @@ VALUES ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), - ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), - ('InvoiceIn', 'toUnbook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); + ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); diff --git a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js index 617649488..a697e9ddc 100644 --- a/modules/invoiceIn/back/methods/invoice-in/toUnbook.js +++ b/modules/invoiceIn/back/methods/invoice-in/toUnbook.js @@ -47,10 +47,11 @@ module.exports = Self => { } }, myOptions); - if (bookEntry?.ASIEN) { - accountingEntries = await models.Xdiario.count({ASIEN: bookEntry.ASIEN}, myOptions); + let asien = bookEntry?.ASIEN; + if (asien) { + accountingEntries = await models.Xdiario.count({ASIEN: asien}, myOptions); - await models.Xdiario.destroyAll({ASIEN: bookEntry.ASIEN}, myOptions); + await models.Xdiario.destroyAll({ASIEN: asien}, myOptions); await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions); } else { const linkedBookEntry = await models.Xdiario.findOne({ @@ -61,14 +62,14 @@ module.exports = Self => { } }, myOptions); - bookEntry = linkedBookEntry?.ASIEN; + asien = linkedBookEntry?.ASIEN; isLinked = true; } if (tx) await tx.commit(); return { isLinked, - bookEntry: bookEntry?.ASIEN, + bookEntry: asien, accountingEntries }; } catch (e) { From 1671423d23b647d6fd8ed4942b67bb365397b261 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 27 May 2024 12:53:25 +0200 Subject: [PATCH 11/12] fix: refs #6942 add deleteById acl --- .../11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql index 86542de1a..5475b70ac 100644 --- a/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql +++ b/db/versions/11065-yellowChrysanthemum/01-modifyInvoiceInAcls.sql @@ -13,9 +13,11 @@ VALUES ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), ('InvoiceIn', 'toUnbook', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), ('InvoiceIn', 'updateInvoiceIn', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'corrective', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'exchangeRateUpdate', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), - ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); + ('InvoiceIn', 'toBook', 'WRITE', 'ALLOW', 'ROLE', 'buyer'), + ('InvoiceIn', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); From 1af24e847392823669e4251e95890dca49f0839f Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 27 May 2024 13:34:00 +0200 Subject: [PATCH 12/12] fix : refs #6942 remove grafana update priv --- .../00-modifyInvoiceInPrivileges.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql b/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql index 90acd1745..b65ca1c17 100644 --- a/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql +++ b/db/versions/11065-yellowChrysanthemum/00-modifyInvoiceInPrivileges.sql @@ -1,4 +1,4 @@ -REVOKE UPDATE ON vn. invoiceIn FROM administrative, hrBoss, buyer, logistic, grafana; +REVOKE UPDATE ON vn. invoiceIn FROM administrative, hrBoss, buyer, logistic; GRANT UPDATE (id, serialNumber, serial, @@ -21,4 +21,4 @@ GRANT UPDATE (id, withholdingSageFk, expenseFkDeductible, editorFk -) ON vn.invoiceIn TO administrative, hrBoss, buyer, logistic, grafana; \ No newline at end of file +) ON vn.invoiceIn TO administrative, hrBoss, buyer, logistic; \ No newline at end of file