Skip to content

Commit

Permalink
Merge pull request #3596 from ONE-F-M/188120671
Browse files Browse the repository at this point in the history
feat: Department wise Salary Component Account
  • Loading branch information
pjamsheer authored Aug 27, 2024
2 parents 2f04c6b + 0e1c1d5 commit 0144111
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 1 deletion.
102 changes: 102 additions & 0 deletions one_fm/one_fm/custom/salary_component_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"custom_fields": [
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"creation": "2024-08-26 14:25:46.059132",
"default": null,
"depends_on": null,
"description": "If left empty, will apply to all departments.",
"docstatus": 0,
"dt": "Salary Component Account",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_department",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"idx": 3,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"insert_after": "account",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Department",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2024-08-26 14:25:46.059132",
"modified_by": "Administrator",
"module": null,
"name": "Salary Component Account-custom_department",
"no_copy": 0,
"non_negative": 0,
"options": "Department",
"owner": "Administrator",
"parent": null,
"parentfield": null,
"parenttype": null,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"show_dashboard": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
}
],
"custom_perms": [],
"doctype": "Salary Component Account",
"links": [],
"property_setters": [
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"creation": "2024-08-26 14:26:30.843062",
"default_value": null,
"doc_type": "Salary Component Account",
"docstatus": 0,
"doctype_or_field": "DocType",
"field_name": null,
"idx": 0,
"is_system_generated": 0,
"modified": "2024-08-26 14:26:30.843062",
"modified_by": "Administrator",
"module": null,
"name": "Salary Component Account-main-field_order",
"owner": "Administrator",
"parent": null,
"parentfield": null,
"parenttype": null,
"property": "field_order",
"property_type": "Data",
"row_name": null,
"value": "[\"company\", \"account\", \"custom_department\"]"
}
],
"sync_on_migrate": 1
}
74 changes: 73 additions & 1 deletion one_fm/overrides/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,86 @@
from frappe.utils import (
add_to_date,
cint,
getdate
getdate,
get_link_to_form,
flt
)
from hrms.payroll.doctype.payroll_entry.payroll_entry import ( PayrollEntry, get_employee_list, get_salary_structure, remove_payrolled_employees,
set_fields_to_select, set_searchfield, set_match_conditions)



class PayrollEntryOverride(PayrollEntry):
def get_salary_component_total(
self,
component_type=None,
employee_wise_accounting_enabled=False,
):
salary_components = self.get_salary_components(component_type)
if salary_components:
component_dict = {}

for item in salary_components:
if not self.should_add_component_to_accrual_jv(component_type, item):
continue

department = frappe.db.get_value("Employee", item.employee, "department")
employee_cost_centers = self.get_payroll_cost_centers_for_employee(
item.employee, item.salary_structure
)
employee_advance = self.get_advance_deduction(component_type, item)

for cost_center, percentage in employee_cost_centers.items():
amount_against_cost_center = flt(item.amount) * percentage / 100

if employee_advance:
self.add_advance_deduction_entry(
item, amount_against_cost_center, cost_center, employee_advance
)
else:
key = (item.salary_component, cost_center, department)
component_dict[key] = component_dict.get(key, 0) + amount_against_cost_center

if employee_wise_accounting_enabled:
self.set_employee_based_payroll_payable_entries(
component_type, item.employee, amount_against_cost_center
)

account_details = self.get_account(component_dict=component_dict)

return account_details

def get_account(self, component_dict=None):
account_dict = {}
for key, amount in component_dict.items():
component, cost_center, department = key
account = self.get_salary_component_account(component, department)
accounting_key = (account, cost_center)

account_dict[accounting_key] = account_dict.get(accounting_key, 0) + amount

return account_dict

def get_salary_component_account(self, salary_component, department):
account = frappe.db.get_value("Salary Component Account",
{"parent": salary_component, "company": self.company, "custom_department": department},
"account", cache=True
)
if not account:
account = frappe.db.get_value("Salary Component Account",
{"parent": salary_component, "company": self.company},
"account", cache=True
)

if not account:
frappe.throw(
_("Please set account in Salary Component {0}").format(
get_link_to_form("Salary Component", salary_component)
)
)

return account

@frappe.whitelist()
def fill_employee_details(self):
filters = self.make_filters()
Expand Down

0 comments on commit 0144111

Please sign in to comment.