# Buggy code
def convert_to_presentation_currency(gl_entries, currency_info):
    """
    Take a list of GL Entries and change the 'debit' and 'credit' values to currencies
    in `currency_info`.
    :param gl_entries:
    :param currency_info:
    :return:
    """
    converted_gl_list = []
    presentation_currency = currency_info["presentation_currency"]
    company_currency = currency_info["company_currency"]

    for entry in gl_entries:
        account = entry["account"]
        debit = flt(entry["debit"])
        credit = flt(entry["credit"])
        debit_in_account_currency = flt(entry["debit_in_account_currency"])
        credit_in_account_currency = flt(entry["credit_in_account_currency"])
        account_currency = entry["account_currency"]

        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"]
            )
            converted_value = convert(
                value, presentation_currency, company_currency, date
            )

            if entry.get("debit"):
                entry["debit"] = converted_value

            if entry.get("credit"):
                entry["credit"] = converted_value

        elif account_currency == presentation_currency:
            if entry.get("debit"):
                entry["debit"] = debit_in_account_currency

            if entry.get("credit"):
                entry["credit"] = credit_in_account_currency

        converted_gl_list.append(entry)

    return converted_gl_list


# Traceback (pymysql.err.ProgrammingError)
$ bench --site test.site install-app erpnext

Installing erpnext...
Updating DocTypes for erpnext       : [===                                     ] 9%An error occurred while installing erpnext:
Traceback (most recent call last):
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/commands/site.py", line 215, in install_app
_install_app(app, verbose=context.verbose)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/installer.py", line 84, in install_app
sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/sync.py", line 69, in sync_for
import_file_by_path(doc_path, force=force, ignore_version=True,
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 69, in import_file_by_path
import_doc(doc, force=force, data_import=data_import, pre_process=pre_process,
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 143, in import_doc
doc.insert()
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 268, in insert
self.run_post_save_methods()
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 964, in run_post_save_methods
self.run_method("on_update")
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 831, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 1116, in composer
return composed(self, method, *args, **kwargs)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 1099, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/document.py", line 825, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 291, in on_update
self.run_module_method("on_doctype_update")
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 357, in run_module_method
module = load_doctype_module(self.name, self.module)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/modules/utils.py", line 204, in load_doctype_module
doctype_python_modules[key] = frappe.get_module(module_name)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/__init__.py", line 858, in get_module
return importlib.import_module(modulename)
File "/home/haris/myproject/frappe-bench/env/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/haris/myproject/frappe-bench/apps/erpnext/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py", line 8, in <module>
from erpnext.accounts.report.general_ledger.general_ledger import execute as get_soa
File "/home/haris/myproject/frappe-bench/apps/erpnext/erpnext/accounts/report/general_ledger/general_ledger.py", line 7, in <module>
from erpnext.accounts.report.utils import get_currency, convert_to_presentation_currency
File "/home/haris/myproject/frappe-bench/apps/erpnext/erpnext/accounts/report/utils.py", line 10, in <module>
sum(frappe.get_list('Account', fields=['name'], or_filters=[{'root_type': 'Income'}, {'root_type': 'Expense'}], as_list=True), ())
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/__init__.py", line 1329, in get_list
return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/db_query.py", line 96, in execute
result = self.build_and_run()
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/db_query.py", line 110, in build_and_run
args = self.prepare_args()
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/db_query.py", line 136, in prepare_args
self.set_optional_columns()
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/db_query.py", line 302, in set_optional_columns
columns = get_table_columns(self.doctype)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/model/meta.py", line 49, in get_table_columns
return frappe.db.get_table_columns(doctype)
File "/home/haris/myproject/frappe-bench/apps/frappe/frappe/database/database.py", line 893, in get_table_columns
raise self.TableMissingError('DocType', doctype)
pymysql.err.ProgrammingError: ('DocType', 'Account')

# Fixed code
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`.
    :param gl_entries:
    :param currency_info:
    :return:
    """
    converted_gl_list = []
    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"])
        credit = flt(entry["credit"])
        debit_in_account_currency = flt(entry["debit_in_account_currency"])
        credit_in_account_currency = flt(entry["credit_in_account_currency"])
        account_currency = entry["account_currency"]

        if account_currency != presentation_currency:
            value = debit or credit

            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"):
                entry["debit"] = converted_value

            if entry.get("credit"):
                entry["credit"] = converted_value

        elif account_currency == presentation_currency:
            if entry.get("debit"):
                entry["debit"] = debit_in_account_currency

            if entry.get("credit"):
                entry["credit"] = credit_in_account_currency

        converted_gl_list.append(entry)

    return converted_gl_list