feat: discount validity date in payment terms

This commit is contained in:
Saqib Ansari
2021-02-11 13:04:43 +05:30
committed by Deepesh Garg
parent e2e2a305da
commit 09ef7b62a1
5 changed files with 43 additions and 7 deletions

View File

@@ -1337,7 +1337,7 @@ def apply_early_payment_discount(paid_amount, received_amount, doc):
difference_amount = 0
if doc.doctype in ["Sales Invoice", "Purchase Invoice"] and doc.payment_schedule:
for term in doc.payment_schedule:
if not term.discounted_amount and term.discount_percentage and getdate(nowdate()) <= term.due_date:
if not term.discounted_amount and term.discount_percentage and getdate(nowdate()) <= term.discount_validity:
discount_amount = term.payment_amount * (term.discount_percentage / 100)
discount_amount_in_foreign_currency = discount_amount * doc.get('conversion_rate', 1)

View File

@@ -8,6 +8,7 @@
"payment_term",
"description",
"discount_percentage",
"discount_validity",
"discounted_amount",
"outstanding",
"column_break_3",
@@ -100,12 +101,20 @@
"fieldtype": "Currency",
"label": "Outstanding",
"read_only": 1
},
{
"depends_on": "discount_percentage",
"fetch_from": "payment_term.discount_validity",
"fieldname": "discount_validity",
"fieldtype": "Date",
"label": "Discount Validity",
"mandatory_depends_on": "discount_percentage"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-02-10 13:39:47.405252",
"modified": "2021-02-11 13:03:33.353333",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Schedule",

View File

@@ -16,6 +16,7 @@
"due_date_based_on",
"credit_days",
"credit_months",
"discount_validity",
"section_break_6",
"description"
],
@@ -77,10 +78,17 @@
"fieldname": "discount_percentage",
"fieldtype": "Float",
"label": "Discount (%)"
},
{
"depends_on": "discount_percentage",
"fieldname": "discount_validity",
"fieldtype": "Int",
"label": "Discount Validity",
"mandatory_depends_on": "discount_percentage"
}
],
"links": [],
"modified": "2021-02-08 12:41:38.215919",
"modified": "2021-02-11 13:04:03.192185",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Term",

View File

@@ -8,6 +8,7 @@
"payment_term",
"description",
"discount_percentage",
"discount_validity",
"column_break_3",
"invoice_portion",
"due_date_based_on",
@@ -85,12 +86,18 @@
"fieldname": "discount_percentage",
"fieldtype": "Float",
"label": "Discount (%)"
},
{
"fetch_from": "payment_term.discount_validity",
"fieldname": "discount_validity",
"fieldtype": "Int",
"label": "Discount Validity"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-02-08 12:39:20.175580",
"modified": "2021-02-11 12:54:48.934368",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Terms Template Detail",

View File

@@ -1233,6 +1233,14 @@ def get_payment_term_details(term, posting_date=None, grand_total=None, base_gra
term_details.invoice_portion = term.invoice_portion
term_details.payment_amount = flt(term.invoice_portion) * flt(grand_total) / 100
term_details.outstanding = term_details.payment_amount
term_details.mode_of_payment = term.mode_of_payment
term_details.discount_percentage = term.discount_percentage
if term.discount_percentage:
term_details.discount_validity = get_discount_date(term, bill_date or posting_date)
print(term_details.discount_validity)
if bill_date:
term_details.due_date = get_due_date(term, bill_date)
elif posting_date:
@@ -1240,12 +1248,9 @@ def get_payment_term_details(term, posting_date=None, grand_total=None, base_gra
if getdate(term_details.due_date) < getdate(posting_date):
term_details.due_date = posting_date
term_details.mode_of_payment = term.mode_of_payment
term_details.discount_percentage = term.discount_percentage
return term_details
def get_due_date(term, posting_date=None, bill_date=None):
due_date = None
date = bill_date or posting_date
@@ -1257,6 +1262,13 @@ def get_due_date(term, posting_date=None, bill_date=None):
due_date = add_months(get_last_day(date), term.credit_months)
return due_date
def get_discount_date(term, date):
discount_date = None
if term.due_date_based_on == "Day(s) after invoice date":
discount_date = add_days(date, term.discount_validity)
elif term.due_date_based_on == "Day(s) after the end of the invoice month":
discount_date = add_days(get_last_day(date), term.discount_validity)
return discount_date
def get_supplier_block_status(party_name):
"""