fix: modify voucher type based on account type#3842
fix: modify voucher type based on account type#3842elshafei-developer wants to merge 8 commits intofrappe:developfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughPayroll Entry logic and tests were changed to treat both "Bank Entry" and "Cash Entry" journal entries as payment sources. The 🚥 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. 📝 Coding Plan
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 Tip CodeRabbit can generate a title for your PR based on the changes with custom instructions.Set the |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py (1)
1009-1100: Add server-side validation for payment_account account type.The code at lines 1093-1095 assumes
payment_accountis either a "Bank" or "Cash" account without validation. Although client-side filtering exists in the form, direct API calls or database updates could bypass this, resulting in an incorrect voucher type being set for unsupported account types.Add this validation method:
def validate_payment_account(self): if not self.payment_account: return payment_account_type = frappe.db.get_value( "Account", self.payment_account, "account_type" ) if payment_account_type not in ("Bank", "Cash"): frappe.throw( _( "Account type should be either {0} or {1} for payment account {2}, please set and try again" ).format( frappe.bold("Bank"), frappe.bold("Cash"), frappe.bold(get_link_to_form("Account", self.payment_account)), ) )Then call it in
before_submit():def before_submit(self): self.validate_existing_salary_slips() self.validate_payroll_payable_account() + self.validate_payment_account() if self.get_employees_with_unmarked_attendance(): frappe.throw(_("Cannot submit. Attendance is not marked for some employees."))
🧹 Nitpick comments (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py (1)
882-904: Consider renaming for clarity.The method name
has_bank_entriesand the return key"has_bank_entries"are now misleading since the logic checks for both "Bank Entry" and "Cash Entry" voucher types. Consider renaming to better reflect the actual behavior (e.g.,has_payment_entriesorhas_bank_or_cash_entries).Apply this diff to improve clarity:
@frappe.whitelist() - def has_bank_entries(self) -> dict[str, bool]: + def has_payment_entries(self) -> dict[str, bool]: je = frappe.qb.DocType("Journal Entry") jea = frappe.qb.DocType("Journal Entry Account") - bank_entries = ( + payment_entries = ( frappe.qb.from_(je) .inner_join(jea) .on(je.name == jea.parent) .select(je.name) .where( ((je.voucher_type == "Bank Entry") | (je.voucher_type == "Cash Entry")) & (jea.reference_name == self.name) & (jea.reference_type == "Payroll Entry") ) ).run(as_dict=True) return { - "has_bank_entries": bool(bank_entries), - "has_bank_entries_for_withheld_salaries": not any( + "has_payment_entries": bool(payment_entries), + "has_payment_entries_for_withheld_salaries": not any( employee.is_salary_withheld for employee in self.employees ), }Note: This change would require updating any client-side code that calls this method or uses the returned keys.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: asmitahase
Repo: frappe/hrms PR: 3448
File: hrms/hr/doctype/employee_advance/employee_advance.py:109-117
Timestamp: 2025-08-07T11:26:49.671Z
Learning: In the Employee Advance system, `set_total_advance_paid` is only called after advance payment ledger entries are created, which already validates that the account type is either "Receivable" or "Payable". Additional validation for account type in this method would be redundant.
⏰ 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). (2)
- GitHub Check: build
- GitHub Check: Summary
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py (1)
1093-1103: LGTM! The voucher type is now correctly determined based on account type.The logic properly sets "Bank Entry" for bank accounts and "Cash Entry" otherwise. Using
get_cached_valueis efficient.Note that
payment_accountfield lacks explicit validation to restrict it to Bank or Cash account types (unlikepayroll_payable_accountwhich validates account_type). The runtime conditional serves as a defensive fallback, but consider adding field-level validation or a doctype validation method to enforce thatpayment_accountmust be Bank or Cash type.
🧹 Nitpick comments (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py (1)
886-907: Method name is now slightly misleading but functionally correct.The method
has_bank_entriesand its return keyhas_bank_entriesnow also check for "Cash Entry" journal entries. The logic change is correct for the fix, but the naming could be more accurate (e.g.,has_payment_entries).Consider renaming for clarity in a future refactor, though this may require changes to callers.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
hrms/payroll/doctype/payroll_entry/payroll_entry.py(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: asmitahase
Repo: frappe/hrms PR: 3448
File: hrms/hr/doctype/employee_advance/employee_advance.py:109-117
Timestamp: 2025-08-07T11:26:49.671Z
Learning: In the Employee Advance system, `set_total_advance_paid` is only called after advance payment ledger entries are created, which already validates that the account type is either "Receivable" or "Payable". Additional validation for account type in this method would be redundant.
⏰ 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). (3)
- GitHub Check: Python Unit Tests (1)
- GitHub Check: Python Unit Tests (2)
- GitHub Check: Summary
|
Can you check failing tests? |
f3d9929 to
f236fcc
Compare
f236fcc to
a444d53
Compare
@asmitahase |
|
This pull request is being marked as inactive because of no recent activity. It will be closed in 3 days if no further activity occurs. |
|
@asmitahase |
Change was already requested, please check the comments above. |
I have already pushed the commits to fix the failing tests as requested above, and resolved the issue. |
|
This pull request is being marked as inactive because of no recent activity. It will be closed in 3 days if no further activity occurs. |
Incorrect voucher_type assignment
Payroll Entrywas always creating Journal Entries withvoucher_type = "Bank Entry"even when the selectedpayment_accountis a Cash account.The updated logic checks the
account_typeofpayment_accountand sets thevoucher_typeaccordingly (Bank Entry for bank accounts, Cash Entry for cash accounts).backport version-15-hotfix
backport version-16-hotfix
Summary by CodeRabbit
Bug Fixes
Tests