mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-20 07:15:11 +00:00
refactor: Optimize asset depreciation schedule retrieval with type hints
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
import json
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
@@ -164,7 +164,7 @@ def get_depr_cost_center_and_series():
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_depreciation_entry(
|
||||
depr_schedule_name: str | list[dict],
|
||||
depr_schedule_name: str,
|
||||
date: DateTimeLikeObject | None = None,
|
||||
sch_start_idx: int | None = None,
|
||||
sch_end_idx: int | None = None,
|
||||
|
||||
@@ -396,19 +396,17 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
|
||||
method: "erpnext.assets.doctype.asset_capitalization.asset_capitalization.get_warehouse_details",
|
||||
child: item,
|
||||
args: {
|
||||
args: {
|
||||
item_code: item.item_code,
|
||||
warehouse: cstr(item.warehouse),
|
||||
qty: -1 * flt(item.stock_qty),
|
||||
serial_no: item.serial_no,
|
||||
posting_date: me.frm.doc.posting_date,
|
||||
posting_time: me.frm.doc.posting_time,
|
||||
company: me.frm.doc.company,
|
||||
voucher_type: me.frm.doc.doctype,
|
||||
voucher_no: me.frm.doc.name,
|
||||
allow_zero_valuation: 1,
|
||||
serial_and_batch_bundle: item.serial_and_batch_bundle,
|
||||
},
|
||||
item_code: item.item_code,
|
||||
warehouse: cstr(item.warehouse),
|
||||
qty: -1 * flt(item.stock_qty),
|
||||
serial_no: item.serial_no,
|
||||
posting_date: me.frm.doc.posting_date,
|
||||
posting_time: me.frm.doc.posting_time,
|
||||
company: me.frm.doc.company,
|
||||
voucher_type: me.frm.doc.doctype,
|
||||
voucher_no: me.frm.doc.name,
|
||||
allow_zero_valuation: 1,
|
||||
serial_and_batch_bundle: item.serial_and_batch_bundle,
|
||||
},
|
||||
callback: function (r) {
|
||||
if (!r.exc) {
|
||||
|
||||
@@ -711,18 +711,14 @@ def get_consumed_stock_item_details(ctx: ItemDetailsCtx):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_warehouse_details(args: dict | str):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
args = frappe._dict(args)
|
||||
|
||||
@erpnext.normalize_ctx_input(ItemDetailsCtx)
|
||||
def get_warehouse_details(ctx: ItemDetailsCtx) -> frappe._dict:
|
||||
out = frappe._dict()
|
||||
if args.warehouse and args.item_code:
|
||||
if ctx.warehouse and ctx.item_code:
|
||||
out = frappe._dict(
|
||||
{
|
||||
"actual_qty": get_previous_sle(args).get("qty_after_transaction") or 0,
|
||||
"valuation_rate": get_incoming_rate(args, raise_error_if_no_rate=False),
|
||||
"actual_qty": get_previous_sle(ctx).get("qty_after_transaction") or 0,
|
||||
"valuation_rate": get_incoming_rate(ctx, raise_error_if_no_rate=False),
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
@@ -287,7 +287,7 @@ def get_asset_depr_schedule_doc(asset_name: str, status: str | None = None, fina
|
||||
if not asset_depr_schedule:
|
||||
return
|
||||
|
||||
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", asset_depr_schedule[0].name)
|
||||
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", asset_depr_schedule)
|
||||
|
||||
return asset_depr_schedule_doc
|
||||
|
||||
@@ -299,21 +299,23 @@ def get_asset_depr_schedule_name(asset_name, status=None, finance_book=None):
|
||||
]
|
||||
|
||||
if status:
|
||||
if isinstance(status, str):
|
||||
status = [status]
|
||||
filters.append(["status", "in", status])
|
||||
status_list = [status] if isinstance(status, str) else status
|
||||
filters.append(["status", "in", status_list])
|
||||
|
||||
if finance_book:
|
||||
filters.append(["finance_book", "=", finance_book])
|
||||
else:
|
||||
filters.append(["finance_book", "is", "not set"])
|
||||
finance_book_filter = (
|
||||
["finance_book", "=", finance_book] if finance_book else ["finance_book", "is", "not set"]
|
||||
)
|
||||
filters.append(finance_book_filter)
|
||||
|
||||
return frappe.get_all(
|
||||
depreciation_schedules = frappe.get_all(
|
||||
doctype="Asset Depreciation Schedule",
|
||||
filters=filters,
|
||||
fields=["name"],
|
||||
limit=1,
|
||||
)
|
||||
|
||||
return depreciation_schedules[0].name if depreciation_schedules else None
|
||||
|
||||
|
||||
def is_first_day_of_the_month(date):
|
||||
first_day_of_the_month = get_first_day(date)
|
||||
|
||||
Reference in New Issue
Block a user