Skip to content

fix: exclude Period Closing Voucher entries from net movement calculations in financial reports#54130

Open
ljain112 wants to merge 1 commit intofrappe:developfrom
ljain112:fix-period-movement
Open

fix: exclude Period Closing Voucher entries from net movement calculations in financial reports#54130
ljain112 wants to merge 1 commit intofrappe:developfrom
ljain112:fix-period-movement

Conversation

@ljain112
Copy link
Copy Markdown
Collaborator

@ljain112 ljain112 commented Apr 8, 2026

Issue: Period Movement included Period Closing Entry, due to which Accounts in Profit and Loss were showing a 0 balance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: excluding Period Closing Voucher entries from net movement calculations in financial reports, which directly addresses the core issue.
Description check ✅ Passed The description is directly related to the changeset, explaining the issue of Period Movement including Period Closing Entries and how it affected Profit and Loss accounts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
erpnext/accounts/doctype/financial_report_template/financial_report_engine.py (1)

669-678: Consider using flt() consistently on both movement values.

Line 674 applies flt() to pcv_movement but line 669 does not apply it to total_movement. While .get(..., 0.0) provides a default, if the database returns None for an existing key (e.g., from SUM() edge cases), total_movement could be None.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d16d06 and 9a23e6e.

📒 Files selected for processing (2)
  • erpnext/accounts/doctype/financial_report_template/financial_report_engine.py
  • erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 97.46835% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.12%. Comparing base (98dfd64) to head (9a23e6e).
⚠️ Report is 50 commits behind head on develop.

Files with missing lines Patch % Lines
...al_report_template/test_financial_report_engine.py 97.26% 2 Missing ⚠️
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     
Files with missing lines Coverage Δ
...nancial_report_template/financial_report_engine.py 43.74% <100.00%> (ø)
...al_report_template/test_financial_report_engine.py 99.74% <97.26%> (-0.26%) ⬇️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant