From 4fcb54ff7c1da402f493142d198f201634174898 Mon Sep 17 00:00:00 2001 From: Piyush Singhania Date: Mon, 1 Nov 2021 19:36:02 +0530 Subject: [PATCH 1/3] Added translation support and currency symbol in the error message --- models/doctype/Payment/Payment.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/models/doctype/Payment/Payment.js b/models/doctype/Payment/Payment.js index a92ea9bd..fd89e2f8 100644 --- a/models/doctype/Payment/Payment.js +++ b/models/doctype/Payment/Payment.js @@ -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')}` + ) ); } } From 093a29785687d444ce65fb47f62b7cc5ccc20ca7 Mon Sep 17 00:00:00 2001 From: Ankit Singhaniya Date: Mon, 1 Nov 2021 23:08:08 +0530 Subject: [PATCH 2/3] simplify the condition to check if value is larger then max amount --- models/doctype/Payment/Payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/doctype/Payment/Payment.js b/models/doctype/Payment/Payment.js index fd89e2f8..bd934ece 100644 --- a/models/doctype/Payment/Payment.js +++ b/models/doctype/Payment/Payment.js @@ -107,7 +107,7 @@ module.exports = { validate(value, doc) { const amount = doc.getSum('for', 'amount'); - if (!(amount >= value)) { + if (value > amount)) { throw new frappe.errors.ValidationError( frappe._( `Payment amount cannot exceed ${frappe.format( From 59c57c289b6297754e13dbe06f8abfb43bee2017 Mon Sep 17 00:00:00 2001 From: Ankit Singhaniya Date: Mon, 1 Nov 2021 23:09:31 +0530 Subject: [PATCH 3/3] improve message when trying to pay 0 --- models/doctype/Payment/Payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/doctype/Payment/Payment.js b/models/doctype/Payment/Payment.js index bd934ece..4528957b 100644 --- a/models/doctype/Payment/Payment.js +++ b/models/doctype/Payment/Payment.js @@ -119,7 +119,7 @@ module.exports = { } else if (value === 0) { throw new frappe.errors.ValidationError( frappe._( - `Payment amount cannot be ${frappe.format(value, 'Currency')}` + `Payment amount cannot be ${frappe.format(value, 'Currency')}. Amount has been reset to max viable amount.` ) ); }