mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-25 13:03:02 +00:00
feat: option for preconfigured selectable service providers
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
// 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) {
|
||||
frm.add_custom_button(__('Restore Defaults'), function(){
|
||||
frm.doc.api_endpoint = "https://api.exchangerate.host/convert";
|
||||
frm.clear_table("req_params")
|
||||
frm.clear_table("result_key")
|
||||
let params = {
|
||||
date: '{transaction_date}',
|
||||
from: '{from_currency}',
|
||||
to: '{to_currency}'
|
||||
}
|
||||
var row;
|
||||
$.each(params, function(key, value){
|
||||
row = frm.add_child("req_params");
|
||||
row.key = key;
|
||||
row.value = value;
|
||||
})
|
||||
row = frm.add_child("result_key");
|
||||
row.key = 'result';
|
||||
frm.refresh_fields();
|
||||
frm.save();
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,94 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-09-02 14:53:50.923529",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"api_details_section",
|
||||
"api_endpoint",
|
||||
"url",
|
||||
"column_break_3",
|
||||
"help",
|
||||
"section_break_2",
|
||||
"req_params",
|
||||
"column_break_4",
|
||||
"result_key"
|
||||
],
|
||||
"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": "Parameters",
|
||||
"options": "Currency Exchange Settings Details",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "api_details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "API Details"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "result_key",
|
||||
"fieldtype": "Table",
|
||||
"label": "Result Key",
|
||||
"options": "Currency Exchange Settings Result",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "url",
|
||||
"fieldtype": "Data",
|
||||
"label": "Example URL",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "help",
|
||||
"fieldtype": "HTML",
|
||||
"label": "Help",
|
||||
"options": "<h3>Currency Exchange Settings Help</h3>\n<p>There are 3 variables that could be used within the endpoint, result key and in values of the parameter.</p>\n<p>Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.</p>\n<p>Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}</p>"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 11:41:34.375637",
|
||||
"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
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import nowdate
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CurrencyExchangeSettings(Document):
|
||||
def validate(self):
|
||||
transaction_date = nowdate()
|
||||
from_currency = 'USD'
|
||||
to_currency = 'INR'
|
||||
params = {}
|
||||
for row in self.req_params:
|
||||
params[row.key] = row.value.format(
|
||||
transaction_date=transaction_date,
|
||||
to_currency=to_currency,
|
||||
from_currency=from_currency
|
||||
)
|
||||
import requests
|
||||
api_url = self.api_endpoint.format(
|
||||
transaction_date=transaction_date,
|
||||
to_currency=to_currency,
|
||||
from_currency=from_currency
|
||||
)
|
||||
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:
|
||||
for key in self.result_key:
|
||||
value = value[str(key.key).format(
|
||||
transaction_date=transaction_date,
|
||||
to_currency=to_currency,
|
||||
from_currency=from_currency
|
||||
)]
|
||||
except Exception:
|
||||
frappe.throw("Invalid result key. Response: " + response.text)
|
||||
if not isinstance(value, (int, float)):
|
||||
frappe.throw(_("Returned exchange rate is neither integer not float."))
|
||||
self.url = response.url
|
||||
frappe.msgprint("Exchange rate of USD to INR is " + str(value))
|
||||
@@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCurrencyExchangeSettings(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,39 +0,0 @@
|
||||
{
|
||||
"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": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Value",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 17:49:17.383982",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Currency Exchange Settings Details",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# 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
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-09-03 13:17:22.088259",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"key"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "key",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Key",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 17:49:33.858070",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Currency Exchange Settings Result",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CurrencyExchangeSettingsResult(Document):
|
||||
pass
|
||||
Reference in New Issue
Block a user