refactor(plaid): move configuration from site_config to doctype (#18712)
* feat(plaid): move plaid from site_config to doctype plaid requires accessing site_config and cloud users cannot access site_config and hence, plaid integration doesn't work on the cloud. Moving all the configuration from site_config to the Plaid Settings doctype fixes this issue. Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * feat(plaid): make changes to plaid_settings and add patch * remove all references for get()-ing plaid variables from frappe.conf and replace them with values from doctype * add patch to move all existing plaid settings variable values from frappe.conf to plaid_settings doctype Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * fix(plaid): use get_single_value for Plaid Settings Co-Authored-By: Himanshu <himanshuwarekar@yahoo.com> * chore: reload plaid_settings before running patch Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * chore: remove useless semicolon fuck codacy Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
parent
f8899827e0
commit
b3c732daf5
@ -3,30 +3,31 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
import requests
|
from frappe.utils.password import get_decrypted_password
|
||||||
from plaid import Client
|
from plaid import Client
|
||||||
from plaid.errors import APIError, ItemError
|
from plaid.errors import APIError, ItemError
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
import requests
|
||||||
|
|
||||||
class PlaidConnector():
|
class PlaidConnector():
|
||||||
def __init__(self, access_token=None):
|
def __init__(self, access_token=None):
|
||||||
|
|
||||||
if not(frappe.conf.get("plaid_client_id") and frappe.conf.get("plaid_secret") and frappe.conf.get("plaid_public_key")):
|
plaid_settings = frappe.get_single("Plaid Settings")
|
||||||
frappe.throw(_("Please complete your Plaid API configuration before synchronizing your account"))
|
|
||||||
|
|
||||||
self.config = {
|
self.config = {
|
||||||
"plaid_client_id": frappe.conf.get("plaid_client_id"),
|
"plaid_client_id": plaid_settings.plaid_client_id,
|
||||||
"plaid_secret": frappe.conf.get("plaid_secret"),
|
"plaid_secret": get_decrypted_password("Plaid Settings", "Plaid Settings", 'plaid_secret'),
|
||||||
"plaid_public_key": frappe.conf.get("plaid_public_key"),
|
"plaid_public_key": plaid_settings.plaid_public_key,
|
||||||
"plaid_env": frappe.conf.get("plaid_env")
|
"plaid_env": plaid_settings.plaid_env
|
||||||
}
|
}
|
||||||
|
|
||||||
self.client = Client(client_id=self.config["plaid_client_id"],
|
self.client = Client(client_id=self.config.get("plaid_client_id"),
|
||||||
secret=self.config["plaid_secret"],
|
secret=self.config.get("plaid_secret"),
|
||||||
public_key=self.config["plaid_public_key"],
|
public_key=self.config.get("plaid_public_key"),
|
||||||
environment=self.config["plaid_env"]
|
environment=self.config.get("plaid_env")
|
||||||
)
|
)
|
||||||
|
|
||||||
self.access_token = access_token
|
self.access_token = access_token
|
||||||
|
|
||||||
@ -78,4 +79,4 @@ class PlaidConnector():
|
|||||||
transactions.extend(response['transactions'])
|
transactions.extend(response['transactions'])
|
||||||
return transactions
|
return transactions
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
|
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
|
||||||
|
@ -4,8 +4,18 @@
|
|||||||
frappe.provide("erpnext.integrations");
|
frappe.provide("erpnext.integrations");
|
||||||
|
|
||||||
frappe.ui.form.on('Plaid Settings', {
|
frappe.ui.form.on('Plaid Settings', {
|
||||||
link_new_account: function(frm) {
|
enabled: function(frm) {
|
||||||
new erpnext.integrations.plaidLink(frm);
|
frm.toggle_reqd('plaid_client_id', frm.doc.enabled);
|
||||||
|
frm.toggle_reqd('plaid_secret', frm.doc.enabled);
|
||||||
|
frm.toggle_reqd('plaid_public_key', frm.doc.enabled);
|
||||||
|
frm.toggle_reqd('plaid_env', frm.doc.enabled);
|
||||||
|
},
|
||||||
|
refresh: function(frm) {
|
||||||
|
if(frm.doc.enabled) {
|
||||||
|
frm.add_custom_button('Link a new bank account', () => {
|
||||||
|
new erpnext.integrations.plaidLink(frm);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -19,20 +29,10 @@ erpnext.integrations.plaidLink = class plaidLink {
|
|||||||
|
|
||||||
init_config() {
|
init_config() {
|
||||||
const me = this;
|
const me = this;
|
||||||
frappe.xcall('erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.plaid_configuration')
|
me.plaid_env = me.frm.doc.plaid_env;
|
||||||
.then(result => {
|
me.plaid_public_key = me.frm.doc.plaid_public_key;
|
||||||
if (result !== "disabled") {
|
me.client_name = frappe.boot.sitename;
|
||||||
if (result.plaid_env == undefined || result.plaid_public_key == undefined) {
|
me.init_plaid();
|
||||||
frappe.throw(__("Please add valid Plaid api keys in site_config.json first"));
|
|
||||||
}
|
|
||||||
me.plaid_env = result.plaid_env;
|
|
||||||
me.plaid_public_key = result.plaid_public_key;
|
|
||||||
me.client_name = result.client_name;
|
|
||||||
me.init_plaid();
|
|
||||||
} else {
|
|
||||||
frappe.throw(__("Please save your document before adding a new account"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_plaid() {
|
init_plaid() {
|
||||||
@ -104,4 +104,4 @@ erpnext.integrations.plaidLink = class plaidLink {
|
|||||||
});
|
});
|
||||||
}, __("Select a company"), __("Continue"));
|
}, __("Select a company"), __("Continue"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,161 +1,96 @@
|
|||||||
{
|
{
|
||||||
"allow_copy": 0,
|
"creation": "2018-10-25 10:02:48.656165",
|
||||||
"allow_events_in_timeline": 0,
|
"doctype": "DocType",
|
||||||
"allow_guest_to_view": 0,
|
"editable_grid": 1,
|
||||||
"allow_import": 0,
|
"engine": "InnoDB",
|
||||||
"allow_rename": 0,
|
"field_order": [
|
||||||
"beta": 0,
|
"enabled",
|
||||||
"creation": "2018-10-25 10:02:48.656165",
|
"column_break_2",
|
||||||
"custom": 0,
|
"automatic_sync",
|
||||||
"docstatus": 0,
|
"section_break_4",
|
||||||
"doctype": "DocType",
|
"plaid_client_id",
|
||||||
"document_type": "",
|
"plaid_secret",
|
||||||
"editable_grid": 1,
|
"column_break_7",
|
||||||
"engine": "InnoDB",
|
"plaid_public_key",
|
||||||
|
"plaid_env"
|
||||||
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"default": "0",
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "enabled",
|
||||||
"allow_on_submit": 0,
|
"fieldtype": "Check",
|
||||||
"bold": 0,
|
"label": "Enabled"
|
||||||
"collapsible": 0,
|
},
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "enabled",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Enabled",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"default": "0",
|
||||||
"allow_in_quick_entry": 0,
|
"depends_on": "eval:doc.enabled==1",
|
||||||
"allow_on_submit": 0,
|
"fieldname": "automatic_sync",
|
||||||
"bold": 0,
|
"fieldtype": "Check",
|
||||||
"collapsible": 0,
|
"label": "Synchronize all accounts every hour"
|
||||||
"columns": 0,
|
},
|
||||||
"depends_on": "eval:doc.enabled==1",
|
|
||||||
"fieldname": "automatic_sync",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Synchronize all accounts every hour",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"depends_on": "eval:doc.enabled==1",
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "plaid_client_id",
|
||||||
"allow_on_submit": 0,
|
"fieldtype": "Data",
|
||||||
"bold": 0,
|
"in_list_view": 1,
|
||||||
"collapsible": 0,
|
"label": "Plaid Client ID",
|
||||||
"columns": 0,
|
"reqd": 1
|
||||||
"depends_on": "eval:(doc.enabled==1)&&(!doc.__islocal)",
|
},
|
||||||
"fieldname": "link_new_account",
|
{
|
||||||
"fieldtype": "Button",
|
"depends_on": "eval:doc.enabled==1",
|
||||||
"hidden": 0,
|
"fieldname": "plaid_secret",
|
||||||
"ignore_user_permissions": 0,
|
"fieldtype": "Password",
|
||||||
"ignore_xss_filter": 0,
|
"in_list_view": 1,
|
||||||
"in_filter": 0,
|
"label": "Plaid Secret",
|
||||||
"in_global_search": 0,
|
"reqd": 1
|
||||||
"in_list_view": 0,
|
},
|
||||||
"in_standard_filter": 0,
|
{
|
||||||
"label": "Link a new bank account",
|
"depends_on": "eval:doc.enabled==1",
|
||||||
"length": 0,
|
"fieldname": "plaid_public_key",
|
||||||
"no_copy": 0,
|
"fieldtype": "Data",
|
||||||
"permlevel": 0,
|
"in_list_view": 1,
|
||||||
"precision": "",
|
"label": "Plaid Public Key",
|
||||||
"print_hide": 0,
|
"reqd": 1
|
||||||
"print_hide_if_no_value": 0,
|
},
|
||||||
"read_only": 0,
|
{
|
||||||
"remember_last_selected_value": 0,
|
"depends_on": "eval:doc.enabled==1",
|
||||||
"report_hide": 0,
|
"fieldname": "plaid_env",
|
||||||
"reqd": 0,
|
"fieldtype": "Data",
|
||||||
"search_index": 0,
|
"in_list_view": 1,
|
||||||
"set_only_once": 0,
|
"label": "Plaid Environment",
|
||||||
"translatable": 0,
|
"reqd": 1
|
||||||
"unique": 0
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_2",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_4",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_7",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"has_web_view": 0,
|
"issingle": 1,
|
||||||
"hide_heading": 0,
|
"modified": "2019-08-13 17:00:06.939422",
|
||||||
"hide_toolbar": 0,
|
"modified_by": "Administrator",
|
||||||
"idx": 0,
|
"module": "ERPNext Integrations",
|
||||||
"image_view": 0,
|
"name": "Plaid Settings",
|
||||||
"in_create": 0,
|
"owner": "Administrator",
|
||||||
"is_submittable": 0,
|
|
||||||
"issingle": 1,
|
|
||||||
"istable": 0,
|
|
||||||
"max_attachments": 0,
|
|
||||||
"modified": "2018-12-14 12:51:12.331395",
|
|
||||||
"modified_by": "Administrator",
|
|
||||||
"module": "ERPNext Integrations",
|
|
||||||
"name": "Plaid Settings",
|
|
||||||
"name_case": "",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
"amend": 0,
|
"create": 1,
|
||||||
"cancel": 0,
|
"delete": 1,
|
||||||
"create": 1,
|
"email": 1,
|
||||||
"delete": 1,
|
"print": 1,
|
||||||
"email": 1,
|
"read": 1,
|
||||||
"export": 0,
|
"role": "System Manager",
|
||||||
"if_owner": 0,
|
"share": 1,
|
||||||
"import": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"print": 1,
|
|
||||||
"read": 1,
|
|
||||||
"report": 0,
|
|
||||||
"role": "System Manager",
|
|
||||||
"set_user_permissions": 0,
|
|
||||||
"share": 1,
|
|
||||||
"submit": 0,
|
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quick_entry": 0,
|
"sort_field": "modified",
|
||||||
"read_only": 0,
|
"sort_order": "DESC"
|
||||||
"read_only_onload": 0,
|
|
||||||
"show_name_in_global_search": 0,
|
|
||||||
"sort_field": "modified",
|
|
||||||
"sort_order": "DESC",
|
|
||||||
"track_changes": 0,
|
|
||||||
"track_seen": 0,
|
|
||||||
"track_views": 0
|
|
||||||
}
|
}
|
@ -16,8 +16,13 @@ class PlaidSettings(Document):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def plaid_configuration():
|
def plaid_configuration():
|
||||||
if frappe.db.get_value("Plaid Settings", None, "enabled") == "1":
|
if frappe.db.get_single_value("Plaid Settings", "enabled"):
|
||||||
return {"plaid_public_key": frappe.conf.get("plaid_public_key") or None, "plaid_env": frappe.conf.get("plaid_env") or None, "client_name": frappe.local.site }
|
plaid_settings = frappe.get_single("Plaid Settings")
|
||||||
|
return {
|
||||||
|
"plaid_public_key": plaid_settings.plaid_public_key,
|
||||||
|
"plaid_env": plaid_settings.plaid_env,
|
||||||
|
"client_name": frappe.local.site
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
return "disabled"
|
return "disabled"
|
||||||
|
|
||||||
|
@ -625,6 +625,7 @@ erpnext.patches.v12_0.add_default_buying_selling_terms_in_company
|
|||||||
erpnext.patches.v12_0.update_ewaybill_field_position
|
erpnext.patches.v12_0.update_ewaybill_field_position
|
||||||
erpnext.patches.v12_0.create_accounting_dimensions_in_missing_doctypes
|
erpnext.patches.v12_0.create_accounting_dimensions_in_missing_doctypes
|
||||||
erpnext.patches.v11_1.set_status_for_material_request_type_manufacture
|
erpnext.patches.v11_1.set_status_for_material_request_type_manufacture
|
||||||
|
erpnext.patches.v12_0.move_plaid_settings_to_doctype
|
||||||
execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_link')
|
execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_link')
|
||||||
execute:frappe.reload_doc('desk', 'doctype','dashboard')
|
execute:frappe.reload_doc('desk', 'doctype','dashboard')
|
||||||
execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_source')
|
execute:frappe.reload_doc('desk', 'doctype','dashboard_chart_source')
|
||||||
|
22
erpnext/patches/v12_0/move_plaid_settings_to_doctype.py
Normal file
22
erpnext/patches/v12_0/move_plaid_settings_to_doctype.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright (c) 2017, Frappe and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
frappe.reload_doc("erpnext_integrations", "doctype", "plaid_settings")
|
||||||
|
plaid_settings = frappe.get_single("Plaid Settings")
|
||||||
|
if plaid_settings.enabled:
|
||||||
|
if not (frappe.conf.plaid_client_id and frappe.conf.plaid_env \
|
||||||
|
and frappe.conf.plaid_public_key and frappe.conf.plaid_secret):
|
||||||
|
plaid_settings.enabled = 0
|
||||||
|
else:
|
||||||
|
plaid_settings.update({
|
||||||
|
"plaid_client_id": frappe.conf.plaid_client_id,
|
||||||
|
"plaid_public_key": frappe.conf.plaid_public_key,
|
||||||
|
"plaid_env": frappe.conf.plaid_env,
|
||||||
|
"plaid_secret": frappe.conf.plaid_secret
|
||||||
|
})
|
||||||
|
plaid_settings.flags.ignore_mandatory = True
|
||||||
|
plaid_settings.save()
|
Loading…
Reference in New Issue
Block a user