fix: Installation failed due to global variable (#23114)
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index c2c7207..219871b 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -378,7 +378,7 @@
if filters and filters.get('presentation_currency') != d.default_currency:
currency_info['company'] = d.name
currency_info['company_currency'] = d.default_currency
- convert_to_presentation_currency(gl_entries, currency_info)
+ convert_to_presentation_currency(gl_entries, currency_info, filters.get('company'))
for entry in gl_entries:
key = entry.account_number or entry.account_name
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index d5b8cdb..1b65a31 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -423,7 +423,7 @@
distributed_cost_center_query=distributed_cost_center_query), gl_filters, as_dict=True) #nosec
if filters and filters.get('presentation_currency'):
- convert_to_presentation_currency(gl_entries, get_currency(filters))
+ convert_to_presentation_currency(gl_entries, get_currency(filters), filters.get('company'))
for entry in gl_entries:
gl_entries_by_account.setdefault(entry.account, []).append(entry)
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index fcd36e4..0a72f6a 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -180,7 +180,7 @@
filters, as_dict=1)
if filters.get('presentation_currency'):
- return convert_to_presentation_currency(gl_entries, currency_map)
+ return convert_to_presentation_currency(gl_entries, currency_map, filters.get('company'))
else:
return gl_entries
diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py
index 4a9af49..9de8d19 100644
--- a/erpnext/accounts/report/utils.py
+++ b/erpnext/accounts/report/utils.py
@@ -6,10 +6,6 @@
from frappe.utils import cint, get_datetime_str, formatdate, flt
__exchange_rates = {}
-P_OR_L_ACCOUNTS = list(
- sum(frappe.get_list('Account', fields=['name'], or_filters=[{'root_type': 'Income'}, {'root_type': 'Expense'}], as_list=True), ())
-)
-
def get_currency(filters):
"""
@@ -73,18 +69,7 @@
return rate
-
-def is_p_or_l_account(account_name):
- """
- Check if the given `account name` is an `Account` with `root_type` of either 'Income'
- or 'Expense'.
- :param account_name:
- :return: Boolean
- """
- return account_name in P_OR_L_ACCOUNTS
-
-
-def convert_to_presentation_currency(gl_entries, currency_info):
+def convert_to_presentation_currency(gl_entries, currency_info, company):
"""
Take a list of GL Entries and change the 'debit' and 'credit' values to currencies
in `currency_info`.
@@ -96,6 +81,9 @@
presentation_currency = currency_info['presentation_currency']
company_currency = currency_info['company_currency']
+ pl_accounts = [d.name for d in frappe.get_list('Account',
+ filters={'report_type': 'Profit and Loss', 'company': company})]
+
for entry in gl_entries:
account = entry['account']
debit = flt(entry['debit'])
@@ -107,7 +95,7 @@
if account_currency != presentation_currency:
value = debit or credit
- date = currency_info['report_date'] if not is_p_or_l_account(account) else entry['posting_date']
+ date = entry['posting_date'] if account in pl_accounts else currency_info['report_date']
converted_value = convert(value, presentation_currency, company_currency, date)
if entry.get('debit'):