19 lines
758 B
JavaScript
19 lines
758 B
JavaScript
|
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');
|
||
|
});
|
||
|
};
|