feat: refs #7936 add save validation
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
c270ec3723
commit
1f6e401e39
|
@ -52,7 +52,8 @@ module.exports = Self => {
|
||||||
accountingEntries = await models.Xdiario.count({ASIEN: asien}, myOptions);
|
accountingEntries = await models.Xdiario.count({ASIEN: asien}, myOptions);
|
||||||
|
|
||||||
await models.Xdiario.destroyAll({ASIEN: asien}, myOptions);
|
await models.Xdiario.destroyAll({ASIEN: asien}, myOptions);
|
||||||
await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions);
|
const invoiceIn = await Self.findById(invoiceInId, myOptions);
|
||||||
|
await invoiceIn.updateAttribute('isBooked', false, myOptions);
|
||||||
} else {
|
} else {
|
||||||
const linkedBookEntry = await models.Xdiario.findOne({
|
const linkedBookEntry = await models.Xdiario.findOne({
|
||||||
fields: ['ASIEN'],
|
fields: ['ASIEN'],
|
||||||
|
|
|
@ -82,7 +82,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invoiceIn = await Self.findById(id, null, myOptions);
|
const invoiceIn = await Self.findById(id, null, myOptions);
|
||||||
invoiceIn.updateAttributes({supplierFk,
|
await invoiceIn.updateAttributes({supplierFk,
|
||||||
supplierRef,
|
supplierRef,
|
||||||
issued,
|
issued,
|
||||||
operated,
|
operated,
|
||||||
|
@ -94,6 +94,7 @@ module.exports = Self => {
|
||||||
companyFk,
|
companyFk,
|
||||||
withholdingSageFk
|
withholdingSageFk
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
return invoiceIn;
|
return invoiceIn;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -19,4 +19,19 @@ module.exports = Self => {
|
||||||
return new UserError(`This invoice has a linked vehicle.`);
|
return new UserError(`This invoice has a linked vehicle.`);
|
||||||
return err;
|
return err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Self.observe('before save', async function(ctx) {
|
||||||
|
if (ctx.newInstance) return;
|
||||||
|
|
||||||
|
const changes = ctx.data || ctx.instance;
|
||||||
|
const orgData = ctx.currentInstance;
|
||||||
|
let isNotEditable = orgData.isBooked || (!orgData.isBooked && changes.isBooked);
|
||||||
|
|
||||||
|
if (isNotEditable) {
|
||||||
|
for (const [key, value] of Object.entries(changes)) {
|
||||||
|
if (key !== 'isBooked' && value !== orgData[key])
|
||||||
|
throw new UserError('InvoiceIn is already booked');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue