Calculate due date in Purchase Invoice on the basis of Supplier invoice date (#12913)
* pass bill_date as parameter and calculate due_date on that basis * calculate payment_schedule on the basis of bill_date if present else posting_date * add bill_date as an argument to get_party_details * pass bill_date on supplier trigger in purchase invoice
This commit is contained in:
@@ -137,7 +137,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
validate_due_date(self.posting_date, self.due_date, "Customer", self.customer, self.company)
|
||||
elif self.doctype == "Purchase Invoice":
|
||||
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company)
|
||||
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company, self.bill_date)
|
||||
|
||||
def set_price_list_currency(self, buying_or_selling):
|
||||
if self.meta.get_field("posting_date"):
|
||||
@@ -908,7 +908,7 @@ def update_invoice_status():
|
||||
where due_date < CURDATE() and docstatus = 1 and outstanding_amount > 0""")
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_terms(terms_template, posting_date=None, grand_total=None):
|
||||
def get_payment_terms(terms_template, posting_date=None, grand_total=None, bill_date=None):
|
||||
if not terms_template:
|
||||
return
|
||||
|
||||
@@ -916,13 +916,13 @@ def get_payment_terms(terms_template, posting_date=None, grand_total=None):
|
||||
|
||||
schedule = []
|
||||
for d in terms_doc.get("terms"):
|
||||
term_details = get_payment_term_details(d, posting_date, grand_total)
|
||||
term_details = get_payment_term_details(d, posting_date, grand_total, bill_date)
|
||||
schedule.append(term_details)
|
||||
|
||||
return schedule
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_term_details(term, posting_date=None, grand_total=None):
|
||||
def get_payment_term_details(term, posting_date=None, grand_total=None, bill_date=None):
|
||||
term_details = frappe._dict()
|
||||
if isinstance(term, unicode):
|
||||
term = frappe.get_doc("Payment Term", term)
|
||||
@@ -931,17 +931,23 @@ def get_payment_term_details(term, posting_date=None, grand_total=None):
|
||||
term_details.description = term.description
|
||||
term_details.invoice_portion = term.invoice_portion
|
||||
term_details.payment_amount = flt(term.invoice_portion) * flt(grand_total) / 100
|
||||
if posting_date:
|
||||
term_details.due_date = get_due_date(posting_date, term)
|
||||
if bill_date:
|
||||
term_details.due_date = get_due_date(term, bill_date)
|
||||
elif posting_date:
|
||||
term_details.due_date = get_due_date(term, posting_date)
|
||||
|
||||
if getdate(term_details.due_date) < getdate(posting_date):
|
||||
term_details.due_date = posting_date
|
||||
|
||||
return term_details
|
||||
|
||||
def get_due_date(posting_date, term):
|
||||
def get_due_date(term, posting_date=None, bill_date=None):
|
||||
due_date = None
|
||||
date = bill_date or posting_date
|
||||
if term.due_date_based_on == "Day(s) after invoice date":
|
||||
due_date = add_days(posting_date, term.credit_days)
|
||||
due_date = add_days(date, term.credit_days)
|
||||
elif term.due_date_based_on == "Day(s) after the end of the invoice month":
|
||||
due_date = add_days(get_last_day(posting_date), term.credit_days)
|
||||
due_date = add_days(get_last_day(date), term.credit_days)
|
||||
elif term.due_date_based_on == "Month(s) after the end of the invoice month":
|
||||
due_date = add_months(get_last_day(posting_date), term.credit_months)
|
||||
|
||||
due_date = add_months(get_last_day(date), term.credit_months)
|
||||
return due_date
|
||||
|
||||
Reference in New Issue
Block a user