fix: Cleanup and fixes

This commit is contained in:
Deepesh Garg
2022-01-10 17:31:38 +05:30
parent c68b2c3763
commit e2dab6f421
7 changed files with 92 additions and 28 deletions

View File

@@ -59,13 +59,20 @@ def set_single_defaults():
pass
frappe.db.set_default("date_format", "dd-mm-yyyy")
setup_currency_exchange()
def setup_currency_exchange():
ces = frappe.get_single('Currency Exchange Settings')
try:
ces.api_endpoint = "https://api.exchangerate.host/convert"
ces.append('result_key', {'key': 'result'})
ces.append('req_params', {'key': 'date', 'value': '{transaction_date}'})
ces.append('req_params', {'key': 'from', 'value': '{from_currency}'})
ces.append('req_params', {'key': 'to', 'value': '{to_currency}'})
ces.set('result_key', [])
ces.set('req_params', [])
ces.api_endpoint = "https://frankfurter.app/{transaction_date}"
ces.append('result_key', {'key': 'rates'})
ces.append('result_key', {'key': '{to_currency}'})
ces.append('req_params', {'key': 'base', 'value': '{from_currency}'})
ces.append('req_params', {'key': 'symbols', 'value': '{to_currency}'})
ces.save()
except frappe.ValidationError:
pass

View File

@@ -100,7 +100,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
if not value:
import requests
settings = frappe.get_single('Currency Exchange Settings')
settings = frappe.get_cached_doc('Currency Exchange Settings')
req_params = {
"transaction_date": transaction_date,
"from_currency": from_currency,