Skip to content

fix: after mapping of stock entry map correct addresses and gstin#3998

Open
karm1000 wants to merge 7 commits intoresilient-tech:developfrom
karm1000:fix/after-mapping-stock-entry
Open

fix: after mapping of stock entry map correct addresses and gstin#3998
karm1000 wants to merge 7 commits intoresilient-tech:developfrom
karm1000:fix/after-mapping-stock-entry

Conversation

@karm1000
Copy link
Copy Markdown
Member

depends on: frappe/erpnext#52724

@karm1000 karm1000 requested a review from ljain112 February 17, 2026 12:12
@karm1000 karm1000 marked this pull request as ready for review February 25, 2026 11:58
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 25, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces hardcoded checks in after_mapping_stock_entry with unconditional calls to set_item_tax_template(doc, source_doc) and _get_fields_mapping(doc, source_doc), early-returning if no mapping. Uses the returned mapping to assign doc.bill_from_address, doc.bill_from_gstin, doc.bill_to_address, and doc.bill_to_gstin from the source and calls set_address_display(doc). Adds _get_fields_mapping(doc, source_doc) to determine source field mappings for Subcontracting Order, Purchase Receipt, and Stock Entry (including Material Transfer cases) and adds set_item_tax_template(doc, source_doc) to copy item_tax_template from source items to target items.

🚥 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 describes the main change: fixing address and GSTIN mapping after stock entry mapping.
Description check ✅ Passed The description mentions a dependency on a related pull request, which is relevant context for the changeset.

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


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
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@india_compliance/gst_india/overrides/subcontracting_transaction.py`:
- Around line 99-121: The Stock Entry branch currently returns the generic
from_fields/to_fields tuple (billing_address/company_gstin →
supplier_address/supplier_gstin) which don't exist on Stock Entry; update the
branch where source_doc.doctype == "Stock Entry" (the conditional that checks
doc.purpose == "Material Transfer" and not doc.is_return) to return Stock
Entry-specific keys: ("bill_from_address", "bill_from_gstin") as the from side
and ("bill_to_address", "bill_to_gstin") as the to side (leave the other
branches unchanged).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22e442e and e864efd.

📒 Files selected for processing (1)
  • india_compliance/gst_india/overrides/subcontracting_transaction.py

@karm1000 karm1000 force-pushed the fix/after-mapping-stock-entry branch from ce26838 to 78be8d3 Compare March 12, 2026 08:00
Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
india_compliance/gst_india/overrides/subcontracting_transaction.py (1)

117-122: ⚠️ Potential issue | 🟠 Major

Stock Entry branch uses incorrect field names.

This issue was previously flagged. When source_doc.doctype == "Stock Entry", the function returns ("billing_address", "company_gstin") and ("supplier_address", "supplier_gstin"), but Stock Entry uses bill_from_address, bill_from_gstin, bill_to_address, and bill_to_gstin fields. This will cause source_doc.get() to return None for all address/GSTIN fields.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@india_compliance/gst_india/overrides/subcontracting_transaction.py` around
lines 117 - 122, In the branch that checks source_doc.doctype == "Stock Entry"
(inside the function handling subcontracting transactions when doc.purpose ==
"Material Transfer" and not doc.is_return), replace the returned field-name
tuples so they reference Stock Entry field names: return from_fields as
("bill_from_address", "bill_from_gstin") and to_fields as ("bill_to_address",
"bill_to_gstin") instead of the current ("billing_address","company_gstin") /
("supplier_address","supplier_gstin"); update the return statement that
currently returns from_fields, to_fields accordingly so subsequent
source_doc.get(...) calls retrieve the correct address/GSTIN values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@india_compliance/gst_india/overrides/subcontracting_transaction.py`:
- Around line 127-147: The function set_item_tax_template contains a dead
Purchase Order branch and will raise AttributeError when source_doc lacks
supplied_items; remove the dead check for "Purchase Order" and add a doctype
guard before iterating source_doc.supplied_items (only Subcontracting Order has
supplied_items per _get_fields_mapping). Update logic in set_item_tax_template
to: if source_doc.doctype == "Subcontracting Order" (or hasattr(source_doc,
"supplied_items")) iterate supplied_items to build item_tax_template_map,
otherwise fall back to using source_doc.items (or another appropriate field for
Purchase Receipt/Stock Entry) when resolving item.item_tax_template via
rm_detail_field so the function safely handles all valid source doctypes.

---

Duplicate comments:
In `@india_compliance/gst_india/overrides/subcontracting_transaction.py`:
- Around line 117-122: In the branch that checks source_doc.doctype == "Stock
Entry" (inside the function handling subcontracting transactions when
doc.purpose == "Material Transfer" and not doc.is_return), replace the returned
field-name tuples so they reference Stock Entry field names: return from_fields
as ("bill_from_address", "bill_from_gstin") and to_fields as ("bill_to_address",
"bill_to_gstin") instead of the current ("billing_address","company_gstin") /
("supplier_address","supplier_gstin"); update the return statement that
currently returns from_fields, to_fields accordingly so subsequent
source_doc.get(...) calls retrieve the correct address/GSTIN values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02b43948-4f6a-488c-b9da-5227ea9318e9

📥 Commits

Reviewing files that changed from the base of the PR and between e864efd and 78be8d3.

📒 Files selected for processing (1)
  • india_compliance/gst_india/overrides/subcontracting_transaction.py

@ljain112
Copy link
Copy Markdown
Member

@greptileai

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 16, 2026

Confidence Score: 2/5

  • Not safe to merge — two logic bugs can silently null out item tax templates on newly mapped Stock Entries.
  • The address/GSTIN mapping logic itself looks correct for the handled paths, but the unconditional null-assignment in the second loop of set_item_tax_template is a clear data-corruption risk, and the changed call order introduces an unintended behavioural regression for the SCO "Material Transfer" (non-return) case. Both issues affect the document being saved and are not caught by any visible guard.
  • india_compliance/gst_india/overrides/subcontracting_transaction.py — specifically lines 83 and 156-157 inside the new set_item_tax_template function.

Important Files Changed

Filename Overview
india_compliance/gst_india/overrides/subcontracting_transaction.py Adds _get_fields_mapping and set_item_tax_template helpers and reworks after_mapping_stock_entry to correctly handle address/GSTIN propagation for multiple source doctypes. Contains a destructive null-assignment bug in the second loop of set_item_tax_template and a behavioral regression for the SCO → Material Transfer (non-return) case.

Reviews (3): Last reviewed commit: "fix: correct field mapping for addresses..." | Re-trigger Greptile

Copy link
Copy Markdown

@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.

♻️ Duplicate comments (2)
india_compliance/gst_india/overrides/subcontracting_transaction.py (2)

99-123: ⚠️ Potential issue | 🟠 Major

Use Stock Entry field names in the Stock Entry branch.

When source_doc.doctype == "Stock Entry", this still returns the generic billing_address/company_gstinsupplier_address/supplier_gstin pair. Stock Entry uses bill_from_* / bill_to_* in this file, so Lines 90-93 will read None and wipe the mapped address/GSTIN values on Stock Entry-to-Stock Entry transfers.

💡 Suggested fix
 def _get_fields_mapping(doc, source_doc):
     from_fields = ("billing_address", "company_gstin")
     to_fields = ("supplier_address", "supplier_gstin")
+    stock_entry_from_fields = ("bill_from_address", "bill_from_gstin")
+    stock_entry_to_fields = ("bill_to_address", "bill_to_gstin")
@@
     elif (
         source_doc.doctype == "Stock Entry"
         and doc.purpose == "Material Transfer"
         and not doc.is_return
     ):
-        return from_fields, to_fields
+        return stock_entry_from_fields, stock_entry_to_fields

127-153: ⚠️ Potential issue | 🟠 Major

set_item_tax_template() skips two source doctypes this hook already supports.

_get_fields_mapping() explicitly handles Purchase Receipt and Stock Entry, but Lines 128-129 return before any item-tax mapping for those flows. That means address/GSTIN mapping succeeds while item.item_tax_template stays unset on the same mapped Stock Entry, which can skew later GST tax mapping. The remaining Purchase Order branch also no longer matches the source doctypes accepted above.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35f02f80-7524-4c77-a664-3dd17ac66049

📥 Commits

Reviewing files that changed from the base of the PR and between 78be8d3 and d0b8c1d.

📒 Files selected for processing (1)
  • india_compliance/gst_india/overrides/subcontracting_transaction.py

@ljain112
Copy link
Copy Markdown
Member

@Mergifyio rebase

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 25, 2026

rebase

✅ Branch has been successfully rebased

@ljain112 ljain112 force-pushed the fix/after-mapping-stock-entry branch from d722b57 to 0d1a439 Compare March 25, 2026 05:50
@ljain112
Copy link
Copy Markdown
Member

@greptileai

Comment on lines +156 to +157
for item in doc.items:
item.item_tax_template = item_tax_template_map.get(item.get(rm_detail_field))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Second loop silently nulls out unmatched item tax templates

item_tax_template_map is only populated for supplied items whose corresponding source order item actually has an item_tax_template set (line 153 guards with if item_tax_template:). For every doc.items row whose sco_rm_detail either doesn't match any key in the map or whose source item had no template, the assignment unconditionally writes None, destroying whatever template the mapping process may have already placed on the item.

Consider only overwriting when a real value is found:

    for item in doc.items:
        template = item_tax_template_map.get(item.get(rm_detail_field))
        if template:
            item.item_tax_template = template

This preserves any template that was already correctly set on items that lack a lookup match.

@ljain112
Copy link
Copy Markdown
Member

@karm1000

Add test cases for both issues.

@ljain112
Copy link
Copy Markdown
Member

ljain112 commented Apr 1, 2026

@karm1000 rebase

@karm1000
Copy link
Copy Markdown
Member Author

karm1000 commented Apr 2, 2026

@Mergifyio rebase

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 2, 2026

rebase

✅ Branch has been successfully rebased

@karm1000 karm1000 force-pushed the fix/after-mapping-stock-entry branch from fbc71fe to 0cd0f19 Compare April 2, 2026 07:19
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 25 complexity

Metric Results
Complexity 25

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

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.

2 participants