Skip to content

Commit

Permalink
refactor: fetch PAN data for indian company
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Nov 16, 2023
1 parent 42b743c commit 39512ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions hrms/payroll/report/income_tax_deductions/income_tax_deductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@

import erpnext

Filters = frappe._dict

def execute(filters=None):
data = get_data(filters)
columns = get_columns()

def execute(filters: Filters = None) -> tuple:
is_indian_company = erpnext.get_region(filters.get("company")) == "India"
columns = get_columns(is_indian_company)
data = get_data(filters, is_indian_company)

return columns, data


def get_columns():
def get_columns(is_indian_company: bool) -> list[dict]:
columns = [
{
"label": _("Employee"),
Expand All @@ -33,7 +36,7 @@ def get_columns():
},
]

if erpnext.get_region() == "India":
if is_indian_company:
columns.append(
{"label": _("PAN Number"), "fieldname": "pan_number", "fieldtype": "Data", "width": 140}
)
Expand All @@ -60,11 +63,11 @@ def get_columns():
return columns


def get_data(filters):
def get_data(filters: Filters, is_indian_company: bool) -> list[dict]:
data = []

employee_pan_dict = {}
if erpnext.get_region() == "India":
if is_indian_company:
employee_pan_dict = frappe._dict(
frappe.get_all("Employee", fields=["name", "pan_number"], as_list=True)
)
Expand All @@ -81,15 +84,15 @@ def get_data(filters):
"gross_pay": d.gross_pay,
}

if erpnext.get_region() == "India":
if is_indian_company:
employee["pan_number"] = employee_pan_dict.get(d.employee)

data.append(employee)

return data


def get_income_tax_deductions(filters):
def get_income_tax_deductions(filters: Filters) -> list[dict]:
component_types = frappe.get_all(
"Salary Component", filters={"is_income_tax_component": 1}, pluck="name"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_report(self):
"posting_date": posting_date,
"it_amount": 7732.0,
"gross_pay": 78000.0,
"pan_number": None,
}

self.assertEqual(result[1][0], expected_data)

0 comments on commit 39512ef

Please sign in to comment.