Skip to content

Commit

Permalink
Merge pull request #2697 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal authored Jan 24, 2025
2 parents 4e8a58c + 4f90a22 commit bff02dd
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 19 deletions.
13 changes: 13 additions & 0 deletions hrms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"hrms.overrides.company.make_company_fixtures",
"hrms.overrides.company.set_default_hr_accounts",
],
"on_trash": "hrms.overrides.company.handle_linked_docs",
},
"Holiday List": {
"on_update": "hrms.utils.holiday_list.invalidate_cache",
Expand Down Expand Up @@ -347,3 +348,15 @@
# Recommended only for DocTypes which have limited documents with untranslated names
# For example: Role, Gender, etc.
# translated_search_doctypes = []

company_data_to_be_ignored = [
"Salary Component Account",
"Salary Structure",
"Salary Structure Assignment",
"Payroll Period",
"Income Tax Slab",
"Leave Period",
"Leave Policy Assignment",
"Employee Onboarding Template",
"Employee Separation Template",
]
12 changes: 8 additions & 4 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,21 @@ def get_salary_assignments(employee, payroll_period):
order_by="from_date",
)

if not assignments:
if not assignments or getdate(assignments[0].from_date) > getdate(start_date):
# if no assignments found for the given period
# get the last one assigned before the period that is still active
assignments = frappe.get_all(
# or the latest assignment hast started in the middle of the period
# get the last one assigned before the period start date
past_assignment = frappe.get_all(
"Salary Structure Assignment",
filters={"employee": employee, "docstatus": 1, "from_date": ["<=", start_date]},
filters={"employee": employee, "docstatus": 1, "from_date": ["<", start_date]},
fields=["*"],
order_by="from_date desc",
limit=1,
)

if past_assignment:
assignments = past_assignment + assignments

return assignments


Expand Down
52 changes: 52 additions & 0 deletions hrms/overrides/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,55 @@ def validate_default_accounts(doc, method=None):
"The currency of {0} should be same as the company's default currency. Please select another account."
).format(frappe.bold(_("Default Payroll Payable Account")))
)


def handle_linked_docs(doc, method=None):
delete_docs_with_company_field(doc)
clear_company_field_for_single_doctypes(doc)


def delete_docs_with_company_field(doc, method=None):
"""
Deletes records from linked doctypes where the 'company' field matches the company's name
"""
company_data_to_be_ignored = frappe.get_hooks("company_data_to_be_ignored") or []
for doctype in company_data_to_be_ignored:
records_to_delete = frappe.get_all(doctype, filters={"company": doc.name}, pluck="name")
if records_to_delete:
frappe.db.delete(doctype, {"name": ["in", records_to_delete]})


def clear_company_field_for_single_doctypes(doc):
"""
Clears the 'company' value in Single doctypes where applicable
"""
single_docs = get_single_doctypes_with_company_field()
singles = frappe.qb.DocType("Singles")
(
frappe.qb.update(singles)
.set(singles.value, "")
.where(singles.doctype.isin(single_docs))
.where(singles.field == "company")
.where(singles.value == doc.name)
).run()


def get_single_doctypes_with_company_field():
DocType = frappe.qb.DocType("DocType")
DocField = frappe.qb.DocType("DocField")

return (
frappe.qb.from_(DocField)
.select(DocField.parent)
.where(
(DocField.fieldtype == "Link")
& (DocField.options == "Company")
& (
DocField.parent.isin(
frappe.qb.from_(DocType)
.select(DocType.name)
.where((DocType.issingle == 1) & (DocType.module.isin(["HR", "Payroll"])))
)
)
)
).run(pluck=True)
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ def test_india_hra_exemption_with_multiple_assignments(self):
)

# salary structure with base 50000, HRA 3000
# effective from 3 months before payroll period
make_salary_structure(
"Monthly Structure for HRA Exemption 1",
"Monthly",
employee=employee,
company="_Test Company",
currency="INR",
payroll_period=payroll_period.name,
from_date=payroll_period.start_date,
from_date=add_months(payroll_period.start_date, -3),
)

# salary structure with base 70000, HRA = base * 0.2 = 14000
Expand All @@ -379,6 +380,7 @@ def test_india_hra_exemption_with_multiple_assignments(self):

salary_structure.submit()

# effective from 6 months after payroll period
create_salary_structure_assignment(
employee,
salary_structure.name,
Expand Down
3 changes: 1 addition & 2 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,10 @@ frappe.ui.form.on("Payroll Entry", {

salary_slip_based_on_timesheet: function (frm) {
frm.toggle_reqd(["payroll_frequency"], !frm.doc.salary_slip_based_on_timesheet);
hrms.set_payroll_frequency_to_null(frm);
},

set_start_end_dates: function (frm) {
if (!frm.doc.salary_slip_based_on_timesheet) {
if (frm.doc.payroll_frequency) {
frappe.call({
method: "hrms.payroll.doctype.payroll_entry.payroll_entry.get_start_end_dates",
args: {
Expand Down
3 changes: 1 addition & 2 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"reqd": 1
},
{
"depends_on": "eval:doc.salary_slip_based_on_timesheet == 0",
"fieldname": "payroll_frequency",
"fieldtype": "Select",
"label": "Payroll Frequency",
Expand Down Expand Up @@ -336,7 +335,7 @@
"icon": "fa fa-cog",
"is_submittable": 1,
"links": [],
"modified": "2023-10-10 14:21:24.517349",
"modified": "2025-01-22 15:27:16.652848",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Entry",
Expand Down
5 changes: 0 additions & 5 deletions hrms/payroll/doctype/salary_slip/salary_slip.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ frappe.ui.form.on("Salary Slip", {
["hourly_wages", "timesheets"],
cint(frm.doc.salary_slip_based_on_timesheet) === 1,
);

frm.toggle_display(
["payment_days", "total_working_days", "leave_without_pay"],
frm.doc.payroll_frequency != "",
);
},

get_emp_and_working_day_details: function (frm) {
Expand Down
6 changes: 3 additions & 3 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def validate(self):
self.validate_dates()
self.check_existing()

if not self.salary_slip_based_on_timesheet:
if self.payroll_frequency:
self.get_date_details()

if not (len(self.get("earnings")) or len(self.get("deductions"))):
Expand Down Expand Up @@ -321,7 +321,7 @@ def get_emp_and_working_day_details(self):
self.set("earnings", [])
self.set("deductions", [])

if not self.salary_slip_based_on_timesheet:
if self.payroll_frequency:
self.get_date_details()

self.validate_dates()
Expand Down Expand Up @@ -1913,7 +1913,7 @@ def set_status(self, status=None):

def process_salary_structure(self, for_preview=0):
"""Calculate salary after salary structure details have been updated"""
if not self.salary_slip_based_on_timesheet:
if self.payroll_frequency:
self.get_date_details()
self.pull_emp_details()
self.get_working_days_details(for_preview=for_preview)
Expand Down
1 change: 0 additions & 1 deletion hrms/payroll/doctype/salary_structure/salary_structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ frappe.ui.form.on("Salary Structure", {

salary_slip_based_on_timesheet: function (frm) {
frm.trigger("toggle_fields");
hrms.set_payroll_frequency_to_null(frm);
},

preview_salary_slip: function (frm) {
Expand Down
2 changes: 1 addition & 1 deletion hrms/regional/india/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_custom_fields():
"fieldname": "hra_section",
"label": "HRA Settings",
"fieldtype": "Section Break",
"insert_after": "asset_received_but_not_billed",
"insert_after": "default_payroll_payable_account",
"collapsible": 1,
},
{
Expand Down

0 comments on commit bff02dd

Please sign in to comment.