feat: refs #7936 add validation to InvoiceIn & InvoiceInTax
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-11-29 12:22:01 +01:00
parent 1f6e401e39
commit 332e1c62d9
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,18 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.observe('before save', async function(ctx) {
if (ctx.newInstance) return;
const models = Self.app.models;
const invoiceIn = await models.InvoiceIn.findById(ctx.currentInstance.invoiceInFk);
if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked');
});
Self.observe('before delete', async function(ctx) {
const models = Self.app.models;
const invoiceInTax = await models.InvoiceInTax.findById(ctx.where.id);
const invoiceIn = await models.InvoiceIn.findById(invoiceInTax.invoiceInFk);
if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked');
});
};

View File

@ -34,4 +34,10 @@ module.exports = Self => {
}
}
});
Self.observe('before delete', async function(ctx) {
const invoiceIn = await Self.findById(ctx.where.id);
if (invoiceIn.isBooked) throw new UserError('InvoiceIn is already booked');
});
};