2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +00:00

Added translation support and currency symbol in the error message

This commit is contained in:
Piyush Singhania 2021-11-01 19:36:02 +05:30
parent 6178cf55c0
commit 4fcb54ff7c

View File

@ -106,11 +106,21 @@ module.exports = {
formula: doc => doc.getSum('for', 'amount'),
validate(value, doc) {
const amount = doc.getSum('for', 'amount');
const isValid = amount >= value && value > 0;
if (!isValid) {
if (!(amount >= value)) {
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')}`
)
);
}
}