[fix] format fiscal year docname to proper date before using 🤦 (#14955)

This commit is contained in:
Prateeksha Singh 2018-07-18 18:03:27 +05:30 committed by Nabin Hait
parent d9d8dda5da
commit 8ecfaaa707
2 changed files with 20 additions and 2 deletions

View File

@ -109,3 +109,14 @@ def auto_create_fiscal_year():
new_fy.insert(ignore_permissions=True)
except frappe.NameError:
pass
def get_from_and_to_date(fiscal_year):
from_and_to_date_tuple = frappe.db.sql("""select year_start_date, year_end_date
from `tabFiscal Year` where name=%s""", (fiscal_year))[0]
from_and_to_date = {
"from_date": from_and_to_date_tuple[0],
"to_date": from_and_to_date_tuple[1]
}
return from_and_to_date

View File

@ -1,7 +1,8 @@
import frappe
from erpnext import get_company_currency, get_default_company
from erpnext.setup.utils import get_exchange_rate
from frappe.utils import cint
from erpnext.accounts.doctype.fiscal_year.fiscal_year import get_from_and_to_date
from frappe.utils import cint, get_datetime_str, formatdate
__exchange_rates = {}
P_OR_L_ACCOUNTS = list(
@ -26,7 +27,12 @@ def get_currency(filters):
company = get_appropriate_company(filters)
company_currency = get_company_currency(company)
presentation_currency = filters['presentation_currency'] if filters.get('presentation_currency') else company_currency
report_date = filters.get('to_date') or filters.get('to_fiscal_year')
report_date = filters.get('to_date')
if not report_date:
fiscal_year_to_date = get_from_and_to_date(filters.get('to_fiscal_year')).to_date
report_date = formatdate(get_datetime_str(fiscal_year_to_date), "dd-MM-yyyy")
currency_map = dict(company=company, company_currency=company_currency, presentation_currency=presentation_currency, report_date=report_date)
@ -58,6 +64,7 @@ def get_rate_as_at(date, from_currency, to_currency):
:param to_currency: Quote currency
:return: Retrieved exchange rate
"""
rate = __exchange_rates.get('{0}-{1}@{2}'.format(from_currency, to_currency, date))
if not rate:
rate = get_exchange_rate(from_currency, to_currency, date) or 1