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

Merge pull request #230 from ankitsinghaniyaz/master

Add validation when paying excess amount
This commit is contained in:
Alan 2021-11-02 11:53:40 +05:30 committed by GitHub
commit 99b24d472e
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,27 @@ 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');
if (value > amount) {
throw new frappe.errors.ValidationError(
frappe._(
`Payment amount cannot exceed ${frappe.format(
amount,
'Currency'
)}. Amount has been reset to max viable amount.`
)
);
} else if (value === 0) {
throw new frappe.errors.ValidationError(
frappe._(
`Payment amount cannot be ${frappe.format(value, 'Currency')}. Amount has been reset to max viable amount.`
)
);
}
}
},
{
fieldname: 'writeoff',