Skip to content

perf: filter by company in get_returned_invoice_items - #59204

Open
Shllokkk wants to merge 2 commits into
frappe:version-16-hotfixfrom
Shllokkk:fix-gp-returned-invoices-company-filter
Open

Shllokkk wants to merge 2 commits into
frappe:version-16-hotfixfrom
Shllokkk:fix-gp-returned-invoices-company-filter

Conversation

@Shllokkk

@Shllokkk Shllokkk commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Manual backport of #59198.

Adds a company filter to get_returned_invoice_items so the Gross Profit report fetches sales returns only for the selected company, instead of loading every company's returns in the date range.

Stacked on #59203 — merge that first.

@github-actions github-actions Bot added the needs-tests This PR needs automated unit-tests. label Sep 20, 2026
@greptile-apps

greptile-apps Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The latest changes appear safe to merge, although the existing non-blocking concern about the company filter changing MariaDB row counts remains outstanding.

Reviews (2) · Last reviewed commit: "perf: filter by company in get_returned_..."

Comment on lines +756 to +757
if self.filters.company:
query = query.where(si.company == self.filters.company)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Company Filter Changes Rows

When a company is selected, this new predicate excludes returned invoices from other companies that the previous query included. This changes the MariaDB row count and violates the repository directive that changed database queries must preserve MariaDB values and row counts, even when the narrower result appears more appropriate. This repository requirement must be satisfied before merging.

Context Used: ERPNext runs on both MariaDB and PostgreSQL from one codebase, but the PostgreSQL test job is label-gated and may not run on this PR, so review every new or changed database query (raw frappe.db.sql, frappe.qb, frappe.get_all/get_list/get_value, and ... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: erpnext/accounts/report/gross_profit/gross_profit.py
Line: 756-757

Comment:
**Company Filter Changes Rows**

When a company is selected, this new predicate excludes returned invoices from other companies that the previous query included. This changes the MariaDB row count and violates the repository directive that changed database queries must preserve MariaDB values and row counts, even when the narrower result appears more appropriate. This repository requirement must be satisfied before merging.

**Context Used:** ERPNext runs on both MariaDB and PostgreSQL from one codebase, but the PostgreSQL test job is label-gated and may not run on this PR, so review every new or changed database query (raw frappe.db.sql, frappe.qb, frappe.get_all/get_list/get_value, and ... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport version-15-hotfix needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant