fix(hrms): sick leave BHXH formula /24 + base tháng liền kề (TETRA-1446) #12

Merged
tant merged 2 commits from fix/TETRA-1446-sick-leave-bhxh-formula into develop 2026-04-25 22:44:51 +07:00
Owner

Summary

Fix 2 bug trong BHXH Claim sick-leave / work-injury formula vi phạm Luật BHXH 41/2024 Đ.45 khoản 5 (hiệu lực 01/07/2025).

Trước: daily_rate = avg_salary_6m / 26 → NV thiếu ~8% + sai số khi đổi bậc.
Sau: daily_rate = lương_BH_tháng_liền_kề / 24 (chỉ sick leave + work-injury).

Maternity (Thai san) giữ /26 + 6-month avg per Đ.39 — KHÔNG ảnh hưởng.

Changes

  • vhrms/vhrms/doctype/bhxh_claim/bhxh_claim.py: rename calculate_average_salarycalculate_insurance_base_salary, branch logic theo claim_type, fix divisor /24 cho sick/work-injury.
  • vhrms/vhrms/payroll/vietnam_calculations.py: helper mới get_previous_month_insurance_salary(employee, claim_month) với fallback chain Salary Slip → SSA → Employee.ctc.
  • vhrms/vhrms/patches/v0_7_0/recompute_old_bhxh_claims.py: backfill patch READ-ONLY — log delta cho từng claim từ 01/07/2025, không auto-update (HR review thủ công).
  • vhrms/patches.txt: register new patch.
  • vhrms/vhrms/tests/test_bhxh_claim_formula.py: 10 unit tests (divisor /24, helper fallback chain, sick-leave dùng tháng liền kề, maternity regression, edge cases NV mới).
  • vhrms/vhrms/tests/test_payroll_deductions.py: extend frappe stub với add_months / get_first_day / get_last_day (do vietnam_calculations.py import thêm các helper này).
  • CHANGELOG.md: entry [0.7.0].

Test plan

  • Unit tests local (10 tests pass + 8 existing pass + 50 other payroll tests pass)
  • bench migrate trên staging → patch chạy + log delta
  • Test sick leave 1 NV: divisor đã /24, base lấy tháng liền kề
  • Test maternity (Thai san): vẫn /26 + 6-month avg (regression check)
  • Test edge case NV mới (chưa có salary slip tháng trước): fallback SSA base
  • HR review log từ patch backfill, làm điều chỉnh cho các claim đã submit từ 01/07/2025

Refs

  • TETRA-1446
  • Luật BHXH 41/2024 Đ.45 khoản 5
  • Confluence ADR Section 11 S1.v5

🤖 Generated with Claude Code

## Summary Fix 2 bug trong BHXH Claim sick-leave / work-injury formula vi phạm **Luật BHXH 41/2024 Đ.45 khoản 5** (hiệu lực 01/07/2025). **Trước**: `daily_rate = avg_salary_6m / 26` → NV thiếu ~8% + sai số khi đổi bậc. **Sau**: `daily_rate = lương_BH_tháng_liền_kề / 24` (chỉ sick leave + work-injury). Maternity (`Thai san`) giữ /26 + 6-month avg per Đ.39 — KHÔNG ảnh hưởng. ## Changes - `vhrms/vhrms/doctype/bhxh_claim/bhxh_claim.py`: rename `calculate_average_salary` → `calculate_insurance_base_salary`, branch logic theo claim_type, fix divisor /24 cho sick/work-injury. - `vhrms/vhrms/payroll/vietnam_calculations.py`: helper mới `get_previous_month_insurance_salary(employee, claim_month)` với fallback chain Salary Slip → SSA → Employee.ctc. - `vhrms/vhrms/patches/v0_7_0/recompute_old_bhxh_claims.py`: backfill patch READ-ONLY — log delta cho từng claim từ 01/07/2025, không auto-update (HR review thủ công). - `vhrms/patches.txt`: register new patch. - `vhrms/vhrms/tests/test_bhxh_claim_formula.py`: 10 unit tests (divisor /24, helper fallback chain, sick-leave dùng tháng liền kề, maternity regression, edge cases NV mới). - `vhrms/vhrms/tests/test_payroll_deductions.py`: extend frappe stub với `add_months` / `get_first_day` / `get_last_day` (do `vietnam_calculations.py` import thêm các helper này). - `CHANGELOG.md`: entry [0.7.0]. ## Test plan - [x] Unit tests local (10 tests pass + 8 existing pass + 50 other payroll tests pass) - [ ] `bench migrate` trên staging → patch chạy + log delta - [ ] Test sick leave 1 NV: divisor đã /24, base lấy tháng liền kề - [ ] Test maternity (Thai san): vẫn /26 + 6-month avg (regression check) - [ ] Test edge case NV mới (chưa có salary slip tháng trước): fallback SSA base - [ ] HR review log từ patch backfill, làm điều chỉnh cho các claim đã submit từ 01/07/2025 ## Refs - TETRA-1446 - Luật BHXH 41/2024 Đ.45 khoản 5 - Confluence ADR Section 11 S1.v5 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tant force-pushed fix/TETRA-1446-sick-leave-bhxh-formula from 31e1022732 to 56cf83d72c 2026-04-25 22:44:09 +07:00 Compare
Author
Owner

Review summary (Claude Code)

Verdict: APPROVE (after addressing nits in 56cf83d)

Reviewed deeply against TETRA-1446 acceptance + Luật BHXH 41/2024 Đ.45.5. All 4 critical surfaces (divisor, base, fallback chain, maternity regression) verified via 10 unit tests. 18/18 combined payroll suite pass.

Fixes applied in 56cf83d:

  • recompute_old_bhxh_claims.py: import canonical get_previous_month_insurance_salary thay vì duplicate (tránh drift).
  • vietnam_calculations.py: thêm comment intent cho Salary Slip filter (off-cycle slip behavior) + SSA fallback boundary (claim_start, không phải prev_month_end).
  • test_bhxh_claim_formula.py: xóa dead _mock_db_sql + unused SimpleNamespace import.

Deferred (sẽ tạo follow-up tickets):

  • Field average_salary semantic-overload — rename → benefit_base_salary v0.8.0.
  • Test "force-pop modules" hack — chuyển sang pytest fixture sau.
### Review summary (Claude Code) **Verdict**: ✅ APPROVE (after addressing nits in 56cf83d) Reviewed deeply against TETRA-1446 acceptance + Luật BHXH 41/2024 Đ.45.5. All 4 critical surfaces (divisor, base, fallback chain, maternity regression) verified via 10 unit tests. 18/18 combined payroll suite pass. **Fixes applied in 56cf83d**: - `recompute_old_bhxh_claims.py`: import canonical `get_previous_month_insurance_salary` thay vì duplicate (tránh drift). - `vietnam_calculations.py`: thêm comment intent cho Salary Slip filter (off-cycle slip behavior) + SSA fallback boundary (`claim_start`, không phải `prev_month_end`). - `test_bhxh_claim_formula.py`: xóa dead `_mock_db_sql` + unused `SimpleNamespace` import. **Deferred** (sẽ tạo follow-up tickets): - Field `average_salary` semantic-overload — rename → `benefit_base_salary` v0.8.0. - Test "force-pop modules" hack — chuyển sang pytest fixture sau.
tant merged commit dae3afb61e into develop 2026-04-25 22:44:51 +07:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tant/vhrms!12
No description provided.