diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py index d2344d6c77b..363484d9b1a 100644 --- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py +++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py @@ -3,8 +3,28 @@ # For license information, please see license.txt from __future__ import unicode_literals + +import frappe from frappe.model.document import Document +from frappe.utils import flt +from frappe import _ class PaymentTermsTemplate(Document): - pass + def validate(self): + self.validate_invoice_portion() + self.validate_credit_days() + + def validate_invoice_portion(self): + total_portion = 0 + for term in self.terms: + total_portion += term.invoice_portion + + if flt(total_portion, 2) != 100.00: + frappe.msgprint(_('Combined invoice portion must equal 100%'), raise_exception=1, indicator='red') + + def validate_credit_days(self): + for term in self.terms: + if term.credit_days < 0: + frappe.msgprint(_('Credit Days cannot be a negative number'), raise_exception=1, indicator='red') + diff --git a/erpnext/docs/user/manual/en/accounts/payment-terms.md b/erpnext/docs/user/manual/en/accounts/payment-terms.md new file mode 100644 index 00000000000..e69de29bb2d