refactor: use frappe._dict in importers of ItemDetailsCtx

Extend the boundary rule to callers: non-decorated code that built or
annotated with ItemDetailsCtx now uses frappe._dict directly, and drops
the now-unused import. asset_capitalization keeps ItemDetailsCtx for its
own normalize_ctx_input-decorated functions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-07-01 16:30:16 +05:30
parent 9406ec49de
commit e6f8f8f7e9
17 changed files with 40 additions and 45 deletions

View File

@@ -663,7 +663,6 @@ class POSInvoice(SalesInvoice):
def set_pos_fields(self, for_validate=False):
"""Set retail related fields from POS Profiles"""
from erpnext.stock.get_item_details import (
ItemDetailsCtx,
get_pos_profile,
get_pos_profile_item_details_,
)
@@ -736,7 +735,7 @@ class POSInvoice(SalesInvoice):
for item in self.get("items"):
if item.get("item_code"):
profile_details = get_pos_profile_item_details_(
ItemDetailsCtx(item.as_dict()), profile.get("company"), profile
frappe._dict(item.as_dict()), profile.get("company"), profile
)
for fname, val in profile_details.items():
if (not for_validate) or (for_validate and not item.get(fname)):

View File

@@ -126,13 +126,13 @@ class POSService:
doc.update_stock = 0 if dn_flag else cint(pos.get("update_stock"))
def _apply_pos_item_defaults(self, pos, for_validate: bool) -> None:
from erpnext.stock.get_item_details import ItemDetailsCtx, get_pos_profile_item_details_
from erpnext.stock.get_item_details import get_pos_profile_item_details_
for item in self.doc.get("items"):
if not item.get("item_code"):
continue
profile_details = get_pos_profile_item_details_(
ItemDetailsCtx(item.as_dict()), pos, pos, update_data=True
frappe._dict(item.as_dict()), pos, pos, update_data=True
)
for fname, val in profile_details.items():
if (not for_validate) or (for_validate and not item.get(fname)):

View File

@@ -12,7 +12,6 @@ from frappe.utils import cint, flt, parse_json
import erpnext
from erpnext.stock.get_item_details import (
NOT_APPLICABLE_TAX,
ItemDetailsCtx,
_get_item_tax_template,
_get_item_tax_template_from_item_group,
get_item_tax_map,
@@ -350,7 +349,7 @@ def set_balance_in_account_currency(
def set_child_tax_template_and_map(item, child_item, parent_doc) -> None:
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"item_code": item.item_code,
"posting_date": parent_doc.transaction_date,

View File

@@ -500,7 +500,7 @@ def get_target_item_details(item_code: str | None = None, company: str | None =
item_group_defaults = get_item_group_defaults(item.name, company)
brand_defaults = get_brand_defaults(item.name, company)
out.cost_center = get_default_cost_center(
ItemDetailsCtx({"item_code": item.name, "company": company}),
frappe._dict({"item_code": item.name, "company": company}),
item_defaults,
item_group_defaults,
brand_defaults,

View File

@@ -1531,11 +1531,11 @@ class TestPurchaseOrder(ERPNextTestSuite):
(via the standard item lookup the form uses) without going through
the Sales Order → Purchase Order mapping pipeline.
"""
from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details
from erpnext.stock.get_item_details import get_item_details
item = make_item("_Test Drop Ship From Master", {"is_stock_item": 1, "delivered_by_supplier": 1})
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"item_code": item.item_code,
"doctype": "Purchase Order",

View File

@@ -47,7 +47,6 @@ from erpnext.controllers.sales_and_purchase_return import validate_return
from erpnext.setup.utils import get_exchange_rate
from erpnext.stock.doctype.item.item import get_uom_conv_factor
from erpnext.stock.get_item_details import (
ItemDetailsCtx,
get_item_details,
)
from erpnext.utilities.regional import temporary_flag
@@ -782,7 +781,7 @@ class AccountsController(TransactionBase):
for item in self.get("items"):
if item.get("item_code"):
ctx: ItemDetailsCtx = ItemDetailsCtx(parent_dict.copy())
ctx: frappe._dict = frappe._dict(parent_dict.copy())
ctx.update(item.as_dict())
ctx.update(

View File

@@ -25,7 +25,7 @@ from pypika import Order
import erpnext
from erpnext.accounts.utils import build_qb_match_conditions
from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template
from erpnext.stock.get_item_details import _get_item_tax_template
from erpnext.stock.utils import get_combine_datetime
from erpnext.utilities.query import get_filter_conditions_qb
@@ -1056,7 +1056,7 @@ def get_tax_template(doctype: str, txt: str, searchfield: str, start: int, page_
valid_from = filters.get("valid_from")
valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"item_code": filters.get("item_code"),
"posting_date": valid_from,

View File

@@ -21,7 +21,6 @@ from erpnext.controllers.accounts_controller import (
from erpnext.deprecation_dumpster import deprecated
from erpnext.stock.get_item_details import (
NOT_APPLICABLE_TAX,
ItemDetailsCtx,
_get_item_tax_template,
get_item_tax_map,
)
@@ -99,7 +98,7 @@ class calculate_taxes_and_totals:
for item in self.doc.items:
if item.item_code and item.get("item_tax_template"):
item_doc = frappe.get_cached_doc("Item", item.item_code)
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"net_rate": item.net_rate or item.rate,
"base_net_rate": item.base_net_rate or item.base_rate,

View File

@@ -16,7 +16,7 @@ from frappe.website.website_generator import WebsiteGenerator
import erpnext
from erpnext.setup.utils import get_exchange_rate
from erpnext.stock.doctype.item.item import get_item_details
from erpnext.stock.get_item_details import ItemDetailsCtx, get_conversion_factor, get_price_list_rate
from erpnext.stock.get_item_details import get_conversion_factor, get_price_list_rate
form_grid_templates = {"items": "templates/form_grid/item_grid.html"}
@@ -1072,7 +1072,7 @@ def _get_price_list_item_rate(args, bom_doc):
if not bom_doc.buying_price_list:
frappe.throw(_("Please select Price List"))
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"doctype": "BOM",
"price_list": bom_doc.buying_price_list,

View File

@@ -290,7 +290,7 @@ class TestQuotation(ERPNextTestSuite):
def test_gross_profit(self):
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.get_item_details import ItemDetailsCtx, insert_item_price
from erpnext.stock.get_item_details import insert_item_price
item_doc = make_item("_Test Item for Gross Profit", {"is_stock_item": 1})
item_code = item_doc.name
@@ -299,7 +299,7 @@ class TestQuotation(ERPNextTestSuite):
selling_price_list = frappe.get_all("Price List", filters={"selling": 1}, limit=1)[0].name
frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1)
insert_item_price(
ItemDetailsCtx(
frappe._dict(
{
"item_code": item_code,
"price_list": selling_price_list,

View File

@@ -26,7 +26,7 @@ from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry impor
get_sre_reserved_qty_details_for_voucher,
get_ssb_bundle_for_voucher,
)
from erpnext.stock.get_item_details import ItemDetailsCtx, get_bin_details, get_price_list_rate
from erpnext.stock.get_item_details import get_bin_details, get_price_list_rate
def get_requested_item_qty(sales_order: str) -> dict:
@@ -105,7 +105,7 @@ def make_material_request(source_name: str, target_doc: str | Document | None =
target.item_code, target.warehouse, source_parent.company, True
).get("actual_qty", 0)
ctx = ItemDetailsCtx(target.as_dict().copy())
ctx = frappe._dict(target.as_dict().copy())
ctx.update(
{
"company": source_parent.get("company"),

View File

@@ -19,7 +19,7 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle
get_batch_from_bundle,
)
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details
from erpnext.stock.get_item_details import get_item_details
from erpnext.stock.serial_batch_bundle import SerialBatchCreation
from erpnext.tests.utils import ERPNextTestSuite
@@ -595,7 +595,7 @@ class TestBatch(ERPNextTestSuite):
company = "_Test Company with perpetual inventory"
currency = frappe.get_cached_value("Company", company, "default_currency")
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"item_code": "_Test Batch Price Item",
"company": company,

View File

@@ -25,7 +25,7 @@ from erpnext.stock.doctype.item.item import (
validate_is_stock_item,
)
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details
from erpnext.stock.get_item_details import get_item_details
from erpnext.tests.utils import ERPNextTestSuite
@@ -158,7 +158,7 @@ class TestItem(ERPNextTestSuite):
currency = frappe.get_cached_value("Company", company, "default_currency")
details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": "_Test Item",
"company": company,
@@ -188,7 +188,7 @@ class TestItem(ERPNextTestSuite):
create_fixed_asset_item()
details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": "Macbook Pro",
"company": "_Test Company",
@@ -201,7 +201,7 @@ class TestItem(ERPNextTestSuite):
frappe.db.set_value("Asset Category", "Computers", "enable_cwip_accounting", "1")
details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": "Macbook Pro",
"company": "_Test Company",
@@ -291,7 +291,7 @@ class TestItem(ERPNextTestSuite):
for data in expected_item_tax_template:
details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": data["item_code"],
"tax_category": data["tax_category"],
@@ -343,7 +343,7 @@ class TestItem(ERPNextTestSuite):
"cost_center": "_Test Cost Center 2 - _TC", # from item group
}
sales_item_details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": "Test Item With Defaults",
"company": "_Test Company",
@@ -368,7 +368,7 @@ class TestItem(ERPNextTestSuite):
"cost_center": "_Test Write Off Cost Center - _TC", # from item
}
purchase_item_details = get_item_details(
ItemDetailsCtx(
frappe._dict(
{
"item_code": "Test Item With Defaults",
"company": "_Test Company",

View File

@@ -5,7 +5,7 @@
import frappe
from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem
from erpnext.stock.get_item_details import ItemDetailsCtx, get_price_list_rate_for
from erpnext.stock.get_item_details import get_price_list_rate_for
from erpnext.tests.utils import ERPNextTestSuite
@@ -68,7 +68,7 @@ class TestItemPrice(ERPNextTestSuite):
# Check correct price at this quantity
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][2])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"customer": doc.customer,
@@ -84,7 +84,7 @@ class TestItemPrice(ERPNextTestSuite):
def test_price_with_no_qty(self):
# Check correct price when no quantity
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][2])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"customer": doc.customer,
@@ -100,7 +100,7 @@ class TestItemPrice(ERPNextTestSuite):
# Check correct price at first date
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][2])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"customer": "_Test Customer",
@@ -117,7 +117,7 @@ class TestItemPrice(ERPNextTestSuite):
# Check correct price at invalid date
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][3])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"qty": 7,
@@ -133,7 +133,7 @@ class TestItemPrice(ERPNextTestSuite):
# Check correct price when outside of the date
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][4])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"customer": "_Test Customer",
@@ -150,7 +150,7 @@ class TestItemPrice(ERPNextTestSuite):
# Check lowest price when no date provided
doc = frappe.copy_doc(self.globalTestRecords["Item Price"][1])
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"uom": "_Test UOM",
@@ -182,7 +182,7 @@ class TestItemPrice(ERPNextTestSuite):
doc.price_list_rate = 21
doc.insert()
ctx = ItemDetailsCtx(
ctx = frappe._dict(
{
"price_list": doc.price_list,
"uom": "_Test UOM",

View File

@@ -12,7 +12,7 @@ from frappe import _
from frappe.model.document import Document
from frappe.utils import flt
from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details, get_price_list_rate
from erpnext.stock.get_item_details import get_item_details, get_price_list_rate
class PackedItem(Document):
@@ -344,7 +344,7 @@ def update_packed_item_price_data(pi_row, item_data, doc):
return
item_doc = frappe.get_cached_doc("Item", pi_row.item_code)
ctx = ItemDetailsCtx(pi_row.as_dict().copy())
ctx = frappe._dict(pi_row.as_dict().copy())
ctx.update(
{
"company": doc.get("company"),
@@ -442,7 +442,7 @@ def get_items_from_product_bundle(row: str | dict):
"""
from erpnext.selling.doctype.product_bundle.product_bundle import get_active_product_bundle
row, items = ItemDetailsCtx(frappe.parse_json(row)), []
row, items = frappe._dict(frappe.parse_json(row)), []
if bundle_name := row.get("product_bundle"):
frappe.has_permission("Product Bundle", "read", bundle_name, throw=True)

View File

@@ -2148,7 +2148,7 @@ class TestPurchaseReceipt(ERPNextTestSuite):
self.assertEqual(return_pi.docstatus, 1)
def test_disable_last_purchase_rate(self):
from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details
from erpnext.stock.get_item_details import get_item_details
item = make_item(
"_Test Disable Last Purchase Rate",
@@ -2163,7 +2163,7 @@ class TestPurchaseReceipt(ERPNextTestSuite):
item_code=item.name,
)
ctx = ItemDetailsCtx(pr.items[0].as_dict())
ctx = frappe._dict(pr.items[0].as_dict())
ctx.update(
{
"supplier": pr.supplier,

View File

@@ -28,7 +28,6 @@ from erpnext.manufacturing.doctype.bom.bom import (
from erpnext.setup.doctype.brand.brand import get_brand_defaults
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
from erpnext.stock.get_item_details import (
ItemDetailsCtx,
get_barcode_data,
get_bin_details,
get_conversion_factor,
@@ -1189,7 +1188,7 @@ class StockEntry(StockController, SubcontractingInwardController):
return reserved_work_orders
@frappe.whitelist()
def get_item_details(self, args: ItemDetailsCtx | None = None, for_update: bool = False):
def get_item_details(self, args: frappe._dict | None = None, for_update: bool = False):
item = self._fetch_item_data(args)
item_group_defaults = get_item_group_defaults(item.name, self.company)
brand_defaults = get_brand_defaults(item.name, self.company)