Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion models/doctype/Payment/Payment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const frappe = require('frappejs');
const utils = require('../../../accounting/utils');

module.exports = {
Expand Down Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let isValid = amount >= value && value > 0 ? true : false;
const isValid = amount >= value && value > 0

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also lean on using const unless you can't. Then use let


if (!isValid) {
throw new frappe.errors.ValidationError(`Invalid amount ${value}`);
Copy link
Owner

@ankitsinghaniyaz ankitsinghaniyaz Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new frappe.errors.ValidationError(`Invalid amount ${value}`);
throw new frappe.errors.ValidationError(`Payment amount ${value} cannot be accepted. Please enter a value between 0 and ${amount}`);

}
}
},
{
fieldname: 'writeoff',
Expand Down