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

Merge pull request #19 from piyushsinghania/fix/error-message-not-displayed-while-paying-excess-amount

Added validation to give error message when trying to pay excess amount for an invoice
This commit is contained in:
Ankit Singhaniya 2021-10-30 20:03:27 +05:30 committed by GitHub
commit 49fc8d5586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
const frappe = require('frappejs');
const utils = require('../../../accounting/utils');
module.exports = {
@ -102,7 +103,17 @@ module.exports = {
label: 'Amount',
fieldtype: 'Currency',
required: 1,
formula: doc => doc.getSum('for', 'amount')
formula: doc => doc.getSum('for', 'amount'),
validate(value, doc) {
const amount = doc.getSum('for', 'amount');
const isValid = amount >= value && value > 0;
if (!isValid) {
throw new frappe.errors.ValidationError(
`Payment amount ${value} cannot be accepted. Please enter a value between 0 and ${amount}`
);
}
}
},
{
fieldname: 'writeoff',