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

Conversation

piyushsinghania
Copy link

@ankitsinghaniyaz added validation to give an error message when trying to pay the excess amount for an invoice or a negative 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

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

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}`);

@piyushsinghania
Copy link
Author

@ankitsinghaniyaz updated as per the suggested changes.

@ankitsinghaniyaz ankitsinghaniyaz merged commit 49fc8d5 into ankitsinghaniyaz:master Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants