-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix(payment_entry): merge GL entries with similar account heads based on setting #51453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughPaymentEntry.make_gl_entries now reads the Accounts Settings value merge_similar_account_heads and passes it as a merge_entries argument into process_gl_map and make_gl_entries calls, enabling optional consolidation of GL entries when multiple deductions use the same account head. The cancel path and existing exchange gain/loss journal calls remain unchanged. Tests were added/updated to verify merged vs. separate GL entries when the setting is enabled or disabled, and an existing multi-currency test was adjusted to enable the merge setting before assertions. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py (1)
1503-1504: Consider using the@IntegrationTestCase.change_settingsdecorator for proper test isolation.Setting
merge_similar_account_headsdirectly without cleanup can leave the setting modified after the test completes, potentially affecting other tests. The decorator pattern (already used in this file at lines 512, 1294, 1497, etc.) automatically restores the original value after the test.Suggested approach using decorator
Remove lines 1503-1504 and modify the decorator at line 1497-1499:
@IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} + "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1, "merge_similar_account_heads": 1} ) def test_purchase_invoice_advance_taxes(self): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry - frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1) - company = "_Test Company"Alternatively, if the setting must be modified within the test body, restore it afterward:
+ original_value = frappe.db.get_single_value("Accounts Settings", "merge_similar_account_heads") frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1) company = "_Test Company" # ... rest of test ... + + # Cleanup + frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", original_value)
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ljain112
Repo: frappe/erpnext PR: 49963
File: erpnext/accounts/doctype/journal_entry/journal_entry.py:0-0
Timestamp: 2025-10-09T06:59:10.528Z
Learning: In erpnext/accounts/doctype/journal_entry/journal_entry.py, the validate() method calls validate_multi_currency() before apply_tax_withholding(). The validate_multi_currency() method internally calls set_exchange_rate(), so exchange rates are properly set on all account rows before TDS calculations occur in apply_tax_withholding().
Learnt from: vorasmit
Repo: frappe/erpnext PR: 51099
File: erpnext/patches/v16_0/migrate_tax_withholding_data.py:904-910
Timestamp: 2025-12-23T11:28:49.128Z
Learning: In the old Tax Withholding system (before the Tax Withholding Entry refactor), only one TCS account per Sales Invoice was supported. When reviewing migration code in erpnext/patches/v16_0/migrate_tax_withholding_data.py, the query selecting TCS accounts from GL Entries doesn't need explicit aggregation because historical data will only have one TCS account per invoice.
📚 Learning: 2025-12-23T11:28:49.128Z
Learnt from: vorasmit
Repo: frappe/erpnext PR: 51099
File: erpnext/patches/v16_0/migrate_tax_withholding_data.py:904-910
Timestamp: 2025-12-23T11:28:49.128Z
Learning: In the old Tax Withholding system (before the Tax Withholding Entry refactor), only one TCS account per Sales Invoice was supported. When reviewing migration code in erpnext/patches/v16_0/migrate_tax_withholding_data.py, the query selecting TCS accounts from GL Entries doesn't need explicit aggregation because historical data will only have one TCS account per invoice.
Applied to files:
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
📚 Learning: 2025-12-16T05:33:58.723Z
Learnt from: Abdeali099
Repo: frappe/erpnext PR: 51078
File: erpnext/accounts/doctype/financial_report_template/financial_report_engine.py:486-491
Timestamp: 2025-12-16T05:33:58.723Z
Learning: In ERPNext/Frappe codebase, query.run(as_dict=True) returns frappe._dict objects that support both dict-style access (obj["key"]) and attribute-style access (obj.key). Therefore, attribute access on query results is valid and will not raise AttributeError. When reviewing Python code, prefer attribute access (obj.key) for readability where the key is known to exist, but ensure existence checks or fallback handling if there is any doubt about missing keys.
Applied to files:
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Python Unit Tests (1)
- GitHub Check: Python Unit Tests (4)
- GitHub Check: Patch Test
- GitHub Check: Python Unit Tests (2)
- GitHub Check: Python Unit Tests (3)
- GitHub Check: Summary
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #51453 +/- ##
===========================================
+ Coverage 79.04% 79.05% +0.01%
===========================================
Files 1179 1179
Lines 121265 121407 +142
===========================================
+ Hits 95853 95981 +128
- Misses 25412 25426 +14
🚀 New features to boost your workflow:
|
Closes: #48790