Skip to content

G1 - HR Module#1898

Open
nkg05official wants to merge 32 commits into
FusionIIIT:hr-eis-v1from
nkg05official:hr-eis-v1
Open

G1 - HR Module#1898
nkg05official wants to merge 32 commits into
FusionIIIT:hr-eis-v1from
nkg05official:hr-eis-v1

Conversation

@nkg05official
Copy link
Copy Markdown

This PR is showing merge conflicts because the target branch has newer changes in some HR module files (models.py, urls.py, views.py) that overlap with the changes in this PR, so Git is unable to automatically decide which version to keep.

In this PR, the old views.py and urls.py files outside the api folder were intentionally removed because we were instructed to shift the implementation into the api structure. The newer implementation is now inside the api folder, so the old files are no longer required.

To resolve the conflicts and allow automatic merge:

  • delete the old views.py and urls.py files from the target branch (hr-eis-v1) that are outside the api folder
  • keep the latest PR version of models.py

After that, the PR should merge normally without issues.

vikrantwiz02 and others added 30 commits February 17, 2026 17:31
Copilot AI review requested due to automatic review settings May 9, 2026 05:58
@FusionIIIT-Bot
Copy link
Copy Markdown
Collaborator

Congratulations for making your first Pull Request at Fusion!! 🎉 Someone from our team will review it soon.

@nkg05official nkg05official changed the title Hr eis v1 G1 - HR Module May 9, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Member

@vikrantwiz02 vikrantwiz02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — G1 HR Module (Backend)

Good architectural foundation — services/selectors/workflow layers are cleanly separated, BaseForm as an abstract base is the right pattern, and the custom permission class is well-structured. There are blockers to resolve before this can merge: active merge conflict on target branch, binary/scratch files that should not be committed, a silent breaking change on app_name, and an N+1 in the permission check. Details inline.

designation_name = getattr(hold.designation, "name", None)
if not designation_name:
continue
access = ModuleAccess.objects.filter(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N+1 query per designation. For every designation the user holds, a separate ModuleAccess.objects.filter(...) is fired. On a user with many designations this hits the DB once per row. Collapse into a single query:

designation_names = [
    getattr(h.designation, 'name', '').strip()
    for h in working_designations
    if getattr(h.designation, 'name', None)
]
return ModuleAccess.objects.filter(
    designation__in=designation_names,
    hr=True,
).exists()

If case-insensitivity is required, normalise to lowercase before the filter instead of using __iexact per-row.



app_name = 'hr2'
app_name = 'hr2_refactored'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change: app_name renamed from 'hr2' to 'hr2_refactored'. Any reverse('hr2:...') call in views, templates, or tests will raise NoReverseMatch after this merges. Either keep it as 'hr2', or do a full grep across the repo and update every reverse call before renaming.

dependencies = [
('hr2', '0001_initial'),
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration history rewritten — will break existing deployments. The old 0002_auto_20241020_1126.py is deleted and a new 0002_add_leave_pdf_file.py put in its place. Any database that already ran the original 0002 will fail with InconsistentMigrationHistory on the next migrate. If this was applied anywhere (CI, staging), squash or merge migrations rather than replacing them.

@@ -0,0 +1,209 @@
import os
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev-only scripts should not be committed to the repo. create_demo_users.py, create_hr_roles.py, create_superuser.py, scratch_create_users.py, scratch_delete_ltc.py, scratch_insert.py, and scratch_migrate.py are all local one-off scripts. Any persistent setup logic should be a proper manage.py management command; everything else should be deleted and added to .gitignore.

pfNo = models.IntegerField(null=True)
submissionDate = models.DateField(blank=True, null=True)
approved = models.BooleanField(null=True)
approvedDate = models.DateField(auto_now_add=True, null=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto_now_add=True makes approvedDate non-editable. Once set on creation, it cannot be overridden via the ORM (e.g. for backfills or corrections). Since this is an approval date (set during a workflow step, not on row creation), use default=None, blank=True, null=True and set it explicitly in the workflow:

approvedDate = models.DateField(blank=True, null=True, default=None)

WF_HR_APPROVED = "hr_approved"
WF_HR_REJECTED = "hr_rejected"

TERMINAL_STATUSES = frozenset(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String constants across multiple files risk silent typos. These WF_* constants are defined here but compared against raw strings in the serializer and views. A misspelling anywhere is a silent mismatch. Consider a TextChoices class or a shared LeaveWorkflowStatus enum so mismatches raise AttributeError at import time rather than silently failing at runtime.

@vikrantwiz02
Copy link
Copy Markdown
Member

Additional issues:

Binary archive applications/hr2.zip committed. Binary blobs add permanent weight to git history. Remove it — the source code is already present in the hr2/ folder.

Merge conflict with target branch hr-eis-v1. GitHub reports this PR as CONFLICTING. The conflict is in models.py, urls.py, and views.py as described in the PR body. The target branch needs to have the old files removed (as described), then this branch rebased on top before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants