From 9ece52c5cecf15fa6d7350999f27cc3dd68d1b71 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 29 Nov 2024 12:42:15 +0100 Subject: [PATCH] feat: refs #7936 add currency check to updateInvoiceIn --- .../back/methods/invoice-in/updateInvoiceIn.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js index 2f1b4caca..2b059f07b 100644 --- a/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js +++ b/modules/invoiceIn/back/methods/invoice-in/updateInvoiceIn.js @@ -72,6 +72,7 @@ module.exports = Self => { ) => { let tx; const myOptions = {userId: ctx.req.accessToken.userId}; + const models = Self.app.models; if (typeof options == 'object') Object.assign(myOptions, options); @@ -95,6 +96,17 @@ module.exports = Self => { withholdingSageFk }, myOptions); + if (currencyFk) { + const currency = await models.Currency.findById(currencyFk, null, myOptions); + if (currency.code === 'EUR') { + const invoiceInTaxes = await models.InvoiceInTax.find( + {where: {invoiceInFk: id}}, myOptions); + + for (const invoiceInTax of invoiceInTaxes) + await invoiceInTax.updateAttribute('foreignValue', null, myOptions); + } + } + if (tx) await tx.commit(); return invoiceIn; } catch (e) {