mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-26 14:41:42 +01:00
fix: Payment Term must be mandatory if Allocate Payment based on .. is checked (#35798)
fix: Payment Term must be mandatory if `Allocate Payment based on ..` is checked (#35798)
- Front and Back end validation of condition
- Fix test to accomodate fix
(cherry picked from commit 2868baebab)
Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
@@ -2,7 +2,11 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Payment Terms Template', {
|
frappe.ui.form.on('Payment Terms Template', {
|
||||||
setup: function(frm) {
|
refresh: function(frm) {
|
||||||
|
frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms);
|
||||||
|
},
|
||||||
|
|
||||||
|
allocate_payment_based_on_payment_terms: function(frm) {
|
||||||
|
frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from frappe.utils import flt
|
|||||||
class PaymentTermsTemplate(Document):
|
class PaymentTermsTemplate(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_invoice_portion()
|
self.validate_invoice_portion()
|
||||||
self.check_duplicate_terms()
|
self.validate_terms()
|
||||||
|
|
||||||
def validate_invoice_portion(self):
|
def validate_invoice_portion(self):
|
||||||
total_portion = 0
|
total_portion = 0
|
||||||
@@ -23,9 +23,12 @@ class PaymentTermsTemplate(Document):
|
|||||||
_("Combined invoice portion must equal 100%"), raise_exception=1, indicator="red"
|
_("Combined invoice portion must equal 100%"), raise_exception=1, indicator="red"
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_duplicate_terms(self):
|
def validate_terms(self):
|
||||||
terms = []
|
terms = []
|
||||||
for term in self.terms:
|
for term in self.terms:
|
||||||
|
if self.allocate_payment_based_on_payment_terms and not term.payment_term:
|
||||||
|
frappe.throw(_("Row {0}: Payment Term is mandatory").format(term.idx))
|
||||||
|
|
||||||
term_info = (term.payment_term, term.credit_days, term.credit_months, term.due_date_based_on)
|
term_info = (term.payment_term, term.credit_days, term.credit_months, term.due_date_based_on)
|
||||||
if term_info in terms:
|
if term_info in terms:
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
|
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
|
||||||
|
|
||||||
def test_make_purchase_invoice(self):
|
def test_make_purchase_invoice(self):
|
||||||
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_term
|
||||||
|
|
||||||
|
create_payment_term("_Test Payment Term 1 for Purchase Invoice")
|
||||||
|
create_payment_term("_Test Payment Term 2 for Purchase Invoice")
|
||||||
|
|
||||||
if not frappe.db.exists(
|
if not frappe.db.exists(
|
||||||
"Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice"
|
"Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice"
|
||||||
):
|
):
|
||||||
@@ -74,12 +79,14 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
"terms": [
|
"terms": [
|
||||||
{
|
{
|
||||||
"doctype": "Payment Terms Template Detail",
|
"doctype": "Payment Terms Template Detail",
|
||||||
|
"payment_term": "_Test Payment Term 1 for Purchase Invoice",
|
||||||
"invoice_portion": 50.00,
|
"invoice_portion": 50.00,
|
||||||
"credit_days_based_on": "Day(s) after invoice date",
|
"credit_days_based_on": "Day(s) after invoice date",
|
||||||
"credit_days": 00,
|
"credit_days": 00,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Payment Terms Template Detail",
|
"doctype": "Payment Terms Template Detail",
|
||||||
|
"payment_term": "_Test Payment Term 2 for Purchase Invoice",
|
||||||
"invoice_portion": 50.00,
|
"invoice_portion": 50.00,
|
||||||
"credit_days_based_on": "Day(s) after invoice date",
|
"credit_days_based_on": "Day(s) after invoice date",
|
||||||
"credit_days": 30,
|
"credit_days": 30,
|
||||||
|
|||||||
Reference in New Issue
Block a user