Skip to content

Conversation

venkat102
Copy link
Contributor

Issue:
The Accounts Receivable report shows the Expense Claim and Payment Entries made against the Employee Advance.

ref: 47589

Before:

employee-advance-accounts-receivable-issue.mp4

After:

employee-advance-accounts-receivable-fix.mp4

Backport needed for v15

@github-actions github-actions bot added accounts needs-tests This PR needs automated unit-tests. labels Sep 3, 2025
Copy link

coderabbitai bot commented Sep 3, 2025

📝 Walkthrough

Walkthrough

  • Adds a new Check filter handle_employee_advances to the Accounts Receivable report UI.
  • Modifies get_party_type_options in the same report to use an or_filters query allowing Party Type options with name "Employee" or account_type "Receivable".
  • Updates get_payment_ledger_entries in erpnext/accounts/utils.py to refine selection of against_voucher_type and against_voucher_no:
    • Prefer gle.against_voucher_* when present.
    • If against_voucher equals the current voucher and an advance voucher exists, map against fields to advance_voucher_type/no.
    • Otherwise, fall back to current voucher_type/no when against_voucher is absent.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

needs-tests

Suggested reviewers

  • ruthra-kumar
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
erpnext/accounts/report/accounts_receivable/accounts_receivable.js (1)

43-54: Autocomplete options are populated asynchronously but returned synchronously → empty options at runtime

get_party_type_options() returns [] immediately and fills later via Promise; the filter won’t reliably update. Populate options onload and refresh the filter, and use correct or_filters syntax.

Apply the following diff:

@@
 		{
 			fieldname: "party_type",
 			label: __("Party Type"),
-			fieldtype: "Autocomplete",
-			options: get_party_type_options(),
+			fieldtype: "Autocomplete",
+			options: [],
 			on_change: function () {
 				frappe.query_report.set_filter_value("party", "");
 				frappe.query_report.toggle_filter_display(
 					"customer_group",
 					frappe.query_report.get_filter_value("party_type") !== "Customer"
 				);
 			},
 		},
@@
-	onload: function (report) {
+	onload: function (report) {
 		report.page.add_inner_button(__("Accounts Receivable Summary"), function () {
 			var filters = report.get_values();
 			frappe.set_route("query-report", "Accounts Receivable Summary", { company: filters.company });
 		});
+		// Populate Party Types: include "Employee" OR account_type "Receivable"
+		populate_party_type_options(report);
 	},
@@
-function get_party_type_options() {
-	let options = [];
-	frappe.db
-		.get_list("Party Type", {
-			or_filters: { name: "Employee", account_type: "Receivable" },
-			fields: ["name"],
-		})
-		.then((res) => {
-			res.forEach((party_type) => {
-				options.push(party_type.name);
-			});
-		});
-	return options;
-}
+function populate_party_type_options(report) {
+	frappe.db
+		.get_list("Party Type", {
+			filters: [["account_type", "=", "Receivable"]],
+			or_filters: [["name", "=", "Employee"]],
+			fields: ["name"],
+			limit: 0,
+		})
+		.then((res) => {
+			const options = res.map((r) => r.name);
+			const f = report.get_filter("party_type");
+			f.df.options = options;
+			f.refresh();
+			// Sensible default
+			if (!f.get_value() && options.includes("Customer")) {
+				frappe.query_report.set_filter_value("party_type", "Customer");
+			}
+		});
+}

This guarantees options load correctly and keeps the intent of including Employee even if its Party Type isn’t Receivable.

Also applies to: 198-204, 208-221

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fba16ef and 31907a5.

📒 Files selected for processing (2)
  • erpnext/accounts/report/accounts_receivable/accounts_receivable.js (2 hunks)
  • erpnext/accounts/utils.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). (6)
  • GitHub Check: Summary
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Patch Test
🔇 Additional comments (2)
erpnext/accounts/utils.py (1)

1850-1859: Confirm Advance PLE event semantics after remap (Submit vs Adjustment)

After remapping against_voucher_type/no away from the self-voucher, get_advance_ledger_entry() will classify the Advance PLE event as "Adjustment" (not "Submit"). Please confirm this is intended for Employee Advance flows; otherwise, compute event based on the original GLE condition (gle.against_voucher == gle.voucher_no) or pass an explicit event flag from caller.

I can draft a safe change that derives event from GLE-only fields if you want to keep "Submit" for initial advance booking and "Adjustment" only for later applications.

Also applies to: 1902-1919

erpnext/accounts/report/accounts_receivable/accounts_receivable.js (1)

183-187: New “Handle Employee Advances” filter looks fine—ensure it’s actually used server-side

UI addition is clear. Please verify the report script consumes handle_employee_advances and toggles logic accordingly; otherwise it will be a no-op for users.

If it isn’t wired, I can propose the minimal server change to gate the new behavior behind this flag.

Comment on lines +211 to +214
.get_list("Party Type", {
or_filters: { name: "Employee", account_type: "Receivable" },
fields: ["name"],
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

or_filters shape is invalid here; use array-of-conditions, not an object

frappe.db.get_list expects or_filters as an array (e.g., [["name","=","Employee"], ["account_type","=","Receivable"]]). Passing an object will not OR the clauses and may be ignored.

Apply this fix as part of the broader patch below.

🤖 Prompt for AI Agents
In erpnext/accounts/report/accounts_receivable/accounts_receivable.js around
lines 211 to 214, the call to frappe.db.get_list uses or_filters as an object
which is invalid; change or_filters to an array-of-conditions like
[["name","=","Employee"], ["account_type","=","Receivable"]]. Update the
get_list invocation to pass or_filters: [ ["name","=","Employee"],
["account_type","=","Receivable"] ] so the two clauses are properly ORed and the
query returns expected rows.

Comment on lines +1850 to +1859
against_voucher_type = gle.against_voucher_type
against_voucher_no = gle.against_voucher

if gle.against_voucher:
if gle.against_voucher == gle.voucher_no and gle.advance_voucher_no:
against_voucher_type = gle.advance_voucher_type
against_voucher_no = gle.advance_voucher_no
else:
against_voucher_type = gle.voucher_type
against_voucher_no = gle.voucher_no
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Guard against partial advance fields to avoid None against_voucher_type in PLE

Good call mapping self-referencing GLEs to their advance voucher. Add a tight guard to only remap when both advance_voucher_type and advance_voucher_no exist; otherwise we risk writing a PLE row with a null against_voucher_type which can break downstream filters and reconciliation.

Apply this minimal patch:

-				if gle.against_voucher:
-					if gle.against_voucher == gle.voucher_no and gle.advance_voucher_no:
-						against_voucher_type = gle.advance_voucher_type
-						against_voucher_no = gle.advance_voucher_no
+				if gle.against_voucher:
+					if (
+						gle.against_voucher == gle.voucher_no
+						and gle.advance_voucher_type
+						and gle.advance_voucher_no
+					):
+						against_voucher_type = gle.advance_voucher_type
+						against_voucher_no = gle.advance_voucher_no
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
against_voucher_type = gle.against_voucher_type
against_voucher_no = gle.against_voucher
if gle.against_voucher:
if gle.against_voucher == gle.voucher_no and gle.advance_voucher_no:
against_voucher_type = gle.advance_voucher_type
against_voucher_no = gle.advance_voucher_no
else:
against_voucher_type = gle.voucher_type
against_voucher_no = gle.voucher_no
against_voucher_type = gle.against_voucher_type
against_voucher_no = gle.against_voucher
if gle.against_voucher:
if (
gle.against_voucher == gle.voucher_no
and gle.advance_voucher_type
and gle.advance_voucher_no
):
against_voucher_type = gle.advance_voucher_type
against_voucher_no = gle.advance_voucher_no
else:
against_voucher_type = gle.voucher_type
against_voucher_no = gle.voucher_no
🤖 Prompt for AI Agents
In erpnext/accounts/utils.py around lines 1850 to 1859, the current logic remaps
against_voucher_type/against_voucher_no when gle.against_voucher equals
gle.voucher_no and gle.advance_voucher_no exists, which can leave
against_voucher_type as None; update the guard so the remap only occurs when
both gle.advance_voucher_type and gle.advance_voucher_no are truthy (i.e., check
both fields before assigning advance_voucher_type and advance_voucher_no),
leaving the else branch unchanged.

@ruthra-kumar ruthra-kumar self-assigned this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accounts needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants