[FIX] PAYROLL: Isolate allowances and deductions per company to prevent cross-company visibility and edits

This commit is contained in:
Horilla
2025-07-08 11:38:50 +05:30
parent ba1095d58a
commit 395d7fab97
2 changed files with 10 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ from payroll.widgets import component_widgets as widget
logger = logging.getLogger(__name__)
class AllowanceForm(forms.ModelForm):
class AllowanceForm(ModelForm):
"""
Form for Allowance model
"""
@@ -182,7 +182,7 @@ class AllowanceForm(forms.ModelForm):
return multiple_conditions
class DeductionForm(forms.ModelForm):
class DeductionForm(ModelForm):
"""
Form for Deduction model
"""

View File

@@ -1043,6 +1043,10 @@ class Allowance(HorillaModel):
return str(self.title)
def save(self):
request = getattr(horilla_middlewares._thread_locals, "request", None)
selected_company = request.session.get("selected_company")
if not self.id and selected_company and selected_company != "all":
self.company_id = Company.find(selected_company)
super().save()
@@ -1325,6 +1329,10 @@ class Deduction(HorillaModel):
return str(self.title)
def save(self):
request = getattr(horilla_middlewares._thread_locals, "request", None)
selected_company = request.session.get("selected_company")
if not self.id and selected_company and selected_company != "all":
self.company_id = Company.find(selected_company)
super().save()