refactor: remove discount validity date

This commit is contained in:
Saqib Ansari
2021-02-12 11:17:22 +05:30
committed by Deepesh Garg
parent 09ef7b62a1
commit 153323ee41
6 changed files with 17 additions and 64 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.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_in_foreign_currency = discount_amount * doc.get('conversion_rate', 1)

View File

@@ -6,11 +6,10 @@
"engine": "InnoDB",
"field_order": [
"payment_term",
"description",
"discount_percentage",
"discount_validity",
"discounted_amount",
"outstanding",
"description",
"column_break_3",
"due_date",
"invoice_portion",
@@ -101,20 +100,12 @@
"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-11 13:03:33.353333",
"modified": "2021-02-11 20:11:42.058393",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Schedule",

View File

@@ -10,13 +10,12 @@
"field_order": [
"payment_term_name",
"invoice_portion",
"mode_of_payment",
"discount_percentage",
"column_break_3",
"due_date_based_on",
"credit_days",
"credit_months",
"discount_validity",
"mode_of_payment",
"section_break_6",
"description"
],
@@ -78,17 +77,10 @@
"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-11 13:04:03.192185",
"modified": "2021-02-11 20:09:42.559344",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Term",

View File

@@ -12,23 +12,8 @@ from frappe import _
class PaymentTermsTemplate(Document):
def validate(self):
self.validate_invoice_portion()
self.validate_credit_days()
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):
terms = []
for term in self.terms:

View File

@@ -6,9 +6,8 @@
"engine": "InnoDB",
"field_order": [
"payment_term",
"description",
"discount_percentage",
"discount_validity",
"description",
"column_break_3",
"invoice_portion",
"due_date_based_on",
@@ -23,7 +22,8 @@
"fieldtype": "Link",
"in_list_view": 1,
"label": "Payment Term",
"options": "Payment Term"
"options": "Payment Term",
"reqd": 1
},
{
"columns": 2,
@@ -60,7 +60,8 @@
"fieldname": "credit_days",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Credit Days"
"label": "Credit Days",
"non_negative": 1
},
{
"default": "0",
@@ -68,7 +69,8 @@
"fetch_from": "payment_term.credit_months",
"fieldname": "credit_months",
"fieldtype": "Int",
"label": "Credit Months"
"label": "Credit Months",
"non_negative": 1
},
{
"fetch_from": "payment_term.mode_of_payment",
@@ -86,18 +88,12 @@
"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-11 12:54:48.934368",
"modified": "2021-02-11 20:10:29.233745",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Terms Template Detail",

View File

@@ -910,7 +910,8 @@ class AccountsController(TransactionBase):
else:
for d in self.get("payment_schedule"):
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
def set_due_date(self):
@@ -949,8 +950,7 @@ class AccountsController(TransactionBase):
total = 0
base_total = 0
for d in self.get("payment_schedule"):
total += flt(d.payment_amount)
base_total += flt(d.base_payment_amount)
total += flt(d.payment_amount) if not d.discount_percentage else 0
base_grand_total = self.get("base_rounded_total") or self.base_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.invoice_portion = term.invoice_portion
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.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:
@@ -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)
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):
"""
Returns a dict containing the values of `on_hold`, `release_date` and `hold_type` of