2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

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

Added translation support and currency symbol in the error message
This commit is contained in:
Ankit Singhaniya 2021-11-01 23:10:21 +05:30 committed by GitHub
commit 95e1510682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,11 +106,21 @@ module.exports = {
formula: doc => doc.getSum('for', 'amount'), formula: doc => doc.getSum('for', 'amount'),
validate(value, doc) { validate(value, doc) {
const amount = doc.getSum('for', 'amount'); const amount = doc.getSum('for', 'amount');
const isValid = amount >= value && value > 0;
if (!isValid) { if (value > amount)) {
throw new frappe.errors.ValidationError( throw new frappe.errors.ValidationError(
`Payment amount ${value} cannot be accepted. Please enter a value between 0 and ${amount}` 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.`
)
); );
} }
} }