fix: incorrect type hint

This commit is contained in:
khushi8112
2026-02-17 17:51:27 +05:30
parent 84773a3a32
commit 773cc80ed4
7 changed files with 31 additions and 35 deletions

View File

@@ -8,7 +8,6 @@ from typing import Any
import frappe import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document
from frappe.query_builder.functions import IfNull, Sum from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import ( from frappe.utils import (
cint, cint,
@@ -1133,7 +1132,7 @@ def create_asset_maintenance(
item_name: str, item_name: str,
asset_category: str, asset_category: str,
company: str, company: str,
) -> Document: ):
asset_maintenance = frappe.new_doc("Asset Maintenance") asset_maintenance = frappe.new_doc("Asset Maintenance")
asset_maintenance.update( asset_maintenance.update(
{ {
@@ -1152,7 +1151,7 @@ def create_asset_repair(
company: str, company: str,
asset: str, asset: str,
asset_name: str, asset_name: str,
) -> Document: ):
asset_repair = frappe.new_doc("Asset Repair") asset_repair = frappe.new_doc("Asset Repair")
asset_repair.update({"company": company, "asset": asset, "asset_name": asset_name}) asset_repair.update({"company": company, "asset": asset, "asset_name": asset_name})
return asset_repair return asset_repair
@@ -1164,7 +1163,7 @@ def create_asset_capitalization(
asset: str, asset: str,
asset_name: str, asset_name: str,
item_code: str, item_code: str,
) -> Document: ):
asset_capitalization = frappe.new_doc("Asset Capitalization") asset_capitalization = frappe.new_doc("Asset Capitalization")
asset_capitalization.update( asset_capitalization.update(
{ {
@@ -1182,7 +1181,7 @@ def create_asset_value_adjustment(
asset: str, asset: str,
asset_category: str, asset_category: str,
company: str, company: str,
) -> Document: ):
asset_value_adjustment = frappe.new_doc("Asset Value Adjustment") asset_value_adjustment = frappe.new_doc("Asset Value Adjustment")
asset_value_adjustment.update({"asset": asset, "company": company, "asset_category": asset_category}) asset_value_adjustment.update({"asset": asset, "company": company, "asset_category": asset_category})
return asset_value_adjustment return asset_value_adjustment
@@ -1193,7 +1192,7 @@ def get_item_details(
item_code: str, item_code: str,
asset_category: str, asset_category: str,
net_purchase_amount: float, net_purchase_amount: float,
) -> list[dict[str, Any]]: ):
asset_category_doc = frappe.get_cached_doc("Asset Category", asset_category) asset_category_doc = frappe.get_cached_doc("Asset Category", asset_category)
books = [] books = []
for d in asset_category_doc.finance_books: for d in asset_category_doc.finance_books:
@@ -1243,7 +1242,7 @@ def get_asset_account(account_name, asset=None, asset_category=None, company=Non
@frappe.whitelist() @frappe.whitelist()
def make_journal_entry(asset_name: str) -> Document: def make_journal_entry(asset_name: str):
asset = frappe.get_doc("Asset", asset_name) asset = frappe.get_doc("Asset", asset_name)
( (
fixed_asset_account, fixed_asset_account,
@@ -1286,9 +1285,9 @@ def make_journal_entry(asset_name: str) -> Document:
@frappe.whitelist() @frappe.whitelist()
def make_asset_movement( def make_asset_movement(
assets: list[dict[str, Any]], assets: list[dict] | str,
purpose: str = "Transfer", purpose: str = "Transfer",
) -> dict[str, Any]: ):
import json import json
if isinstance(assets, str): if isinstance(assets, str):
@@ -1323,7 +1322,7 @@ def is_cwip_accounting_enabled(asset_category):
def get_asset_value_after_depreciation( def get_asset_value_after_depreciation(
asset_name: str, asset_name: str,
finance_book: str | None = None, finance_book: str | None = None,
) -> float: ):
asset = frappe.get_doc("Asset", asset_name) asset = frappe.get_doc("Asset", asset_name)
if not asset.calculate_depreciation: if not asset.calculate_depreciation:
return flt(asset.value_after_depreciation) return flt(asset.value_after_depreciation)
@@ -1332,7 +1331,7 @@ def get_asset_value_after_depreciation(
@frappe.whitelist() @frappe.whitelist()
def has_active_capitalization(asset: str) -> bool: def has_active_capitalization(asset: str):
active_capitalizations = frappe.db.count( active_capitalizations = frappe.db.count(
"Asset Capitalization", filters={"target_asset": asset, "docstatus": 1} "Asset Capitalization", filters={"target_asset": asset, "docstatus": 1}
) )
@@ -1344,7 +1343,7 @@ def get_values_from_purchase_doc(
purchase_doc_name: str, purchase_doc_name: str,
item_code: str, item_code: str,
doctype: str, doctype: str,
) -> dict[str, Any]: ):
purchase_doc = frappe.get_doc(doctype, purchase_doc_name) purchase_doc = frappe.get_doc(doctype, purchase_doc_name)
matching_items = [item for item in purchase_doc.items if item.item_code == item_code] matching_items = [item for item in purchase_doc.items if item.item_code == item_code]
@@ -1366,7 +1365,7 @@ def get_values_from_purchase_doc(
@frappe.whitelist() @frappe.whitelist()
def split_asset(asset_name: str, split_qty: int) -> Document: def split_asset(asset_name: str, split_qty: int):
"""Split an asset into two based on the given quantity.""" """Split an asset into two based on the given quantity."""
existing_asset = frappe.get_doc("Asset", asset_name) existing_asset = frappe.get_doc("Asset", asset_name)
split_qty = cint(split_qty) split_qty = cint(split_qty)

View File

@@ -6,7 +6,6 @@ from typing import Any
import frappe import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document
from frappe.query_builder import Order from frappe.query_builder import Order
from frappe.query_builder.functions import Max, Min from frappe.query_builder.functions import Max, Min
from frappe.utils import ( from frappe.utils import (
@@ -169,8 +168,8 @@ def make_depreciation_entry(
date: DateTimeLikeObject | None = None, date: DateTimeLikeObject | None = None,
sch_start_idx: int | None = None, sch_start_idx: int | None = None,
sch_end_idx: int | None = None, sch_end_idx: int | None = None,
accounting_dimensions: dict[str, Any] | None = None, accounting_dimensions: list[dict] | None = None,
) -> Document: ):
frappe.has_permission("Journal Entry", throw=True) frappe.has_permission("Journal Entry", throw=True)
date = date or today() date = date or today()
@@ -776,7 +775,7 @@ def get_profit_gl_entries(
@frappe.whitelist() @frappe.whitelist()
def get_disposal_account_and_cost_center(company: str) -> tuple[str, str]: def get_disposal_account_and_cost_center(company: str):
disposal_account, depreciation_cost_center = frappe.get_cached_value( disposal_account, depreciation_cost_center = frappe.get_cached_value(
"Company", company, ["disposal_account", "depreciation_cost_center"] "Company", company, ["disposal_account", "depreciation_cost_center"]
) )
@@ -792,9 +791,9 @@ def get_disposal_account_and_cost_center(company: str) -> tuple[str, str]:
@frappe.whitelist() @frappe.whitelist()
def get_value_after_depreciation_on_disposal_date( def get_value_after_depreciation_on_disposal_date(
asset: str, asset: str,
disposal_date: str, disposal_date: DateTimeLikeObject,
finance_book: str | None = None, finance_book: str | None = None,
) -> float: ):
asset_doc = frappe.get_doc("Asset", asset) asset_doc = frappe.get_doc("Asset", asset)
if asset_doc.asset_type == "Composite Component": if asset_doc.asset_type == "Composite Component":

View File

@@ -610,7 +610,7 @@ class AssetCapitalization(StockController):
@frappe.whitelist() @frappe.whitelist()
def get_target_item_details(item_code: str | None = None, company: str | None = None) -> frappe._dict: def get_target_item_details(item_code: str | None = None, company: str | None = None):
out = frappe._dict() out = frappe._dict()
# Get Item Details # Get Item Details
@@ -636,7 +636,7 @@ def get_target_item_details(item_code: str | None = None, company: str | None =
@frappe.whitelist() @frappe.whitelist()
def get_target_asset_details(asset: str | None = None, company: str | None = None) -> frappe._dict: def get_target_asset_details(asset: str | None = None, company: str | None = None):
out = frappe._dict() out = frappe._dict()
# Get Asset Details # Get Asset Details
@@ -711,7 +711,7 @@ def get_consumed_stock_item_details(ctx: ItemDetailsCtx):
@frappe.whitelist() @frappe.whitelist()
def get_warehouse_details(args: dict[str, Any]) -> frappe._dict: def get_warehouse_details(args: dict | str):
if isinstance(args, str): if isinstance(args, str):
args = json.loads(args) args = json.loads(args)
@@ -798,7 +798,7 @@ def get_service_item_details(ctx: ItemDetailsCtx) -> frappe._dict:
@frappe.whitelist() @frappe.whitelist()
def get_items_tagged_to_wip_composite_asset(params: dict[str, Any]): def get_items_tagged_to_wip_composite_asset(params: dict | str):
if isinstance(params, str): if isinstance(params, str):
params = json.loads(params) params = json.loads(params)

View File

@@ -97,7 +97,7 @@ def calculate_next_due_date(
end_date: DateTimeLikeObject | None = None, end_date: DateTimeLikeObject | None = None,
last_completion_date: DateTimeLikeObject | None = None, last_completion_date: DateTimeLikeObject | None = None,
next_due_date: DateTimeLikeObject | None = None, next_due_date: DateTimeLikeObject | None = None,
) -> str: ):
if not start_date and not last_completion_date: if not start_date and not last_completion_date:
start_date = frappe.utils.now() start_date = frappe.utils.now()
@@ -186,7 +186,7 @@ def get_team_members(
@frappe.whitelist() @frappe.whitelist()
def get_maintenance_log(asset_name: str) -> list[dict[str, Any]]: def get_maintenance_log(asset_name: str):
return frappe.db.sql( return frappe.db.sql(
""" """
select maintenance_status, count(asset_name) as count, asset_name select maintenance_status, count(asset_name) as count, asset_name

View File

@@ -448,7 +448,7 @@ class AssetRepair(AccountsController):
@frappe.whitelist() @frappe.whitelist()
def get_downtime(failure_date: DateTimeLikeObject, completion_date: DateTimeLikeObject) -> float: def get_downtime(failure_date: DateTimeLikeObject, completion_date: DateTimeLikeObject):
downtime = time_diff_in_hours(completion_date, failure_date) downtime = time_diff_in_hours(completion_date, failure_date)
return round(downtime, 2) return round(downtime, 2)
@@ -461,8 +461,8 @@ def get_purchase_invoice(
searchfield: str, searchfield: str,
start: int, start: int,
page_len: int, page_len: int,
filters: dict[str, str], filters: dict,
) -> list[list[str]]: ):
""" """
Get Purchase Invoices that have expense accounts for non-stock items. Get Purchase Invoices that have expense accounts for non-stock items.
Only returns invoices with at least one non-stock, non-fixed-asset item with an expense account. Only returns invoices with at least one non-stock, non-fixed-asset item with an expense account.
@@ -503,8 +503,8 @@ def get_expense_accounts(
searchfield: str, searchfield: str,
start: int, start: int,
page_len: int, page_len: int,
filters: dict[str, str], filters: dict,
) -> list[list[str]]: ):
""" """
Get expense accounts for non-stock (service) items from the purchase invoice. Get expense accounts for non-stock (service) items from the purchase invoice.
Used as a query function for link fields. Used as a query function for link fields.
@@ -562,7 +562,7 @@ def _get_expense_accounts_for_purchase_invoice(purchase_invoice: str) -> list[st
@frappe.whitelist() @frappe.whitelist()
def get_unallocated_repair_cost( def get_unallocated_repair_cost(
purchase_invoice: str, expense_account: str, exclude_asset_repair: str | None = None purchase_invoice: str, expense_account: str, exclude_asset_repair: str | None = None
) -> float: ):
""" """
Calculate the unused repair cost for a purchase invoice and expense account. Calculate the unused repair cost for a purchase invoice and expense account.
""" """

View File

@@ -227,6 +227,6 @@ class AssetValueAdjustment(Document):
@frappe.whitelist() @frappe.whitelist()
def get_value_of_accounting_dimensions(asset_name: str) -> dict: def get_value_of_accounting_dimensions(asset_name: str):
dimension_fields = [*frappe.get_list("Accounting Dimension", pluck="fieldname"), "cost_center"] dimension_fields = [*frappe.get_list("Accounting Dimension", pluck="fieldname"), "cost_center"]
return frappe.db.get_value("Asset", asset_name, fieldname=dimension_fields, as_dict=True) return frappe.db.get_value("Asset", asset_name, fieldname=dimension_fields, as_dict=True)

View File

@@ -211,9 +211,7 @@ def _ring_area(coords):
@frappe.whitelist() @frappe.whitelist()
def get_children( def get_children(doctype: str, parent: str | None = None, location: str | None = None, is_root: bool = False):
doctype: str, parent: str | None = None, location: str | None = None, is_root: bool = False
) -> list[dict]:
if parent is None or parent == "All Locations": if parent is None or parent == "All Locations":
parent = "" parent = ""