feat: currency exchange settings

This commit is contained in:
rtdany10 2021-09-02 19:52:12 +05:30
parent a158b825fc
commit ff19113677
11 changed files with 235 additions and 0 deletions

View File

@ -0,0 +1,8 @@
// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Currency Exchange Settings', {
// refresh: function(frm) {
// }
});

View File

@ -0,0 +1,86 @@
{
"actions": [],
"creation": "2021-09-02 14:53:50.923529",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"api_details_section",
"api_endpoint",
"column_break_3",
"result_key",
"section_break_2",
"req_params",
"column_break_4",
"extra_params"
],
"fields": [
{
"fieldname": "api_endpoint",
"fieldtype": "Data",
"in_list_view": 1,
"label": "API Endpoint",
"reqd": 1
},
{
"fieldname": "section_break_2",
"fieldtype": "Section Break",
"label": "Request Parameters"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fieldname": "req_params",
"fieldtype": "Table",
"label": "Mandatory Parameters",
"options": "Currency Exchange Settings Details",
"reqd": 1
},
{
"fieldname": "extra_params",
"fieldtype": "Table",
"label": "Additional Parameters",
"options": "Currency Exchange Settings Extra Details"
},
{
"fieldname": "api_details_section",
"fieldtype": "Section Break",
"label": "API Details"
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "result_key",
"fieldtype": "Data",
"label": "Result Key",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-09-02 15:18:29.198210",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange Settings",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@ -0,0 +1,38 @@
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.model.document import Document
class CurrencyExchangeSettings(Document):
def validate(self):
if len(self.req_params) != 3:
frappe.throw(_("Make sure all the three mandatory parameters are filled."))
req_params = {
'transaction_date': '2021-08-01',
'from_currency': 'USD',
'to_currency': 'INR'
}
params = {}
for row in self.req_params:
try:
params[row.key] = req_params[row.value]
req_params.pop(row.value)
except:
frappe.throw(_("Make sure all the three mandatory parameters are filled."))
import requests
api_url = self.api_endpoint
try:
response = requests.get(api_url, params=params)
except requests.exceptions.RequestException as e:
frappe.throw("Error: " + str(e))
response.raise_for_status()
value = response.json()
try:
rate = value[str(self.result_key)]
except KeyError:
frappe.throw(_("Invalid result key."))
if not isinstance(rate, (int, float)):
frappe.throw(_("Returned exchange rate is neither integer not float."))
frappe.msgprint(_("Exchange rate of USD to INR on 01-08-2021 is ") + str(rate))

View File

@ -0,0 +1,8 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import unittest
class TestCurrencyExchangeSettings(unittest.TestCase):
pass

View File

@ -0,0 +1,40 @@
{
"actions": [],
"creation": "2021-09-02 14:54:49.033512",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"key",
"value"
],
"fields": [
{
"fieldname": "key",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Key",
"reqd": 1
},
{
"fieldname": "value",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Value",
"options": "\ntransaction_date\nfrom_currency\nto_currency",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-02 15:24:24.675019",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange Settings Details",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@ -0,0 +1,8 @@
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class CurrencyExchangeSettingsDetails(Document):
pass

View File

@ -0,0 +1,39 @@
{
"actions": [],
"creation": "2021-09-02 15:18:17.888667",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"key",
"value"
],
"fields": [
{
"fieldname": "key",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Key",
"reqd": 1
},
{
"fieldname": "value",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Value",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-02 15:18:17.888667",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange Settings Extra Details",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@ -0,0 +1,8 @@
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class CurrencyExchangeSettingsExtraDetails(Document):
pass