diff --git a/server_environment_iap/__init__.py b/server_environment_iap/__init__.py
new file mode 100644
index 0000000..0650744
--- /dev/null
+++ b/server_environment_iap/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/server_environment_iap/__manifest__.py b/server_environment_iap/__manifest__.py
new file mode 100644
index 0000000..25be39c
--- /dev/null
+++ b/server_environment_iap/__manifest__.py
@@ -0,0 +1,13 @@
+# Copyright 2021 Camptocamp SA
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+{
+ "name": "IAP Account configuration with server_environment",
+ "summary": "Configure IAP Account with server_environment_files",
+ "version": "14.0.1.0.0",
+ "license": "AGPL-3",
+ "author": "Camptocamp, Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/server-env",
+ "depends": ["iap", "server_environment"],
+ "data": ["views/iap_views.xml"],
+}
diff --git a/server_environment_iap/models/__init__.py b/server_environment_iap/models/__init__.py
new file mode 100644
index 0000000..966d7e1
--- /dev/null
+++ b/server_environment_iap/models/__init__.py
@@ -0,0 +1 @@
+from . import iap_account
diff --git a/server_environment_iap/models/iap_account.py b/server_environment_iap/models/iap_account.py
new file mode 100644
index 0000000..5be8c05
--- /dev/null
+++ b/server_environment_iap/models/iap_account.py
@@ -0,0 +1,31 @@
+# Copyright 2021 Camptocamp SA
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
+
+from odoo import api, models
+
+
+class IapAccount(models.Model):
+ _name = "iap.account"
+ _inherit = [
+ "iap.account",
+ "server.env.techname.mixin",
+ "server.env.mixin",
+ ]
+
+ @property
+ def _server_env_fields(self):
+ base_fields = super()._server_env_fields
+ iap_fields = {
+ "service_name": {},
+ "account_token": {},
+ }
+ iap_fields.update(base_fields)
+ return iap_fields
+
+ @api.model
+ def _server_env_global_section_name(self):
+ """Name of the global section in the configuration files
+
+ Can be customized in your model
+ """
+ return "iap_account"
diff --git a/server_environment_iap/readme/CONFIGURE.rst b/server_environment_iap/readme/CONFIGURE.rst
new file mode 100644
index 0000000..a98f6a0
--- /dev/null
+++ b/server_environment_iap/readme/CONFIGURE.rst
@@ -0,0 +1,4 @@
+With this module installed, the IAP Accounts can be configured
+in the `server_environment_files` module, or in the environment variable ``SERVER_ENV_CONFIG``
+and/or ``SERVER_ENV_CONFIG_SECRET``. See the documentation of `server_environment` for
+more information.
diff --git a/server_environment_iap/readme/CONTRIBUTORS.rst b/server_environment_iap/readme/CONTRIBUTORS.rst
new file mode 100644
index 0000000..accaa82
--- /dev/null
+++ b/server_environment_iap/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
+* Maksym Yankin (https://https://www.camptocamp.com)
diff --git a/server_environment_iap/readme/DESCRIPTION.rst b/server_environment_iap/readme/DESCRIPTION.rst
new file mode 100644
index 0000000..350b29c
--- /dev/null
+++ b/server_environment_iap/readme/DESCRIPTION.rst
@@ -0,0 +1,3 @@
+This module allows to configure the IAP Accounts
+using the `server_environment` mechanism: you can then have different
+IAP Accounts for the production and the test environment.
diff --git a/server_environment_iap/readme/ROADMAP.rst b/server_environment_iap/readme/ROADMAP.rst
new file mode 100644
index 0000000..647e064
--- /dev/null
+++ b/server_environment_iap/readme/ROADMAP.rst
@@ -0,0 +1,2 @@
+* Due to the special nature of this addon, you cannot test it on the OCA
+ runbot.
diff --git a/server_environment_iap/tests/__init__.py b/server_environment_iap/tests/__init__.py
new file mode 100644
index 0000000..210651a
--- /dev/null
+++ b/server_environment_iap/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_server_environment_iap
diff --git a/server_environment_iap/tests/config_iap_test.xml b/server_environment_iap/tests/config_iap_test.xml
new file mode 100644
index 0000000..4e0d167
--- /dev/null
+++ b/server_environment_iap/tests/config_iap_test.xml
@@ -0,0 +1,7 @@
+
+
+ account_xml
+ iap_from_config
+ value_from_xml
+
+
diff --git a/server_environment_iap/tests/test_server_environment_iap.py b/server_environment_iap/tests/test_server_environment_iap.py
new file mode 100644
index 0000000..b1bc928
--- /dev/null
+++ b/server_environment_iap/tests/test_server_environment_iap.py
@@ -0,0 +1,87 @@
+# Copyright 2016-2018 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+import psycopg2
+
+from odoo.modules.module import get_resource_path
+from odoo.tests.common import Form
+from odoo.tools import convert_file
+from odoo.tools.misc import mute_logger
+
+from odoo.addons.server_environment.tests.common import ServerEnvironmentCase
+
+
+class TestEnv(ServerEnvironmentCase):
+ def setUp(self):
+ super().setUp()
+ self.IAP = self.env["iap.account"]
+ self.env_config = (
+ "[iap_account.account_1]\n"
+ "service_name=partner_autocomplete_1\n"
+ "account_token=my_secret_token_1\n"
+ "[iap_account.account_2]\n"
+ "service_name=partner_autocomplete_2\n"
+ "account_token=my_secret_token_2\n"
+ "[iap_account.account_xml]\n"
+ "service_name=partner_autocomplete_xml\n"
+ "account_token=my_secret_token_xml\n"
+ )
+
+ def _load_xml(self, module, filepath):
+ convert_file(
+ self.env.cr,
+ module,
+ get_resource_path(module, filepath),
+ {},
+ mode="init",
+ noupdate=False,
+ kind="test",
+ )
+
+ def test_create_account_from_config(self):
+ """Get account data from config"""
+ with self.load_config(public=self.env_config):
+ account = self.IAP.create({"tech_name": "account_1"})
+ self.assertEqual(account.service_name, "partner_autocomplete_1")
+ self.assertEqual(account.account_token, "my_secret_token_1")
+ # `tech_name` must be unique
+ with self.assertRaises(psycopg2.IntegrityError):
+ with mute_logger("odoo.sql_db"), self.cr.savepoint():
+ self.IAP.create({"tech_name": "account_1"})
+
+ def test_create_account_not_in_config(self):
+ """We can set account data that is not in config file"""
+ with self.load_config(public=self.env_config):
+ account = self.IAP.create(
+ {
+ "tech_name": "account_4",
+ "service_name": "new_partner_autocomplete",
+ "account_token": "my_new_secret_token",
+ }
+ )
+ self.assertEqual(account.service_name, "new_partner_autocomplete")
+ self.assertEqual(account.account_token, "my_new_secret_token")
+
+ # TODO: should it be overriden on xml import?
+ # def test_override_xmldata(self):
+ # with self.load_config(public=self.env_config):
+ # self._load_xml("server_environment_iap", "tests/config_iap_test.xml")
+ # account = self.IAP.search([("tech_name", "=", "account_xml")])
+ # self.assertEqual(account.service_name, "partner_autocomplete_xml")
+ # self.assertEqual(account.account_token, "my_secret_token_xml")
+
+ def test_update_account_data(self):
+ """We can't set account data that is in config file"""
+ with self.load_config(public=self.env_config):
+ # when creating, the value is overridden by config file
+ account = self.IAP.create(
+ {
+ "tech_name": "account_2",
+ }
+ )
+ account_form = Form(account)
+ self.assertEqual(account.service_name, "partner_autocomplete_2")
+ self.assertEqual(account.account_token, "my_secret_token_2")
+ with self.assertRaises(AssertionError):
+ account_form.service_name = "new_partner_autocomplete"
+ with self.assertRaises(AssertionError):
+ account_form.account_token = "my_new_secret_token"
diff --git a/server_environment_iap/views/iap_views.xml b/server_environment_iap/views/iap_views.xml
new file mode 100644
index 0000000..106621a
--- /dev/null
+++ b/server_environment_iap/views/iap_views.xml
@@ -0,0 +1,25 @@
+
+
+
+ iap.account.form.inherit
+ iap.account
+
+
+
+
+
+
+
+
+
+ iap.account.tree.inherit
+ iap.account
+
+
+
+
+
+
+
+
+
diff --git a/setup/server_environment_iap/odoo/addons/server_environment_iap b/setup/server_environment_iap/odoo/addons/server_environment_iap
new file mode 120000
index 0000000..e21dc23
--- /dev/null
+++ b/setup/server_environment_iap/odoo/addons/server_environment_iap
@@ -0,0 +1 @@
+../../../../server_environment_iap
\ No newline at end of file
diff --git a/setup/server_environment_iap/setup.py b/setup/server_environment_iap/setup.py
new file mode 100644
index 0000000..28c57bb
--- /dev/null
+++ b/setup/server_environment_iap/setup.py
@@ -0,0 +1,6 @@
+import setuptools
+
+setuptools.setup(
+ setup_requires=['setuptools-odoo'],
+ odoo_addon=True,
+)