fix: provide filter by depreciable assets in fixed asset register (#34803)
This commit is contained in:
parent
934e1b4e6a
commit
c957a5cd2e
@ -24,7 +24,7 @@ frappe.query_reports["Fixed Asset Register"] = {
|
|||||||
"label": __("Period Based On"),
|
"label": __("Period Based On"),
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"options": ["Fiscal Year", "Date Range"],
|
"options": ["Fiscal Year", "Date Range"],
|
||||||
"default": ["Fiscal Year"],
|
"default": "Fiscal Year",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -75,12 +75,6 @@ frappe.query_reports["Fixed Asset Register"] = {
|
|||||||
fieldtype: "Link",
|
fieldtype: "Link",
|
||||||
options: "Asset Category"
|
options: "Asset Category"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
fieldname:"finance_book",
|
|
||||||
label: __("Finance Book"),
|
|
||||||
fieldtype: "Link",
|
|
||||||
options: "Finance Book"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
fieldname:"cost_center",
|
fieldname:"cost_center",
|
||||||
label: __("Cost Center"),
|
label: __("Cost Center"),
|
||||||
@ -96,8 +90,20 @@ frappe.query_reports["Fixed Asset Register"] = {
|
|||||||
reqd: 1
|
reqd: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname:"is_existing_asset",
|
fieldname:"finance_book",
|
||||||
label: __("Is Existing Asset"),
|
label: __("Finance Book"),
|
||||||
|
fieldtype: "Link",
|
||||||
|
options: "Finance Book",
|
||||||
|
depends_on: "eval: doc.only_depreciable_assets == 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname:"only_depreciable_assets",
|
||||||
|
label: __("Only depreciable assets"),
|
||||||
|
fieldtype: "Check"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname:"only_existing_assets",
|
||||||
|
label: __("Only existing assets"),
|
||||||
fieldtype: "Check"
|
fieldtype: "Check"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -45,8 +45,10 @@ def get_conditions(filters):
|
|||||||
filters.year_end_date = getdate(fiscal_year.year_end_date)
|
filters.year_end_date = getdate(fiscal_year.year_end_date)
|
||||||
|
|
||||||
conditions[date_field] = ["between", [filters.year_start_date, filters.year_end_date]]
|
conditions[date_field] = ["between", [filters.year_start_date, filters.year_end_date]]
|
||||||
if filters.get("is_existing_asset"):
|
if filters.get("only_depreciable_assets"):
|
||||||
conditions["is_existing_asset"] = filters.get("is_existing_asset")
|
conditions["calculate_depreciation"] = filters.get("only_depreciable_assets")
|
||||||
|
if filters.get("only_existing_assets"):
|
||||||
|
conditions["is_existing_asset"] = filters.get("only_existing_assets")
|
||||||
if filters.get("asset_category"):
|
if filters.get("asset_category"):
|
||||||
conditions["asset_category"] = filters.get("asset_category")
|
conditions["asset_category"] = filters.get("asset_category")
|
||||||
if filters.get("cost_center"):
|
if filters.get("cost_center"):
|
||||||
@ -102,19 +104,18 @@ def get_data(filters):
|
|||||||
]
|
]
|
||||||
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
||||||
|
|
||||||
assets_linked_to_fb = frappe.db.get_all(
|
assets_linked_to_fb = None
|
||||||
doctype="Asset Finance Book",
|
|
||||||
filters={"finance_book": filters.finance_book or ("is", "not set")},
|
if filters.only_depreciable_assets:
|
||||||
pluck="parent",
|
assets_linked_to_fb = frappe.db.get_all(
|
||||||
)
|
doctype="Asset Finance Book",
|
||||||
|
filters={"finance_book": filters.finance_book or ("is", "not set")},
|
||||||
|
pluck="parent",
|
||||||
|
)
|
||||||
|
|
||||||
for asset in assets_record:
|
for asset in assets_record:
|
||||||
if filters.finance_book:
|
if assets_linked_to_fb and asset.asset_id not in assets_linked_to_fb:
|
||||||
if asset.asset_id not in assets_linked_to_fb:
|
continue
|
||||||
continue
|
|
||||||
else:
|
|
||||||
if asset.calculate_depreciation and asset.asset_id not in assets_linked_to_fb:
|
|
||||||
continue
|
|
||||||
|
|
||||||
asset_value = get_asset_value_after_depreciation(asset.asset_id, filters.finance_book)
|
asset_value = get_asset_value_after_depreciation(asset.asset_id, filters.finance_book)
|
||||||
row = {
|
row = {
|
||||||
@ -172,11 +173,11 @@ def prepare_chart_data(data, filters):
|
|||||||
"datasets": [
|
"datasets": [
|
||||||
{
|
{
|
||||||
"name": _("Asset Value"),
|
"name": _("Asset Value"),
|
||||||
"values": [d.get("asset_value") for d in labels_values_map.values()],
|
"values": [flt(d.get("asset_value"), 2) for d in labels_values_map.values()],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": _("Depreciatied Amount"),
|
"name": _("Depreciatied Amount"),
|
||||||
"values": [d.get("depreciated_amount") for d in labels_values_map.values()],
|
"values": [flt(d.get("depreciated_amount"), 2) for d in labels_values_map.values()],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -312,7 +313,7 @@ def get_columns(filters):
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"label": _("Asset Id"),
|
"label": _("Asset ID"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"fieldname": "asset_id",
|
"fieldname": "asset_id",
|
||||||
"options": "Asset",
|
"options": "Asset",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user