refactor(treewide): formatting and ruff fixes, + manually enabled F401
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index d09282d..ee2f9cb 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -156,19 +156,14 @@
def update_bin_details(args, out, doc):
- if (
- args.get("doctype") == "Material Request"
- and args.get("material_request_type") == "Material Transfer"
- ):
+ if args.get("doctype") == "Material Request" and args.get("material_request_type") == "Material Transfer":
out.update(get_bin_details(args.item_code, args.get("from_warehouse")))
elif out.get("warehouse"):
company = args.company if (doc and doc.get("doctype") == "Purchase Order") else None
# calculate company_total_stock only for po
- bin_details = get_bin_details(
- args.item_code, out.warehouse, company, include_child_warehouses=True
- )
+ bin_details = get_bin_details(args.item_code, out.warehouse, company, include_child_warehouses=True)
out.update(bin_details)
@@ -274,9 +269,7 @@
if not item:
item = frappe.get_doc("Item", args.get("item_code"))
- if (
- item.variant_of and not item.taxes and frappe.db.exists("Item Tax", {"parent": item.variant_of})
- ):
+ if item.variant_of and not item.taxes and frappe.db.exists("Item Tax", {"parent": item.variant_of}):
item.update_template_tables()
item_defaults = get_item_defaults(item.name, args.company)
@@ -321,9 +314,7 @@
# Set stock UOM in args, so that it can be used while fetching item price
args.stock_uom = item.stock_uom
- if args.get("batch_no") and item.name != frappe.get_cached_value(
- "Batch", args.get("batch_no"), "item"
- ):
+ if args.get("batch_no") and item.name != frappe.get_cached_value("Batch", args.get("batch_no"), "item"):
args["batch_no"] = ""
out = frappe._dict(
@@ -344,9 +335,7 @@
"provisional_expense_account": get_provisional_account(
args, item_defaults, item_group_defaults, brand_defaults
),
- "cost_center": get_default_cost_center(
- args, item_defaults, item_group_defaults, brand_defaults
- ),
+ "cost_center": get_default_cost_center(args, item_defaults, item_group_defaults, brand_defaults),
"has_serial_no": item.has_serial_no,
"has_batch_no": item.has_batch_no,
"batch_no": args.get("batch_no"),
@@ -372,9 +361,7 @@
if args.get("doctype") in ["Sales Order", "Sales Invoice"]
else 0,
"is_fixed_asset": item.is_fixed_asset,
- "last_purchase_rate": item.last_purchase_rate
- if args.get("doctype") in ["Purchase Order"]
- else 0,
+ "last_purchase_rate": item.last_purchase_rate if args.get("doctype") in ["Purchase Order"] else 0,
"transaction_date": args.get("transaction_date"),
"against_blanket_order": args.get("against_blanket_order"),
"bom_no": item.get("default_bom"),
@@ -510,9 +497,7 @@
itemwise_barcode = {}
for item in items_list:
- barcodes = frappe.db.get_all(
- "Item Barcode", filters={"parent": item.item_code}, fields="barcode"
- )
+ barcodes = frappe.db.get_all("Item Barcode", filters={"parent": item.item_code}, fields="barcode")
for barcode in barcodes:
if item.item_code not in itemwise_barcode:
@@ -532,13 +517,13 @@
if item_rates is None:
item_rates = {}
- if isinstance(item_codes, (str,)):
+ if isinstance(item_codes, str):
item_codes = json.loads(item_codes)
- if isinstance(item_rates, (str,)):
+ if isinstance(item_rates, str):
item_rates = json.loads(item_rates)
- if isinstance(item_tax_templates, (str,)):
+ if isinstance(item_tax_templates, str):
item_tax_templates = json.loads(item_tax_templates)
for item_code in item_codes:
@@ -606,9 +591,7 @@
taxes_with_no_validity.append(tax)
if taxes_with_validity:
- taxes = sorted(
- taxes_with_validity, key=lambda i: i.valid_from or tax.maximum_net_rate, reverse=True
- )
+ taxes = sorted(taxes_with_validity, key=lambda i: i.valid_from or tax.maximum_net_rate, reverse=True)
else:
taxes = taxes_with_no_validity
@@ -761,7 +744,7 @@
elif not cost_center and args.get("item_code") and company:
for method in ["get_item_defaults", "get_item_group_defaults", "get_brand_defaults"]:
- path = "erpnext.stock.get_item_details.{0}".format(method)
+ path = f"erpnext.stock.get_item_details.{method}"
data = frappe.get_attr(path)(args.get("item_code"), company)
if data and (data.selling_cost_center or data.buying_cost_center):
@@ -776,11 +759,7 @@
if not cost_center and args.get("cost_center"):
cost_center = args.get("cost_center")
- if (
- company
- and cost_center
- and frappe.get_cached_value("Cost Center", cost_center, "company") != company
- ):
+ if company and cost_center and frappe.get_cached_value("Cost Center", cost_center, "company") != company:
return None
if not cost_center and company:
@@ -790,11 +769,7 @@
def get_default_supplier(args, item, item_group, brand):
- return (
- item.get("default_supplier")
- or item_group.get("default_supplier")
- or brand.get("default_supplier")
- )
+ return item.get("default_supplier") or item_group.get("default_supplier") or brand.get("default_supplier")
def get_price_list_rate(args, item_doc, out=None):
@@ -829,9 +804,7 @@
if not price_list_rate:
return out
- out.price_list_rate = (
- flt(price_list_rate) * flt(args.plc_conversion_rate) / flt(args.conversion_rate)
- )
+ out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) / flt(args.conversion_rate)
if frappe.db.get_single_value("Buying Settings", "disable_last_purchase_rate"):
return out
@@ -846,9 +819,7 @@
def insert_item_price(args):
"""Insert Item Price if Price List and Price List Rate are specified and currency is the same"""
- if frappe.db.get_value(
- "Price List", args.price_list, "currency", cache=True
- ) == args.currency and cint(
+ if frappe.db.get_value("Price List", args.price_list, "currency", cache=True) == args.currency and cint(
frappe.db.get_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing")
):
if frappe.has_permission("Item Price", "write"):
@@ -870,7 +841,9 @@
):
frappe.db.set_value("Item Price", item_price.name, "price_list_rate", price_list_rate)
frappe.msgprint(
- _("Item Price updated for {0} in Price List {1}").format(args.item_code, args.price_list),
+ _("Item Price updated for {0} in Price List {1}").format(
+ args.item_code, args.price_list
+ ),
alert=True,
)
else:
@@ -1011,11 +984,7 @@
if not args.conversion_rate and args.currency == company_currency:
args.conversion_rate = 1.0
- if (
- not args.ignore_conversion_rate
- and args.conversion_rate == 1
- and args.currency != company_currency
- ):
+ if not args.ignore_conversion_rate and args.conversion_rate == 1 and args.currency != company_currency:
args.conversion_rate = (
get_exchange_rate(args.currency, company_currency, args.transaction_date, "for_buying") or 1.0
)
@@ -1050,7 +1019,9 @@
if meta.get_field("plc_conversion_rate"):
args.plc_conversion_rate = flt(
args.plc_conversion_rate,
- get_field_precision(meta.get_field("plc_conversion_rate"), frappe._dict({"fields": args})),
+ get_field_precision(
+ meta.get_field("plc_conversion_rate"), frappe._dict({"fields": args})
+ ),
)
@@ -1288,9 +1259,7 @@
company_currency = get_company_currency(args.company)
if (not plc_conversion_rate) or (
- price_list_currency
- and args.price_list_currency
- and price_list_currency != args.price_list_currency
+ price_list_currency and args.price_list_currency and price_list_currency != args.price_list_currency
):
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
plc_conversion_rate = (
@@ -1312,9 +1281,7 @@
@frappe.whitelist()
def get_default_bom(item_code=None):
def _get_bom(item):
- bom = frappe.get_all(
- "BOM", dict(item=item, is_active=True, is_default=True, docstatus=1), limit=1
- )
+ bom = frappe.get_all("BOM", dict(item=item, is_active=True, is_default=True, docstatus=1), limit=1)
return bom[0].name if bom else None
if not item_code:
@@ -1354,7 +1321,7 @@
pi_item = frappe.qb.DocType("Purchase Invoice Item")
valuation_rate = (
frappe.qb.from_(pi_item)
- .select((Sum(pi_item.base_net_amount) / Sum(pi_item.qty * pi_item.conversion_factor)))
+ .select(Sum(pi_item.base_net_amount) / Sum(pi_item.qty * pi_item.conversion_factor))
.where((pi_item.docstatus == 1) & (pi_item.item_code == item_code))
).run()