diff --git a/setup/support/odoo/addons/support b/setup/support/odoo/addons/support new file mode 120000 index 0000000..49024cc --- /dev/null +++ b/setup/support/odoo/addons/support @@ -0,0 +1 @@ +../../../../support \ No newline at end of file diff --git a/setup/support/setup.py b/setup/support/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/support/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/support/__init__.py b/support/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/support/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/support/__manifest__.py b/support/__manifest__.py new file mode 100644 index 0000000..19150a3 --- /dev/null +++ b/support/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2025 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Support", + "summary": "Provide Akretion cross connect support integration", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Akretion", + "website": "https://github.com/akretion/support", + "depends": [ + "cross_connect_client", + ], + "data": [ + "data/cross_connect_server.xml", + "data/ir_actions_server.xml", + "security/res_groups.xml", + ], +} diff --git a/support/data/cross_connect_server.xml b/support/data/cross_connect_server.xml new file mode 100644 index 0000000..93d4754 --- /dev/null +++ b/support/data/cross_connect_server.xml @@ -0,0 +1,16 @@ + + + + + + Support + https://erp-fr.akretion.com/api-support + Paste remote api key here + + + + diff --git a/support/data/ir_actions_server.xml b/support/data/ir_actions_server.xml new file mode 100644 index 0000000..92131be --- /dev/null +++ b/support/data/ir_actions_server.xml @@ -0,0 +1,18 @@ + + + + + + Créer un ticket support + + code + action = model.redirect_to_support() + + + diff --git a/support/models/__init__.py b/support/models/__init__.py new file mode 100644 index 0000000..8fa8191 --- /dev/null +++ b/support/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_actions +from . import cross_connect_server diff --git a/support/models/cross_connect_server.py b/support/models/cross_connect_server.py new file mode 100644 index 0000000..2158707 --- /dev/null +++ b/support/models/cross_connect_server.py @@ -0,0 +1,82 @@ +# Copyright 2025 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import re + +from odoo import api, models +from urllib.parse import urlencode, urlparse + +AKRETION_EMAILS_RE = re.compile(r"^(.*@akretion\.com(\.br)?)$") + + +class CrossConnectServer(models.Model): + _inherit = "cross.connect.server" + + @api.model + def redirect_to_support(self): + """Redirect to the support page""" + server = self.env.ref("support.akretion_erp") + url = f"/cross_connect_server/{server.id}" + params = { + "origin_db": self.env.cr.dbname, + } + res_model = self.env.context.get("active_model") + res_id = self.env.context.get("active_id") + params["origin_url"] = ( + self.env["ir.config_parameter"].sudo().get_param("web.base.url") or "" + ) + if res_model and res_id: + record = self.env[res_model].browse(res_id) + params["origin_name"] = record.name_get()[0][1] + + url_params = { + "view_type": "form", + "model": res_model, + "id": res_id, + "active_id": res_id, + "cids": ",".join(str(x) for x in self.env.companies.ids), + } + + action = self.env.context.get("params", {}).get("action") + if not action: + action = self.env["ir.actions.act_window"].search( + [("res_model", "=", res_model), ("view_mode", "ilike", "form")], + limit=1, + ) + if action: + action = action.id + if action: + url_params["action"] = action + + params["origin_url"] += f"/web#{urlencode(url_params)}" + + redirect_params = { + "action": "project_customer_access.action_view_all_task", + "view_type": "form", + **{ + f"project.task_default_{field}": value + for field, value in params.items() + }, + } + + final_params = {"redirect_url": f"/web#{urlencode(redirect_params)}"} + url += "?" + urlencode(final_params) + target = "self" + + # Akretion users specific case + if self.env.user.email and AKRETION_EMAILS_RE.match(self.env.user.email): + redirect_params["action"] = ( + "custom_akretion_project.action_view_all_task_real" + ) + server_url = urlparse(server.server_url) + server_url = server_url._replace( + path="/web", + fragment=urlencode(redirect_params), + ) + url = server_url.geturl() + target = "new" + return { + "type": "ir.actions.act_url", + "url": url, + "target": target, + } diff --git a/support/models/ir_actions.py b/support/models/ir_actions.py new file mode 100644 index 0000000..07af48b --- /dev/null +++ b/support/models/ir_actions.py @@ -0,0 +1,23 @@ +# Copyright 2025 Akretion (http://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class IrActions(models.Model): + _inherit = "ir.actions.actions" + + @api.model + def get_bindings(self, model_name): + """Add support action to every model""" + res = super().get_bindings(model_name) + if self.env.user.has_group("support.akretion_erp_group_customer"): + action_id = "support.cross_connect_support" + if "action" in res: + if action_id not in [act.get("xml_id") for act in res["action"]]: + res["action"].append(self._for_xml_id(action_id)) + else: + res["action"] = [self._for_xml_id(action_id)] + + return res diff --git a/support/security/res_groups.xml b/support/security/res_groups.xml new file mode 100644 index 0000000..36486e2 --- /dev/null +++ b/support/security/res_groups.xml @@ -0,0 +1,27 @@ + + + + + + Support: Support User + + + + + Support: Support Manager + + + + + + Support: Support Budget Access + + + + + + diff --git a/support/static/img/icon.png b/support/static/img/icon.png new file mode 100644 index 0000000..b2fb4ae Binary files /dev/null and b/support/static/img/icon.png differ