Skip to content

Commit

Permalink
fix: Payment Term must be mandatory if Allocate Payment based on ..
Browse files Browse the repository at this point in the history
… is checked

- Front and Back end validation of condition
- Fix test to accomodate fix
  • Loading branch information
marination committed Jun 20, 2023
1 parent 4fbff20 commit a73a9e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// For license information, please see license.txt

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);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PaymentTermsTemplate(Document):
def validate(self):
self.validate_invoice_portion()
self.check_duplicate_terms()
self.validate_terms()

def validate_invoice_portion(self):
total_portion = 0
Expand All @@ -23,9 +23,12 @@ def validate_invoice_portion(self):
_("Combined invoice portion must equal 100%"), raise_exception=1, indicator="red"
)

def check_duplicate_terms(self):
def validate_terms(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)
if term_info in terms:
frappe.msgprint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def test_reverse_purchase_receipt_sle(self):
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)

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(
"Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice"
):
Expand All @@ -83,12 +88,14 @@ def test_make_purchase_invoice(self):
"terms": [
{
"doctype": "Payment Terms Template Detail",
"payment_term": "_Test Payment Term 1 for Purchase Invoice",
"invoice_portion": 50.00,
"credit_days_based_on": "Day(s) after invoice date",
"credit_days": 00,
},
{
"doctype": "Payment Terms Template Detail",
"payment_term": "_Test Payment Term 2 for Purchase Invoice",
"invoice_portion": 50.00,
"credit_days_based_on": "Day(s) after invoice date",
"credit_days": 30,
Expand Down

0 comments on commit a73a9e1

Please sign in to comment.