2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

Added validation to give error message when trying to pay excess amount for an invoice

This commit is contained in:
Piyush Singhania 2021-10-29 18:26:45 +05:30
parent ca0c2968e0
commit 102ef29d6b

View File

@ -1,3 +1,4 @@
const frappe = require('frappejs');
const utils = require('../../../accounting/utils');
module.exports = {
@ -102,7 +103,15 @@ module.exports = {
label: 'Amount',
fieldtype: 'Currency',
required: 1,
formula: doc => doc.getSum('for', 'amount')
formula: doc => doc.getSum('for', 'amount'),
validate(value, doc) {
let amount = doc.getSum('for', 'amount');
let isValid = amount >= value && value > 0 ? true : false;
if (!isValid) {
throw new frappe.errors.ValidationError(`Invalid amount ${value}`);
}
}
},
{
fieldname: 'writeoff',