Skip to content

fix: allow zero debit and credit for payroll entries in journal validation#53002

Open
krishna-254 wants to merge 1 commit intofrappe:developfrom
krishna-254:fix/payroll-entry-net-pay-zero
Open

fix: allow zero debit and credit for payroll entries in journal validation#53002
krishna-254 wants to merge 1 commit intofrappe:developfrom
krishna-254:fix/payroll-entry-net-pay-zero

Conversation

@krishna-254
Copy link

Fix

  • Allow row with zero credit and debit when its reference type is Payroll Entry in journal entry.
  • The journal will be now linked allowing it to be easily change on change in payroll entry.
  • Added test case for this case.
image
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

The change modifies the validate_debit_credit_amount method in the Journal Entry doctype to add a conditional exception. Rows containing zero values for both Debit and Credit are now permitted when the row's reference_type is "Payroll Entry", whereas all other voucher types continue to trigger a validation error for such rows.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 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: allowing zero debit and credit for payroll entries in journal entry validation logic.
Description check ✅ Passed The description is related to the changeset, explaining the fix for allowing zero debit/credit rows for payroll entries and mentioning added test coverage.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@erpnext/accounts/doctype/journal_entry/journal_entry.py`:
- Line 920: The current check in journal_entry.py that allows zero debit/credit
for rows with reference_type == "Payroll Entry" is too broad; update the
condition that uses d (the child row) so the zero-value exception only applies
when a Payroll Entry is actually linked. Replace the existing condition (which
checks "and d.reference_type != 'Payroll Entry'") with a guarded check that
requires a non-empty reference_name for Payroll Entry—e.g. treat the row as
invalid unless (d.reference_type == 'Payroll Entry' and d.reference_name) is
true—so only linked Payroll Entry rows may bypass the zero-value validation.

ℹ️ Review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c57e452 and c0edbf1.

📒 Files selected for processing (1)
  • erpnext/accounts/doctype/journal_entry/journal_entry.py
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
for d in self.get("accounts"):
if not flt(d.debit) and not flt(d.credit):
if not flt(d.debit) and not flt(d.credit) and d.reference_type != "Payroll Entry":
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Constrain the zero-value exception to linked Payroll Entry rows.

Line [920] currently allows zero debit/credit when reference_type == "Payroll Entry" even if no payroll document is linked. That broadens the bypass and can allow no-op rows unintentionally. Please require reference_name as part of the exception.

Suggested patch
-				if not flt(d.debit) and not flt(d.credit) and d.reference_type != "Payroll Entry":
+				is_payroll_link_row = d.reference_type == "Payroll Entry" and d.reference_name
+				if not flt(d.debit) and not flt(d.credit) and not is_payroll_link_row:
 					frappe.throw(_("Row {0}: Both Debit and Credit values cannot be zero").format(d.idx))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/accounts/doctype/journal_entry/journal_entry.py` at line 920, The
current check in journal_entry.py that allows zero debit/credit for rows with
reference_type == "Payroll Entry" is too broad; update the condition that uses d
(the child row) so the zero-value exception only applies when a Payroll Entry is
actually linked. Replace the existing condition (which checks "and
d.reference_type != 'Payroll Entry'") with a guarded check that requires a
non-empty reference_name for Payroll Entry—e.g. treat the row as invalid unless
(d.reference_type == 'Payroll Entry' and d.reference_name) is true—so only
linked Payroll Entry rows may bypass the zero-value validation.
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.39%. Comparing base (fd72132) to head (c0edbf1).
⚠️ Report is 230 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #53002      +/-   ##
===========================================
- Coverage    79.41%   79.39%   -0.02%     
===========================================
  Files         1168     1170       +2     
  Lines       123549   123837     +288     
===========================================
+ Hits         98113    98319     +206     
- Misses       25436    25518      +82     
Files with missing lines Coverage Δ
...xt/accounts/doctype/journal_entry/journal_entry.py 74.59% <100.00%> (+0.06%) ⬆️

... and 114 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

Labels

needs-tests This PR needs automated unit-tests.

1 participant