Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Payment Term must be mandatory if Allocate Payment based on .. is checked #35798

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading