mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
refactor: remove discount validity date
This commit is contained in:
committed by
Deepesh Garg
parent
09ef7b62a1
commit
153323ee41
@@ -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.discount_validity:
|
if not term.discounted_amount and term.discount_percentage and getdate(nowdate()) <= term.due_date:
|
||||||
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)
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,10 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"payment_term",
|
"payment_term",
|
||||||
"description",
|
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
"discount_validity",
|
|
||||||
"discounted_amount",
|
"discounted_amount",
|
||||||
"outstanding",
|
"outstanding",
|
||||||
|
"description",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"due_date",
|
"due_date",
|
||||||
"invoice_portion",
|
"invoice_portion",
|
||||||
@@ -101,20 +100,12 @@
|
|||||||
"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-11 13:03:33.353333",
|
"modified": "2021-02-11 20:11:42.058393",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Schedule",
|
"name": "Payment Schedule",
|
||||||
|
|||||||
@@ -10,13 +10,12 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"payment_term_name",
|
"payment_term_name",
|
||||||
"invoice_portion",
|
"invoice_portion",
|
||||||
"mode_of_payment",
|
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"due_date_based_on",
|
"due_date_based_on",
|
||||||
"credit_days",
|
"credit_days",
|
||||||
"credit_months",
|
"credit_months",
|
||||||
"discount_validity",
|
"mode_of_payment",
|
||||||
"section_break_6",
|
"section_break_6",
|
||||||
"description"
|
"description"
|
||||||
],
|
],
|
||||||
@@ -78,17 +77,10 @@
|
|||||||
"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-11 13:04:03.192185",
|
"modified": "2021-02-11 20:09:42.559344",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Term",
|
"name": "Payment Term",
|
||||||
|
|||||||
@@ -12,23 +12,8 @@ from frappe import _
|
|||||||
|
|
||||||
class PaymentTermsTemplate(Document):
|
class PaymentTermsTemplate(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_invoice_portion()
|
|
||||||
self.validate_credit_days()
|
|
||||||
self.check_duplicate_terms()
|
self.check_duplicate_terms()
|
||||||
|
|
||||||
def validate_invoice_portion(self):
|
|
||||||
total_portion = 0
|
|
||||||
for term in self.terms:
|
|
||||||
total_portion += flt(term.get('invoice_portion', 0))
|
|
||||||
|
|
||||||
if flt(total_portion, 2) != 100.00:
|
|
||||||
frappe.msgprint(_('Combined invoice portion must equal 100%'), raise_exception=1, indicator='red')
|
|
||||||
|
|
||||||
def validate_credit_days(self):
|
|
||||||
for term in self.terms:
|
|
||||||
if cint(term.credit_days) < 0:
|
|
||||||
frappe.msgprint(_('Credit Days cannot be a negative number'), raise_exception=1, indicator='red')
|
|
||||||
|
|
||||||
def check_duplicate_terms(self):
|
def check_duplicate_terms(self):
|
||||||
terms = []
|
terms = []
|
||||||
for term in self.terms:
|
for term in self.terms:
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"payment_term",
|
"payment_term",
|
||||||
"description",
|
|
||||||
"discount_percentage",
|
"discount_percentage",
|
||||||
"discount_validity",
|
"description",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"invoice_portion",
|
"invoice_portion",
|
||||||
"due_date_based_on",
|
"due_date_based_on",
|
||||||
@@ -23,7 +22,8 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Payment Term",
|
"label": "Payment Term",
|
||||||
"options": "Payment Term"
|
"options": "Payment Term",
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"columns": 2,
|
"columns": 2,
|
||||||
@@ -60,7 +60,8 @@
|
|||||||
"fieldname": "credit_days",
|
"fieldname": "credit_days",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Credit Days"
|
"label": "Credit Days",
|
||||||
|
"non_negative": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
@@ -68,7 +69,8 @@
|
|||||||
"fetch_from": "payment_term.credit_months",
|
"fetch_from": "payment_term.credit_months",
|
||||||
"fieldname": "credit_months",
|
"fieldname": "credit_months",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Credit Months"
|
"label": "Credit Months",
|
||||||
|
"non_negative": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fetch_from": "payment_term.mode_of_payment",
|
"fetch_from": "payment_term.mode_of_payment",
|
||||||
@@ -86,18 +88,12 @@
|
|||||||
"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-11 12:54:48.934368",
|
"modified": "2021-02-11 20:10:29.233745",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Terms Template Detail",
|
"name": "Payment Terms Template Detail",
|
||||||
|
|||||||
@@ -910,7 +910,8 @@ class AccountsController(TransactionBase):
|
|||||||
else:
|
else:
|
||||||
for d in self.get("payment_schedule"):
|
for d in self.get("payment_schedule"):
|
||||||
if d.invoice_portion:
|
if d.invoice_portion:
|
||||||
d.payment_amount = flt(grand_total * flt(d.invoice_portion) / 100, d.precision('payment_amount'))
|
d.payment_amount = flt(grand_total * flt(d.invoice_portion / 100), d.precision('payment_amount'))
|
||||||
|
d.discounted_amount = flt(d.payment_amount * flt(d.discount_percentage / 100), d.precision('payment_amount'))
|
||||||
d.outstanding = d.payment_amount
|
d.outstanding = d.payment_amount
|
||||||
|
|
||||||
def set_due_date(self):
|
def set_due_date(self):
|
||||||
@@ -949,8 +950,7 @@ class AccountsController(TransactionBase):
|
|||||||
total = 0
|
total = 0
|
||||||
base_total = 0
|
base_total = 0
|
||||||
for d in self.get("payment_schedule"):
|
for d in self.get("payment_schedule"):
|
||||||
total += flt(d.payment_amount)
|
total += flt(d.payment_amount) if not d.discount_percentage else 0
|
||||||
base_total += flt(d.base_payment_amount)
|
|
||||||
|
|
||||||
base_grand_total = self.get("base_rounded_total") or self.base_grand_total
|
base_grand_total = self.get("base_rounded_total") or self.base_grand_total
|
||||||
grand_total = self.get("rounded_total") or self.grand_total
|
grand_total = self.get("rounded_total") or self.grand_total
|
||||||
@@ -1232,15 +1232,12 @@ def get_payment_term_details(term, posting_date=None, grand_total=None, base_gra
|
|||||||
term_details.description = term.description
|
term_details.description = term.description
|
||||||
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.discounted_amount = term_details.payment_amount * (term.discount_percentage / 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.mode_of_payment = term.mode_of_payment
|
||||||
term_details.discount_percentage = term.discount_percentage
|
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:
|
||||||
@@ -1262,14 +1259,6 @@ 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):
|
||||||
"""
|
"""
|
||||||
Returns a dict containing the values of `on_hold`, `release_date` and `hold_type` of
|
Returns a dict containing the values of `on_hold`, `release_date` and `hold_type` of
|
||||||
|
|||||||
Reference in New Issue
Block a user