feat: date filter for fiscal year (#21880)
* feat: date filter for fiscal year
* fix: rename fieldtypes to valid_for_fieldtypes
* Update utils.py
Co-authored-by: Nabin Hait <nabinhait@gmail.com>
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 5165495..f6cd606 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -57,6 +57,9 @@
frappe.cache().hset("fiscal_years", company, fiscal_years)
+ if not transaction_date and not fiscal_year:
+ return fiscal_years
+
if transaction_date:
transaction_date = getdate(transaction_date)
@@ -79,6 +82,23 @@
if verbose==1: frappe.msgprint(error_msg)
raise FiscalYearError(error_msg)
+@frappe.whitelist()
+def get_fiscal_year_filter_field(company=None):
+ field = {
+ "fieldtype": "Select",
+ "options": [],
+ "operator": "Between",
+ "query_value": True
+ }
+ fiscal_years = get_fiscal_years(company=company)
+ for fiscal_year in fiscal_years:
+ field["options"].append({
+ "label": fiscal_year.name,
+ "value": fiscal_year.name,
+ "query_value": [fiscal_year.year_start_date.strftime("%Y-%m-%d"), fiscal_year.year_end_date.strftime("%Y-%m-%d")]
+ })
+ return field
+
def validate_fiscal_year(date, fiscal_year, company, label="Date", doc=None):
years = [f[0] for f in get_fiscal_years(date, label=_(label), company=company)]
if fiscal_year not in years:
@@ -942,4 +962,4 @@
tuple([posting_date] + [d[1] for d in future_stock_vouchers]), as_dict=1):
gl_entries.setdefault((d.voucher_type, d.voucher_no), []).append(d)
- return gl_entries
\ No newline at end of file
+ return gl_entries
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 742cc8e..2a69589 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -41,7 +41,7 @@
notification_config = "erpnext.startup.notifications.get_notification_config"
get_help_messages = "erpnext.utilities.activation.get_help_messages"
leaderboards = "erpnext.startup.leaderboard.get_leaderboards"
-
+filters_config = "erpnext.startup.filters.get_filters_config"
on_session_creation = [
"erpnext.portal.utils.create_customer_or_supplier",
diff --git a/erpnext/startup/filters.py b/erpnext/startup/filters.py
new file mode 100644
index 0000000..a99e49b
--- /dev/null
+++ b/erpnext/startup/filters.py
@@ -0,0 +1,14 @@
+
+import frappe
+
+def get_filters_config():
+ filters_config = {
+ "fiscal year": {
+ "label": "Fiscal Year",
+ "get_field": "erpnext.accounts.utils.get_fiscal_year_filter_field",
+ "valid_for_fieldtypes": ["Date", "Datetime", "DateRange"],
+ "depends_on": "company",
+ }
+ }
+
+ return filters_config
\ No newline at end of file