refactor: Employee Tax Exemption

This commit is contained in:
Nabin Hait
2019-04-25 18:44:10 +05:30
parent 07e005f963
commit 04e7bf464f
16 changed files with 1109 additions and 583 deletions

View File

@@ -221,16 +221,31 @@ def get_employee_leave_policy(employee):
def validate_tax_declaration(declarations):
subcategories = []
for declaration in declarations:
if declaration.exemption_sub_category in subcategories:
frappe.throw(_("More than one selection for {0} not \
allowed").format(declaration.exemption_sub_category), frappe.ValidationError)
subcategories.append(declaration.exemption_sub_category)
max_amount = frappe.db.get_value("Employee Tax Exemption Sub Category", \
declaration.exemption_sub_category, "max_amount")
if declaration.amount > max_amount:
frappe.throw(_("Max exemption amount for {0} is {1}").format(\
declaration.exemption_sub_category, max_amount), frappe.ValidationError)
for d in declarations:
if d.exemption_sub_category in subcategories:
frappe.throw(_("More than one selection for {0} not allowed").format(d.exemption_sub_category))
subcategories.append(d.exemption_sub_category)
def get_total_exemption_amount(declarations):
exemption_category = list(set([d.exemption_category for d in declarations]))
exemptions = frappe._dict()
for d in declarations:
exemptions.setdefault(d.exemption_category, frappe._dict())
category_max_amount = exemptions.get(d.exemption_category).max_amount
if not category_max_amount:
category_max_amount = frappe.db.get_value("Employee Tax Exemption Category", d.exemption_category, "max_amount")
exemptions.get(d.exemption_category).max_amount = category_max_amount
sub_category_exemption_amount = d.max_amount \
if (d.max_amount and flt(d.amount) > flt(d.max_amount)) else d.amount
exemptions.get(d.exemption_category).setdefault("total_exemption_amount", 0.0)
exemptions.get(d.exemption_category).total_exemption_amount += flt(sub_category_exemption_amount)
if category_max_amount and exemptions.get(d.exemption_category).total_exemption_amount > category_max_amount:
exemptions.get(d.exemption_category).total_exemption_amount = category_max_amount
total_exemption_amount = sum([flt(d.total_exemption_amount) for d in exemptions.values()])
return total_exemption_amount
def get_leave_period(from_date, to_date, company):
leave_period = frappe.db.sql("""