Skip to content

Conversation

@Navin-S-R
Copy link
Member

@Navin-S-R Navin-S-R commented Feb 10, 2026

Issue: Return Delivery Notes are not listed on "Get Items From" (Delivery Note) when creating a Sales Invoice with is_return enabled

Ref: 59697

Steps to Reproduce

  1. Create a Sales Invoice for a customer with update stock unchecked.
  2. Create a Delivery Note against the previously created Sales Invoice.
  3. Create a Sales Return against the previously created Delivery Note.
  4. Create a new Sales Invoice with Is Return checked.
  5. Click Get Items From → Delivery Note.
  6. Observe that the Return Delivery Note does not appear in the list

Before:

Screen.Recording.2026-02-09.at.18.29.33.mov

After:

Screen.Recording.2026-02-09.at.18.33.32.mov

Backport Needed v15

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Feb 10, 2026
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.39%. Comparing base (bf20ecc) to head (462aeb8).
⚠️ Report is 84 commits behind head on develop.

Files with missing lines Patch % Lines
erpnext/controllers/queries.py 20.00% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #52594      +/-   ##
===========================================
- Coverage    79.40%   79.39%   -0.02%     
===========================================
  Files         1168     1168              
  Lines       123222   123327     +105     
===========================================
+ Hits         97850    97912      +62     
- Misses       25372    25415      +43     
Files with missing lines Coverage Δ
erpnext/controllers/queries.py 51.93% <20.00%> (-0.77%) ⬇️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Navin-S-R
Copy link
Member Author

Navin-S-R commented Feb 10, 2026

@CodeRabbit review this

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

@Navin-S-R, I'll review the changes in this pull request.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

This pull request makes two focused changes. In JavaScript, it adds toggle_get_items() and is_return() methods to SalesInvoiceController, centralizing logic to show or remove "Get Items From" buttons based on docstatus, view type, and return state, and adds a customer-required check before mapping Delivery Notes. In Python, get_delivery_notes_to_be_billed() is rewritten from raw SQL to the ORM query builder (qb), adds type hints, introduces an original_dn subquery for return-note handling, applies dynamic filters, and returns results as dicts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: toggling Get Items From button visibility based on is_return and POS view state, which directly addresses the bug fix.
Description check ✅ Passed The pull request description clearly relates to the changeset, describing a specific issue (Return Delivery Notes not appearing in Get Items From picker) with reproduction steps and linking to the support ticket.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

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

🤖 Fix all issues with AI agents
In `@erpnext/accounts/doctype/sales_invoice/sales_invoice.js`:
- Around line 257-272: The toggle_get_items() logic removes the "Delivery Note"
picker on reload when this.frm.doc.is_return is true; to fix, change the else
branch so that when this.frm.doc.is_return is truthy you still invoke
this.frm.cscript.delivery_note_btn() (while still removing Sales
Order/Quotation/Timesheet), otherwise remove all "Get Items From" buttons;
update toggle_get_items() to call delivery_note_btn() in the else-path for
return invoices so the DN picker is present on load.
🧹 Nitpick comments (2)
erpnext/controllers/queries.py (2)

13-13: Coalesce is imported but unused.

The new query builder code in get_delivery_notes_to_be_billed doesn't use Coalesce. Remove it to keep imports clean.

Proposed fix
-from frappe.query_builder.functions import Coalesce, Concat, Locate, Sum
+from frappe.query_builder.functions import Concat, Locate, Sum

399-401: Minor: docstatus filter is applied twice — once in the base query (line 385) and again via dynamic filters.

Not a bug, but worth noting. The base query already filters docstatus == 1, and the JS also passes docstatus: 1 in filters. Consider excluding already-handled keys from the dynamic loop to avoid redundancy, or leave as-is since it's harmless.

@ravibharathi656 ravibharathi656 marked this pull request as ready for review February 10, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant