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


import influxframework


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