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>
This commit is contained in:
@@ -57,6 +57,9 @@ def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verb
|
||||
|
||||
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 @@ def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verb
|
||||
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 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date):
|
||||
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
|
||||
return gl_entries
|
||||
|
||||
Reference in New Issue
Block a user