style: format code with black

This commit is contained in:
Ankush Menat
2022-03-28 18:52:46 +05:30
parent 21e00da3d6
commit 494bd9ef78
1395 changed files with 91704 additions and 62532 deletions

View File

@@ -7,6 +7,7 @@ from erpnext.setup.utils import get_exchange_rate
__exchange_rates = {}
def get_currency(filters):
"""
Returns a dictionary containing currency information. The keys of the dict are
@@ -23,15 +24,22 @@ 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
presentation_currency = (
filters["presentation_currency"] if filters.get("presentation_currency") else company_currency
)
report_date = filters.get('to_date')
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"]
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)
currency_map = dict(
company=company,
company_currency=company_currency,
presentation_currency=presentation_currency,
report_date=report_date,
)
return currency_map
@@ -62,13 +70,14 @@ def get_rate_as_at(date, from_currency, to_currency):
:return: Retrieved exchange rate
"""
rate = __exchange_rates.get('{0}-{1}@{2}'.format(from_currency, to_currency, date))
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
__exchange_rates['{0}-{1}@{2}'.format(from_currency, to_currency, date)] = rate
__exchange_rates["{0}-{1}@{2}".format(from_currency, to_currency, date)] = rate
return rate
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
@@ -78,35 +87,35 @@ def convert_to_presentation_currency(gl_entries, currency_info, company):
:return:
"""
converted_gl_list = []
presentation_currency = currency_info['presentation_currency']
company_currency = currency_info['company_currency']
presentation_currency = currency_info["presentation_currency"]
company_currency = currency_info["company_currency"]
account_currencies = list(set(entry['account_currency'] for entry in gl_entries))
account_currencies = list(set(entry["account_currency"] for entry in gl_entries))
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']
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 len(account_currencies) == 1 and account_currency == presentation_currency:
if debit_in_account_currency:
entry['debit'] = debit_in_account_currency
entry["debit"] = debit_in_account_currency
if credit_in_account_currency:
entry['credit'] = credit_in_account_currency
entry["credit"] = credit_in_account_currency
else:
date = currency_info['report_date']
date = currency_info["report_date"]
converted_debit_value = convert(debit, presentation_currency, company_currency, date)
converted_credit_value = convert(credit, presentation_currency, company_currency, date)
if entry.get('debit'):
entry['debit'] = converted_debit_value
if entry.get("debit"):
entry["debit"] = converted_debit_value
if entry.get('credit'):
entry['credit'] = converted_credit_value
if entry.get("credit"):
entry["credit"] = converted_credit_value
converted_gl_list.append(entry)
@@ -114,26 +123,29 @@ def convert_to_presentation_currency(gl_entries, currency_info, company):
def get_appropriate_company(filters):
if filters.get('company'):
company = filters['company']
if filters.get("company"):
company = filters["company"]
else:
company = get_default_company()
return company
@frappe.whitelist()
def get_invoiced_item_gross_margin(sales_invoice=None, item_code=None, company=None, with_item_data=False):
def get_invoiced_item_gross_margin(
sales_invoice=None, item_code=None, company=None, with_item_data=False
):
from erpnext.accounts.report.gross_profit.gross_profit import GrossProfitGenerator
sales_invoice = sales_invoice or frappe.form_dict.get('sales_invoice')
item_code = item_code or frappe.form_dict.get('item_code')
company = company or frappe.get_cached_value("Sales Invoice", sales_invoice, 'company')
sales_invoice = sales_invoice or frappe.form_dict.get("sales_invoice")
item_code = item_code or frappe.form_dict.get("item_code")
company = company or frappe.get_cached_value("Sales Invoice", sales_invoice, "company")
filters = {
'sales_invoice': sales_invoice,
'item_code': item_code,
'company': company,
'group_by': 'Invoice'
"sales_invoice": sales_invoice,
"item_code": item_code,
"company": company,
"group_by": "Invoice",
}
gross_profit_data = GrossProfitGenerator(filters)