diff --git a/pingen_env/README.rst b/pingen_env/README.rst new file mode 100644 index 00000000000..39f30feb615 --- /dev/null +++ b/pingen_env/README.rst @@ -0,0 +1 @@ +to update diff --git a/pingen_env/__init__.py b/pingen_env/__init__.py new file mode 100644 index 00000000000..53b49ac328a --- /dev/null +++ b/pingen_env/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import models +from .hooks import post_init_hook diff --git a/pingen_env/__manifest__.py b/pingen_env/__manifest__.py new file mode 100644 index 00000000000..b8ffe4e0aec --- /dev/null +++ b/pingen_env/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "pingen.com server environment", + "version": "16.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "maintainers": ["ajaniszewska-dev"], + "license": "AGPL-3", + "category": "Reporting", + "complexity": "easy", + "depends": ["pingen", "server_environment"], + "website": "https://github.com/OCA/report-print-send", + "post_init_hook": "post_init_hook", + "installable": True, + "auto_install": False, + "application": False, +} diff --git a/pingen_env/hooks.py b/pingen_env/hooks.py new file mode 100644 index 00000000000..7fd364e9384 --- /dev/null +++ b/pingen_env/hooks.py @@ -0,0 +1,15 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + + +def post_init_hook(cr, registry): + # When installing pingen_env we want to delete data from DB + cr.execute( + """UPDATE res_company + SET pingen_clientid = NULL, + pingen_client_secretid = NULL, + pingen_organization = NULL, + pingen_staging = NULL, + pingen_webhook_secret = NULL; + """ + ) diff --git a/pingen_env/models/__init__.py b/pingen_env/models/__init__.py new file mode 100644 index 00000000000..68cffd9b127 --- /dev/null +++ b/pingen_env/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import res_company diff --git a/pingen_env/models/res_company.py b/pingen_env/models/res_company.py new file mode 100644 index 00000000000..07d72d34430 --- /dev/null +++ b/pingen_env/models/res_company.py @@ -0,0 +1,45 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models + +from odoo.addons.server_environment import serv_config + + +class ResCompany(models.Model): + _inherit = ["res.company"] + + pingen_clientid = fields.Char( + compute="_compute_pingen_env", required=False, readonly=True + ) + pingen_client_secretid = fields.Char( + compute="_compute_pingen_env", required=False, readonly=True + ) + pingen_organization = fields.Char( + compute="_compute_pingen_env", required=False, readonly=True + ) + pingen_staging = fields.Boolean( + compute="_compute_pingen_env", required=False, readonly=True + ) + pingen_webhook_secret = fields.Char( + compute="_compute_pingen_env", required=False, readonly=True + ) + + @api.depends() + def _compute_pingen_env(self): + global_section_name = "pingen" + for company in self: + # default vals + config_vals = { + "pingen_clientid": "", + "pingen_client_secretid": "", + "pingen_organization": "", + "pingen_staging": True, + "pingen_webhook_secret": "", + } + if serv_config.has_section(global_section_name): + config_vals.update(serv_config.items(global_section_name)) + custom_section_name = global_section_name + "." + company.name + if serv_config.has_section(custom_section_name): + config_vals.update(serv_config.items(custom_section_name)) + company.update(config_vals) diff --git a/pingen_env/readme/CONTRIBUTORS.rst b/pingen_env/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..4124e67fb5c --- /dev/null +++ b/pingen_env/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Anna Janiszewska diff --git a/setup/pingen_env/odoo/addons/pingen_env b/setup/pingen_env/odoo/addons/pingen_env new file mode 120000 index 00000000000..1bcd06e2c9e --- /dev/null +++ b/setup/pingen_env/odoo/addons/pingen_env @@ -0,0 +1 @@ +../../../../pingen_env \ No newline at end of file diff --git a/setup/pingen_env/setup.py b/setup/pingen_env/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/pingen_env/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)