Skip to content

Commit daabe84

Browse files
authored
refactor: cleanup args structure akin to some typing (#44226)
* refactor: cleanup args structure akin to some typing this clarification is a human precondition to being able to fix #44219 * chore: excempt previous commit from git blame * fix: adapt signature
1 parent a9bb6b9 commit daabe84

File tree

9 files changed

+468
-400
lines changed

9 files changed

+468
-400
lines changed

.git-blame-ignore-revs

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ ec74a5e56617bbd76ac402451468fd4668af543d
3838

3939
# ruff formatting
4040
a308792ee7fda18a681e9181f4fd00b36385bc23
41+
42+
# noisy typing refactoring of get_item_details
43+
7b7211ac79c248a79ba8a999ff34e734d874c0ae

erpnext/accounts/doctype/pos_invoice/pos_invoice.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def set_status(self, update=False, status=None, update_modified=True):
533533

534534
def set_pos_fields(self, for_validate=False):
535535
"""Set retail related fields from POS Profiles"""
536-
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
536+
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details_
537537

538538
if not self.pos_profile:
539539
pos_profile = get_pos_profile(self.company) or {}
@@ -602,8 +602,8 @@ def set_pos_fields(self, for_validate=False):
602602
# set pos values in items
603603
for item in self.get("items"):
604604
if item.get("item_code"):
605-
profile_details = get_pos_profile_item_details(
606-
profile.get("company"), frappe._dict(item.as_dict()), profile
605+
profile_details = get_pos_profile_item_details_(
606+
frappe._dict(item.as_dict()), profile.get("company"), profile
607607
)
608608
for fname, val in profile_details.items():
609609
if (not for_validate) or (for_validate and not item.get(fname)):

erpnext/accounts/doctype/sales_invoice/sales_invoice.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def set_pos_fields(self, for_validate=False):
766766
"Company", self.company, "default_cash_account"
767767
)
768768

769-
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
769+
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details_
770770

771771
if not self.pos_profile and not self.flags.ignore_pos_profile:
772772
pos_profile = get_pos_profile(self.company) or {}
@@ -834,8 +834,8 @@ def set_pos_fields(self, for_validate=False):
834834
# set pos values in items
835835
for item in self.get("items"):
836836
if item.get("item_code"):
837-
profile_details = get_pos_profile_item_details(
838-
pos, frappe._dict(item.as_dict()), pos, update_data=True
837+
profile_details = get_pos_profile_item_details_(
838+
frappe._dict(item.as_dict()), pos, pos, update_data=True
839839
)
840840
for fname, val in profile_details.items():
841841
if (not for_validate) or (for_validate and not item.get(fname)):

erpnext/assets/doctype/asset_capitalization/asset_capitalization.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from erpnext.stock.get_item_details import (
2929
get_default_cost_center,
3030
get_default_expense_account,
31-
get_item_warehouse,
31+
get_item_warehouse_,
3232
)
3333
from erpnext.stock.stock_ledger import get_previous_sle
3434
from erpnext.stock.utils import get_incoming_rate
@@ -785,11 +785,11 @@ def get_target_asset_details(asset=None, company=None):
785785

786786

787787
@frappe.whitelist()
788-
def get_consumed_stock_item_details(args):
789-
if isinstance(args, str):
790-
args = json.loads(args)
788+
def get_consumed_stock_item_details(args_):
789+
if isinstance(args_, str):
790+
args_ = json.loads(args_)
791791

792-
args = frappe._dict(args)
792+
args = frappe._dict(args_)
793793
out = frappe._dict()
794794

795795
item = frappe._dict()
@@ -803,7 +803,7 @@ def get_consumed_stock_item_details(args):
803803
out.stock_qty = flt(args.stock_qty) or 1
804804
out.stock_uom = item.stock_uom
805805

806-
out.warehouse = get_item_warehouse(item, args, overwrite_warehouse=True) if item else None
806+
out.warehouse = get_item_warehouse_(args, item, overwrite_warehouse=True) if item else None
807807

808808
# Cost Center
809809
item_defaults = get_item_defaults(item.name, args.company)

erpnext/controllers/accounts_controller.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
get_conversion_factor,
6767
get_item_details,
6868
get_item_tax_map,
69-
get_item_warehouse,
69+
get_item_warehouse_,
7070
)
7171
from erpnext.utilities.regional import temporary_flag
7272
from erpnext.utilities.transaction_base import TransactionBase
@@ -3218,7 +3218,7 @@ def set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child
32183218
child_item.update({date_fieldname: trans_item.get(date_fieldname) or p_doc.get(date_fieldname)})
32193219
child_item.stock_uom = item.stock_uom
32203220
child_item.uom = trans_item.get("uom") or item.stock_uom
3221-
child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True)
3221+
child_item.warehouse = get_item_warehouse_(p_doc, item, overwrite_warehouse=True)
32223222
conversion_factor = flt(get_conversion_factor(item.item_code, child_item.uom).get("conversion_factor"))
32233223
child_item.conversion_factor = flt(trans_item.get("conversion_factor")) or conversion_factor
32243224

@@ -3227,7 +3227,7 @@ def set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child
32273227
child_item.base_rate = 1
32283228
child_item.base_amount = 1
32293229
if child_doctype == "Sales Order Item":
3230-
child_item.warehouse = get_item_warehouse(item, p_doc, overwrite_warehouse=True)
3230+
child_item.warehouse = get_item_warehouse_(p_doc, item, overwrite_warehouse=True)
32313231
if not child_item.warehouse:
32323232
frappe.throw(
32333233
_(

erpnext/deprecation_dumpster.py

+24
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,27 @@ def taxes_and_totals_get_itemised_taxable_amount(items):
125125
itemised_taxable_amount[item_code] += item.net_amount
126126

127127
return itemised_taxable_amount
128+
129+
130+
@deprecated(
131+
"erpnext.stock.get_pos_profile_item_details",
132+
"2024-11-19",
133+
"v16",
134+
"Use erpnext.stock.get_pos_profile_item_details_ with a flipped signature",
135+
)
136+
def get_pos_profile_item_details(company, ctx, pos_profile=None, update_data=False):
137+
from erpnext.stock.get_item_details import get_pos_profile_item_details_
138+
139+
return get_pos_profile_item_details_(ctx, company, pos_profile=pos_profile, update_data=update_data)
140+
141+
142+
@deprecated(
143+
"erpnext.stock.get_item_warehouse",
144+
"2024-11-19",
145+
"v16",
146+
"Use erpnext.stock.get_item_warehouse_ with a flipped signature",
147+
)
148+
def get_item_warehouse(item, ctx, overwrite_warehouse, defaults=None):
149+
from erpnext.stock.get_item_details import get_item_warehouse_
150+
151+
return get_item_warehouse_(ctx, item, overwrite_warehouse, defaults=defaults)

erpnext/selling/doctype/sales_order/sales_order.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def update_item(source, target, source_parent):
860860
)
861861

862862
target.rate = flt(
863-
get_price_list_rate(args=args, item_doc=frappe.get_cached_doc("Item", target.item_code)).get(
863+
get_price_list_rate(args, item_doc=frappe.get_cached_doc("Item", target.item_code)).get(
864864
"price_list_rate"
865865
)
866866
)

erpnext/stock/doctype/item_price/test_item_price.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from frappe.tests.utils import make_test_records_for_doctype
88

99
from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem
10-
from erpnext.stock.get_item_details import get_price_list_rate_for, process_args
10+
from erpnext.stock.get_item_details import get_price_list_rate_for
1111

1212

1313
class UnitTestItemPrice(UnitTestCase):
@@ -88,7 +88,7 @@ def test_price_in_a_qty(self):
8888
"qty": 10,
8989
}
9090

91-
price = get_price_list_rate_for(process_args(args), doc.item_code)
91+
price = get_price_list_rate_for(args, doc.item_code)
9292
self.assertEqual(price, 20.0)
9393

9494
def test_price_with_no_qty(self):

0 commit comments

Comments
 (0)