fix: exclude Period Closing Voucher entries from net movement calculations in financial reports#54130
fix: exclude Period Closing Voucher entries from net movement calculations in financial reports#54130ljain112 wants to merge 1 commit intofrappe:developfrom
Conversation
…tions in financial reports
📝 WalkthroughWalkthroughThe financial report engine has been enhanced to handle Period Closing Vouchers (PCVs) with differentiated treatment. The production code now computes separate PCV-specific GL movement aggregates, modifies balance calculation logic to exclude PCV impact from period movement while retaining it in closing balances, and removes prior conditional PCV filtering. The test suite has been refactored to introduce helper functions for PCV lifecycle management, reorganize setup/teardown patterns using decorators, and add a new test case validating the PCV exclusion behavior in quarterly period calculations. Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
erpnext/accounts/doctype/financial_report_template/financial_report_engine.py (1)
669-678: Consider usingflt()consistently on both movement values.Line 674 applies
flt()topcv_movementbut line 669 does not apply it tototal_movement. While.get(..., 0.0)provides a default, if the database returnsNonefor an existing key (e.g., fromSUM()edge cases),total_movementcould beNone.For defensive consistency:
Suggested change
for period in self.periods: period_key = period["key"] - total_movement = gl_movement.get(period_key, 0.0) + total_movement = flt(gl_movement.get(period_key, 0.0)) pcv_movement = gl_movement.get(f"{period_key}__pcv", 0.0) closing_balance = current_balance + total_movement # Net/period movement should exclude PCV entries. movement = total_movement - flt(pcv_movement)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@erpnext/accounts/doctype/financial_report_template/financial_report_engine.py` around lines 669 - 678, The code assumes total_movement from gl_movement.get(period_key, 0.0) is numeric but may be None; wrap total_movement with flt() consistently before using it (e.g., compute total_movement = flt(gl_movement.get(period_key, 0.0))) so closing_balance = current_balance + total_movement and movement = total_movement - flt(pcv_movement) are safe; update the block around PeriodValue construction (PeriodValue, account_data.add_period, current_balance update) to use the flt-wrapped total_movement.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@erpnext/accounts/doctype/financial_report_template/financial_report_engine.py`:
- Around line 669-678: The code assumes total_movement from
gl_movement.get(period_key, 0.0) is numeric but may be None; wrap total_movement
with flt() consistently before using it (e.g., compute total_movement =
flt(gl_movement.get(period_key, 0.0))) so closing_balance = current_balance +
total_movement and movement = total_movement - flt(pcv_movement) are safe;
update the block around PeriodValue construction (PeriodValue,
account_data.add_period, current_balance update) to use the flt-wrapped
total_movement.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 9ab70113-03f5-4507-b766-6782421fd26b
📒 Files selected for processing (2)
erpnext/accounts/doctype/financial_report_template/financial_report_engine.pyerpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #54130 +/- ##
========================================
Coverage 79.12% 79.12%
========================================
Files 1159 1159
Lines 125227 125303 +76
========================================
+ Hits 99082 99152 +70
- Misses 26145 26151 +6
🚀 New features to boost your workflow:
|
Issue: Period Movement included Period Closing Entry, due to which Accounts in Profit and Loss were showing a 0 balance.