-
Notifications
You must be signed in to change notification settings - Fork 9.9k
fix: add validation for cancelled reposting entries #50773
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
base: develop
Are you sure you want to change the base?
fix: add validation for cancelled reposting entries #50773
Conversation
📝 WalkthroughWalkthroughThis change introduces a validation guard in the Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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/controllers/accounts_controller.py (1)
367-383: Consider automatic cleanup of cancelled repost entries.The current implementation blocks deletion and asks users to manually delete cancelled repost entries first. While this is safe and explicit, it creates additional manual work for users. Since cancelled entries (docstatus == 2) are already locked and have no functional impact, consider automatically deleting them during this cleanup process, similar to how the method handles references in active repost entries (lines 385-408).
If the manual approach is intentional for audit trail purposes, consider:
- Adding a more specific error message explaining why manual deletion is required
- Checking if the user has delete permissions and providing a direct "delete" action if possible
- Documenting this design decision
Alternatively, you could add a helper that automatically cleans up cancelled repost entries if the user has appropriate permissions, falling back to the current error message only if automatic cleanup fails.
Example enhancement:
if cancelled_entries: - entries = "<br>".join([get_link_to_form(d.parenttype, d.parent) for d in cancelled_entries]) - - frappe.throw( - _( - "The following cancelled repost entries exist for <b>{0}</b>:<br><br>{1}<br><br>" - "Kindly delete these entries before continuing." - ).format(self.name, entries) - ) + # Attempt automatic cleanup of cancelled entries + try: + for entry in cancelled_entries: + repost_doc = frappe.get_doc(entry.parenttype, entry.parent) + if repost_doc.docstatus == 2: # Verify it's cancelled + repost_doc.delete() + except frappe.PermissionError: + # Fallback to manual deletion request + entries = "<br>".join([get_link_to_form(d.parenttype, d.parent) for d in cancelled_entries]) + frappe.throw( + _( + "The following cancelled repost entries exist for <b>{0}</b>:<br><br>{1}<br><br>" + "These entries must be deleted before continuing. You may need delete permissions." + ).format(self.name, entries) + )
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
erpnext/controllers/accounts_controller.py(1 hunks)
⏰ 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). (1)
- GitHub Check: Summary
Issue: Upon Invoice deletion, with cancelled repost entries getting an error for updation.
Ref: 53866
Steps to reproduce:
Before:
After:
Backport needed: Version-15