mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 23:52:57 +00:00
feat: discount validity date in payment terms
This commit is contained in:
committed by
Deepesh Garg
parent
e2e2a305da
commit
09ef7b62a1
@@ -1337,7 +1337,7 @@ def apply_early_payment_discount(paid_amount, received_amount, doc):
|
|||||||
difference_amount = 0
|
difference_amount = 0
|
||||||
if doc.doctype in ["Sales Invoice", "Purchase Invoice"] and doc.payment_schedule:
|
if doc.doctype in ["Sales Invoice", "Purchase Invoice"] and doc.payment_schedule:
|
||||||
for term in 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 = term.payment_amount * (term.discount_percentage / 100)
|
||||||
discount_amount_in_foreign_currency = discount_amount * doc.get('conversion_rate', 1)
|
discount_amount_in_foreign_currency = discount_amount * doc.get('conversion_rate', 1)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"payment_term",
|
"payment_term",
|
||||||
"description",
|
"description",
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
|
"discount_validity",
|
||||||
"discounted_amount",
|
"discounted_amount",
|
||||||
"outstanding",
|
"outstanding",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
@@ -100,12 +101,20 @@
|
|||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Outstanding",
|
"label": "Outstanding",
|
||||||
"read_only": 1
|
"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,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-02-10 13:39:47.405252",
|
"modified": "2021-02-11 13:03:33.353333",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Schedule",
|
"name": "Payment Schedule",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"due_date_based_on",
|
"due_date_based_on",
|
||||||
"credit_days",
|
"credit_days",
|
||||||
"credit_months",
|
"credit_months",
|
||||||
|
"discount_validity",
|
||||||
"section_break_6",
|
"section_break_6",
|
||||||
"description"
|
"description"
|
||||||
],
|
],
|
||||||
@@ -77,10 +78,17 @@
|
|||||||
"fieldname": "discount_percentage",
|
"fieldname": "discount_percentage",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Discount (%)"
|
"label": "Discount (%)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "discount_percentage",
|
||||||
|
"fieldname": "discount_validity",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Discount Validity",
|
||||||
|
"mandatory_depends_on": "discount_percentage"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-02-08 12:41:38.215919",
|
"modified": "2021-02-11 13:04:03.192185",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Term",
|
"name": "Payment Term",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"payment_term",
|
"payment_term",
|
||||||
"description",
|
"description",
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
|
"discount_validity",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"invoice_portion",
|
"invoice_portion",
|
||||||
"due_date_based_on",
|
"due_date_based_on",
|
||||||
@@ -85,12 +86,18 @@
|
|||||||
"fieldname": "discount_percentage",
|
"fieldname": "discount_percentage",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Discount (%)"
|
"label": "Discount (%)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "payment_term.discount_validity",
|
||||||
|
"fieldname": "discount_validity",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Discount Validity"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-02-08 12:39:20.175580",
|
"modified": "2021-02-11 12:54:48.934368",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Terms Template Detail",
|
"name": "Payment Terms Template Detail",
|
||||||
|
|||||||
@@ -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.invoice_portion = term.invoice_portion
|
||||||
term_details.payment_amount = flt(term.invoice_portion) * flt(grand_total) / 100
|
term_details.payment_amount = flt(term.invoice_portion) * flt(grand_total) / 100
|
||||||
term_details.outstanding = term_details.payment_amount
|
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:
|
if bill_date:
|
||||||
term_details.due_date = get_due_date(term, bill_date)
|
term_details.due_date = get_due_date(term, bill_date)
|
||||||
elif posting_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):
|
if getdate(term_details.due_date) < getdate(posting_date):
|
||||||
term_details.due_date = 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
|
return term_details
|
||||||
|
|
||||||
|
|
||||||
def get_due_date(term, posting_date=None, bill_date=None):
|
def get_due_date(term, posting_date=None, bill_date=None):
|
||||||
due_date = None
|
due_date = None
|
||||||
date = bill_date or posting_date
|
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)
|
due_date = add_months(get_last_day(date), term.credit_months)
|
||||||
return due_date
|
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):
|
def get_supplier_block_status(party_name):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user