Skip to content

Conversation

anwarpatelnoori
Copy link
Contributor

@anwarpatelnoori anwarpatelnoori commented Sep 8, 2025

Closes #49499

Please provide enough information so that others can review your pull request:

  • In Landed Cost Voucher DocTyep, selected company filters are not applied for Purchase Invoice , Purchase Receipt
Image
  • Additionally cancelled documents are also listing
Image

Explain the details for making this change. What existing problem does the pull request solve?

  • To list the selected company documents and which are not cancelled
  • I have removed the StockController setup controller code, because it is redundant and filters are directly applied in the setup controller of the current doc

Screenshots with correct filters

image

Copy link

coderabbitai bot commented Sep 8, 2025

📝 Walkthrough

Walkthrough

The change refactors receipt_document query logic in erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js. It removes the LandedCostVoucher.setup() method and introduces dynamic filter construction in setup_queries for the receipt_document field. Filters now always include docstatus=1 and company for the selected receipt_document_type. Additional filters are applied per type: Purchase Invoice requires update_stock=1; Stock Entry restricts purpose to Manufacture or Repack.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Apply selected company filter to Purchase Invoice and Purchase Receipt in LCV voucher child table (#49499)
Exclude cancelled documents from listing in voucher child table (#49499)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Added Stock Entry-specific filter: purpose in ["Manufacture","Repack"] (erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js) Issue #49499 only mentions Purchase Invoice and Purchase Receipt filtering and cancellation; Stock Entry filtering is not specified in the issue.

Suggested labels

backport version-15-hotfix

Suggested reviewers

  • rohitwaghchaure
  • mihir-kandoi
✨ 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

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

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: 0

🧹 Nitpick comments (3)
erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (3)

137-143: Use numeric literals for Int/Check fields (docstatus, update_stock)

Avoid string comparisons against integer fields. Use 1 instead of "1".

-  [d.receipt_document_type, "docstatus", "=", "1"],
+  [d.receipt_document_type, "docstatus", "=", 1],
...
-  filters.push(["Purchase Invoice", "update_stock", "=", "1"]);
+  filters.push(["Purchase Invoice", "update_stock", "=", 1]);

141-145: Consistency: use strict equality for both branches

Minor consistency/readability tweak.

- if (d.receipt_document_type == "Purchase Invoice") {
+ if (d.receipt_document_type === "Purchase Invoice") {

135-140: Guard when type/company is not set to avoid ambiguous queries

When the row is new or company/type isn’t chosen yet, the current code builds filters with undefined doctype. Return an empty filter set early.

- var d = locals[cdt][cdn];
- var filters = [
+ const d = locals[cdt][cdn];
+ if (!d.receipt_document_type || !frm.doc.company) {
+   return { filters: [] };
+ }
+ const filters = [
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ddc97df and 486507e.

📒 Files selected for processing (1)
  • erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (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
🔇 Additional comments (2)
erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (2)

136-149: LGTM: Filters now correctly scope by company and exclude cancelled docs

This aligns with the bugfix objective: only submitted (docstatus=1) docs from the selected company are listed; PIs additionally need update_stock=1.


143-145: I’ve started extracting the valid purpose options for Stock Entry to verify if “Material Receipt” should be included.

@anwarpatelnoori
Copy link
Contributor Author

@mihir-kandoi

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: 0

🧹 Nitpick comments (4)
erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (4)

135-139: Guard when type/company aren’t selected to avoid malformed queries.

If the row opens before selecting receipt_document_type or company, the first two filters will use an undefined doctype/value. Add a short-circuit.

 frm.set_query("receipt_document", "purchase_receipts", (doc, cdt, cdn) => {
   var d = locals[cdt][cdn];
+  if (!d.receipt_document_type || !frm.doc.company) {
+    // No results until prerequisites are set
+    return { filters: [["name", "=", ""]] };
+  }
   var filters = [
     [d.receipt_document_type, "docstatus", "=", 1],
     [d.receipt_document_type, "company", "=", frm.doc.company],
   ];

141-145: Consider excluding returns for PR/PI.

Typically landed costs shouldn’t be applied to return documents. If aligned with product behavior, add is_return=0 for PR/PI.

   if (d.receipt_document_type === "Purchase Invoice") {
     filters.push(["Purchase Invoice", "update_stock", "=", 1]);
+    filters.push(["Purchase Invoice", "is_return", "=", 0]);
   } else if (d.receipt_document_type === "Stock Entry") {
     filters.push(["Stock Entry", "purpose", "in", ["Manufacture", "Repack"]]);
+  } else if (d.receipt_document_type === "Purchase Receipt") {
+    filters.push(["Purchase Receipt", "is_return", "=", 0]);
   }

136-139: Nit: prefer const and shorthand return.

Minor readability/consistency tidy-up if ESLint/style permits.

-  var filters = [
+  const filters = [
     [d.receipt_document_type, "docstatus", "=", 1],
     [d.receipt_document_type, "company", "=", frm.doc.company],
   ];
 ...
-  return {
-    filters: filters,
-  };
+  return { filters };

Also applies to: 146-148


146-148: Defense-in-depth: validate on the server.

Even with client-side filters, ensure the server methods (e.g., get_receipt_document_details, get_items_from_purchase_receipts) re-validate that docstatus=1 and company matches the LCV.

Happy to draft the backend checks if you want.

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 486507e and 7978dfe.

📒 Files selected for processing (1)
  • erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (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
🔇 Additional comments (2)
erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js (2)

136-148: Good fix: enforce submitted-only and company-scoped results; PI/SE-specific constraints look right.

This should stop cancelled docs (docstatus=2) and cross-company records from appearing; PI update_stock=1 is correctly enforced.


141-145: Double-check Stock Entry purposes.

Confirm that Landed Cost Voucher is intended to include Stock Entries only for Manufacture/Repack in v15; some setups use Material Receipt for freight capitalization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect filters in Voucher Child Table of Land Cost Voucher DocType
1 participant