# Copyright (c) 2017, Xhiveframework and Contributors
# License: GNU General Public License v3. See license.txt


import xhiveframework


def execute():
	xhiveframework.reload_doc("xhiveerp_integrations", "doctype", "plaid_settings")
	plaid_settings = xhiveframework.get_single("Plaid Settings")
	if plaid_settings.enabled:
		if not (xhiveframework.conf.plaid_client_id and xhiveframework.conf.plaid_env and xhiveframework.conf.plaid_secret):
			plaid_settings.enabled = 0
		else:
			plaid_settings.update(
				{
					"plaid_client_id": xhiveframework.conf.plaid_client_id,
					"plaid_env": xhiveframework.conf.plaid_env,
					"plaid_secret": xhiveframework.conf.plaid_secret,
				}
			)
		plaid_settings.flags.ignore_mandatory = True
		plaid_settings.save()
