From 102ef29d6ba62a36cd9d8d83390312ec5360b13d Mon Sep 17 00:00:00 2001 From: Piyush Singhania Date: Fri, 29 Oct 2021 18:26:45 +0530 Subject: [PATCH] Added validation to give error message when trying to pay excess amount for an invoice --- models/doctype/Payment/Payment.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/models/doctype/Payment/Payment.js b/models/doctype/Payment/Payment.js index c61318da..76240afa 100644 --- a/models/doctype/Payment/Payment.js +++ b/models/doctype/Payment/Payment.js @@ -1,3 +1,4 @@ +const frappe = require('frappejs'); const utils = require('../../../accounting/utils'); module.exports = { @@ -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; + + if (!isValid) { + throw new frappe.errors.ValidationError(`Invalid amount ${value}`); + } + } }, { fieldname: 'writeoff',