Multiple fixes related to payment terms (#12115)
This commit is contained in:
@@ -64,16 +64,14 @@ class AccountsController(TransactionBase):
|
||||
def validate_invoice_documents_schedule(self):
|
||||
self.validate_payment_schedule_dates()
|
||||
self.set_due_date()
|
||||
self.validate_invoice_portion()
|
||||
self.set_payment_schedule()
|
||||
self.validate_payment_schedule_amount()
|
||||
self.validate_due_date()
|
||||
self.validate_advance_entries()
|
||||
|
||||
def validate_non_invoice_documents_schedule(self):
|
||||
self.validate_payment_schedule_dates()
|
||||
self.validate_invoice_portion()
|
||||
self.set_payment_schedule()
|
||||
self.validate_payment_schedule_dates()
|
||||
self.validate_payment_schedule_amount()
|
||||
|
||||
def validate_all_documents_schedule(self):
|
||||
@@ -652,6 +650,8 @@ class AccountsController(TransactionBase):
|
||||
date = self.get("due_date")
|
||||
due_date = date or posting_date
|
||||
grand_total = self.get("rounded_total") or self.grand_total
|
||||
if self.doctype in ("Sales Invoice", "Purchase Invoice"):
|
||||
grand_total = grand_total - flt(self.write_off_amount)
|
||||
|
||||
if not self.get("payment_schedule"):
|
||||
if self.get("payment_terms_template"):
|
||||
@@ -663,7 +663,8 @@ class AccountsController(TransactionBase):
|
||||
self.append("payment_schedule", data)
|
||||
else:
|
||||
for d in self.get("payment_schedule"):
|
||||
d.payment_amount = grand_total * flt(d.invoice_portion) / 100
|
||||
if d.invoice_portion:
|
||||
d.payment_amount = grand_total * flt(d.invoice_portion) / 100
|
||||
|
||||
def set_due_date(self):
|
||||
due_dates = [d.due_date for d in self.get("payment_schedule") if d.due_date]
|
||||
@@ -673,12 +674,9 @@ class AccountsController(TransactionBase):
|
||||
def validate_payment_schedule_dates(self):
|
||||
dates = []
|
||||
li = []
|
||||
if self.get('posting_date'):
|
||||
if self.due_date and getdate(self.due_date) < getdate(self.posting_date):
|
||||
frappe.throw(_("Due Date cannot be before posting date"))
|
||||
|
||||
for d in self.get("payment_schedule"):
|
||||
if self.get('posting_date') and getdate(d.due_date) < getdate(self.posting_date):
|
||||
if self.doctype == "Sales Order" and getdate(d.due_date) < getdate(self.transaction_date):
|
||||
frappe.throw(_("Row {0}: Due Date cannot be before posting date").format(d.idx))
|
||||
elif d.due_date in dates:
|
||||
li.append('{0} in row {1}'.format(d.due_date, d.idx))
|
||||
@@ -700,15 +698,6 @@ class AccountsController(TransactionBase):
|
||||
if total != grand_total:
|
||||
frappe.throw(_("Total Payment Amount in Payment Schedule must be equal to Grand / Rounded Total"))
|
||||
|
||||
def validate_invoice_portion(self):
|
||||
if self.get("payment_schedule"):
|
||||
total_portion = 0
|
||||
for term in self.payment_schedule:
|
||||
total_portion += flt(term.get('invoice_portion', 0))
|
||||
|
||||
if flt(total_portion, 2) != 100.00:
|
||||
frappe.msgprint(_('Combined invoice portion must equal 100%'), indicator='red', raise_exception=1)
|
||||
|
||||
def is_rounded_total_disabled(self):
|
||||
if self.meta.get_field("disable_rounded_total"):
|
||||
return self.disable_rounded_total
|
||||
|
||||
Reference in New Issue
Block a user