Skip to content

Commit

Permalink
chore: set default filter dates if missing (backport #36597) (#36598)
Browse files Browse the repository at this point in the history
chore: set default filter dates if missing (#36597)

(cherry picked from commit 98e82e0)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
  • Loading branch information
mergify[bot] and anandbaburajan committed Aug 11, 2023
1 parent ee04c6d commit 96663d7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import frappe
from frappe import _
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import cstr, flt, formatdate, getdate
from frappe.utils import add_months, cstr, flt, formatdate, getdate, nowdate, today

from erpnext.accounts.report.financial_statements import (
get_fiscal_year_data,
get_period_list,
validate_fiscal_year,
)
from erpnext.accounts.utils import get_fiscal_year
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation


Expand All @@ -37,15 +38,26 @@ def get_conditions(filters):

if filters.get("company"):
conditions["company"] = filters.company

if filters.filter_based_on == "Date Range":
if not filters.from_date and not filters.to_date:
filters.from_date = add_months(nowdate(), -12)
filters.to_date = nowdate()

conditions[date_field] = ["between", [filters.from_date, filters.to_date]]
if filters.filter_based_on == "Fiscal Year":
elif filters.filter_based_on == "Fiscal Year":
if not filters.from_fiscal_year and not filters.to_fiscal_year:
default_fiscal_year = get_fiscal_year(today())[0]
filters.from_fiscal_year = default_fiscal_year
filters.to_fiscal_year = default_fiscal_year

fiscal_year = get_fiscal_year_data(filters.from_fiscal_year, filters.to_fiscal_year)
validate_fiscal_year(fiscal_year, filters.from_fiscal_year, filters.to_fiscal_year)
filters.year_start_date = getdate(fiscal_year.year_start_date)
filters.year_end_date = getdate(fiscal_year.year_end_date)

conditions[date_field] = ["between", [filters.year_start_date, filters.year_end_date]]

if filters.get("only_existing_assets"):
conditions["is_existing_asset"] = filters.get("only_existing_assets")
if filters.get("asset_category"):
Expand Down

0 comments on commit 96663d7

Please sign in to comment.