fix: allow zero debit and credit for payroll entries in journal validation#53002
fix: allow zero debit and credit for payroll entries in journal validation#53002krishna-254 wants to merge 1 commit intofrappe:developfrom
Conversation
📝 WalkthroughWalkthroughThe change modifies the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 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.
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.
| 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": |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Fix