From 5aefa334ba420a308bde7bb59d047c6c57af2284 Mon Sep 17 00:00:00 2001 From: Luis Rodriguez Date: Tue, 16 Dec 2025 16:47:37 +0100 Subject: [PATCH] access_fast: add module --- access_fast/README.rst | 82 ++++ access_fast/__init__.py | 2 + access_fast/__manifest__.py | 19 + access_fast/controllers/__init__.py | 1 + access_fast/controllers/main.py | 35 ++ access_fast/models/__init__.py | 1 + access_fast/models/ir_access_fast.py | 22 ++ access_fast/pyproject.toml | 3 + access_fast/readme/CONFIGURE.rst | 8 + access_fast/readme/DESCRIPTION.rst | 4 + access_fast/readme/USAGE.rst | 7 + access_fast/security/ir.model.access.csv | 3 + access_fast/static/description/index.html | 439 +++++++++++++++++++++ access_fast/tests/__init__.py | 1 + access_fast/tests/test_access_fast.py | 55 +++ access_fast/views/ir_access_fast_views.xml | 48 +++ 16 files changed, 730 insertions(+) create mode 100644 access_fast/README.rst create mode 100644 access_fast/__init__.py create mode 100644 access_fast/__manifest__.py create mode 100644 access_fast/controllers/__init__.py create mode 100644 access_fast/controllers/main.py create mode 100644 access_fast/models/__init__.py create mode 100644 access_fast/models/ir_access_fast.py create mode 100644 access_fast/pyproject.toml create mode 100644 access_fast/readme/CONFIGURE.rst create mode 100644 access_fast/readme/DESCRIPTION.rst create mode 100644 access_fast/readme/USAGE.rst create mode 100644 access_fast/security/ir.model.access.csv create mode 100644 access_fast/static/description/index.html create mode 100644 access_fast/tests/__init__.py create mode 100644 access_fast/tests/test_access_fast.py create mode 100644 access_fast/views/ir_access_fast_views.xml diff --git a/access_fast/README.rst b/access_fast/README.rst new file mode 100644 index 000000000..4dc918c3d --- /dev/null +++ b/access_fast/README.rst @@ -0,0 +1,82 @@ +=========== +Access Fast +=========== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:eb532dc50a55103c2e31ff07b32435a5b686c27b0fc26a0040a56b12d7f645da + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-tegin%2Fcb--addons-lightgray.png?logo=github + :target: https://github.com/tegin/cb-addons/tree/16.0/access_fast + :alt: tegin/cb-addons + +|badge1| |badge2| |badge3| + +This addon allows to retrieve specific records through queries. + +This module define generic flow to access records fastly through URL patterns. +So, you can define new actions to access different models and records just by defining new actions. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +#. Go to Settings > Technical > Database Structure > Access Fast +#. Create a new Access Fast Action, defining: + + - **Key**: A unique identifier for the action. + - **Model**: The model to access. + - **Field**: The field used to search the record (e.g., 'name', 'code'). + +Usage +===== + +To use this module, you need to: + +#. Open a session in Odoo with a user that has access to the target model. +#. Use the following URL pattern to access a record: /access_fast/<key>/<field_value> + + - **<key>**: The key defined in the Access Fast Action. + - **<field_value>**: The value of the field to search the record. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Dixmit +* CreuBlanca + +Maintainers +~~~~~~~~~~~ + +This module is part of the `tegin/cb-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/access_fast/__init__.py b/access_fast/__init__.py new file mode 100644 index 000000000..91c5580fe --- /dev/null +++ b/access_fast/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/access_fast/__manifest__.py b/access_fast/__manifest__.py new file mode 100644 index 000000000..710f9d84f --- /dev/null +++ b/access_fast/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Access Fast", + "summary": """This addon allows retrieving specific records through queries.""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,CreuBlanca", + "website": "https://github.com/tegin/cb-addons", + "depends": [ + "base", + ], + "data": [ + "security/ir.model.access.csv", + "views/ir_access_fast_views.xml", + ], + "demo": [], +} diff --git a/access_fast/controllers/__init__.py b/access_fast/controllers/__init__.py new file mode 100644 index 000000000..12a7e529b --- /dev/null +++ b/access_fast/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/access_fast/controllers/main.py b/access_fast/controllers/main.py new file mode 100644 index 000000000..a30316457 --- /dev/null +++ b/access_fast/controllers/main.py @@ -0,0 +1,35 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import http +from odoo.http import request + + +class AccessFastController(http.Controller): + @http.route( + "/access_fast//", + type="http", + methods=["GET"], + csrf=False, + ) + def access_fast(self, action_code, code, **kwargs): + + action = request.env["ir.access.fast"].search( + [("name", "=", action_code)], limit=1 + ) + if not action: + return request.make_response( + "Action not found", headers=[("Content-Type", "text/plain")], status=404 + ) + + record = ( + request.env[action.model_id.model] + .sudo() + .search([(action.field_id.name or "name", "=", code)], limit=1) + ) + if not record: + return request.make_response( + "Record not found", headers=[("Content-Type", "text/plain")], status=404 + ) + + return request.redirect(f"/web#model={action.model_id.model}&id={record.id}") diff --git a/access_fast/models/__init__.py b/access_fast/models/__init__.py new file mode 100644 index 000000000..8314099a7 --- /dev/null +++ b/access_fast/models/__init__.py @@ -0,0 +1 @@ +from . import ir_access_fast diff --git a/access_fast/models/ir_access_fast.py b/access_fast/models/ir_access_fast.py new file mode 100644 index 000000000..d7b09ffbc --- /dev/null +++ b/access_fast/models/ir_access_fast.py @@ -0,0 +1,22 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrAccessFast(models.Model): + _name = "ir.access.fast" + _description = "IR Access Fast Model" + + name = fields.Char(required=True) + model_id = fields.Many2one("ir.model", required=True, ondelete="cascade") + field_id = fields.Many2one( + "ir.model.fields", + domain="[('model_id', '=', model_id)]", + required=True, + ondelete="cascade", + ) + + _sql_constraints = [ + ("name_unique", "unique(name)", "The name must be unique."), + ] diff --git a/access_fast/pyproject.toml b/access_fast/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/access_fast/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/access_fast/readme/CONFIGURE.rst b/access_fast/readme/CONFIGURE.rst new file mode 100644 index 000000000..93df2ae4d --- /dev/null +++ b/access_fast/readme/CONFIGURE.rst @@ -0,0 +1,8 @@ +To configure this module, you need to: + +#. Go to Settings > Technical > Database Structure > Access Fast +#. Create a new Access Fast Action, defining: + + - **Key**: A unique identifier for the action. + - **Model**: The model to access. + - **Field**: The field used to search the record (e.g., 'name', 'code'). \ No newline at end of file diff --git a/access_fast/readme/DESCRIPTION.rst b/access_fast/readme/DESCRIPTION.rst new file mode 100644 index 000000000..15afe712c --- /dev/null +++ b/access_fast/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This addon allows to retrieve specific records through queries. + +This module define generic flow to access records fastly through URL patterns. +So, you can define new actions to access different models and records just by defining new actions. \ No newline at end of file diff --git a/access_fast/readme/USAGE.rst b/access_fast/readme/USAGE.rst new file mode 100644 index 000000000..7b164164c --- /dev/null +++ b/access_fast/readme/USAGE.rst @@ -0,0 +1,7 @@ +To use this module, you need to: + +#. Open a session in Odoo with a user that has access to the target model. +#. Use the following URL pattern to access a record: /access_fast/<key>/<field_value> + + - **<key>**: The key defined in the Access Fast Action. + - **<field_value>**: The value of the field to search the record. \ No newline at end of file diff --git a/access_fast/security/ir.model.access.csv b/access_fast/security/ir.model.access.csv new file mode 100644 index 000000000..04aa20769 --- /dev/null +++ b/access_fast/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_fast_user,access_fast_user,model_ir_access_fast,base.group_user,1,0,0,0 +access_fast_manager,access_fast_manager,model_ir_access_fast,base.group_erp_manager,1,1,1,1 diff --git a/access_fast/static/description/index.html b/access_fast/static/description/index.html new file mode 100644 index 000000000..d41818ba7 --- /dev/null +++ b/access_fast/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +Access Fast + + + +
+

Access Fast

+ + +

Beta License: AGPL-3 tegin/cb-addons

+

This addon allows to retrieve specific records through queries.

+

This module define generic flow to access records fastly through URL patterns. +So, you can define new actions to access different models and records just by defining new actions.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Settings > Technical > Database Structure > Access Fast
  2. +
  3. Create a new Access Fast Action, defining:
      +
    • Key: A unique identifier for the action.
    • +
    • Model: The model to access.
    • +
    • Field: The field used to search the record (e.g., ‘name’, ‘code’).
    • +
    +
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Open a session in Odoo with a user that has access to the target model.
  2. +
  3. Use the following URL pattern to access a record: /access_fast/&lt;key&gt;/&lt;field_value&gt;
      +
    • &lt;key&gt;: The key defined in the Access Fast Action.
    • +
    • &lt;field_value&gt;: The value of the field to search the record.
    • +
    +
  4. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Dixmit
  • +
  • CreuBlanca
  • +
+
+
+

Maintainers

+

This module is part of the tegin/cb-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/access_fast/tests/__init__.py b/access_fast/tests/__init__.py new file mode 100644 index 000000000..b8a8b8f66 --- /dev/null +++ b/access_fast/tests/__init__.py @@ -0,0 +1 @@ +from . import test_access_fast diff --git a/access_fast/tests/test_access_fast.py b/access_fast/tests/test_access_fast.py new file mode 100644 index 000000000..4d9149a6a --- /dev/null +++ b/access_fast/tests/test_access_fast.py @@ -0,0 +1,55 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import HttpCase + + +class TestAccessFast(HttpCase): + def setUp(self): + super().setUp() + self.access_fast = self.env["ir.access.fast"].create( + { + "name": "RP", + "model_id": self.env.ref("base.model_res_partner").id, + "field_id": self.env.ref("base.field_res_partner__name").id, + } + ) + self.partner = self.env["res.partner"].create( + { + "name": "partner", + "email": "test@example.com", + } + ) + + def test_unauthenticated(self): + + result = self.url_open("/access_fast/RP/partner", allow_redirects=False) + + self.assertEqual(result.status_code, 303) + self.assertIn("/web/login", result.headers["Location"]) + + def test_wrong_action(self): + + self.authenticate("admin", "admin") + + result = self.url_open("/access_fast/AA/partner") + + self.assertEqual(result.status_code, 404) + self.assertEqual(result.text, "Action not found") + + def test_wrong_record(self): + + self.authenticate("admin", "admin") + + result = self.url_open("/access_fast/RP/falsePartner") + + self.assertEqual(result.status_code, 404) + self.assertEqual(result.text, "Record not found") + + def test_access_fast(self): + + self.authenticate("admin", "admin") + + result = self.url_open("/access_fast/RP/partner", allow_redirects=False) + + self.assertEqual(result.status_code, 303) diff --git a/access_fast/views/ir_access_fast_views.xml b/access_fast/views/ir_access_fast_views.xml new file mode 100644 index 000000000..e395b5915 --- /dev/null +++ b/access_fast/views/ir_access_fast_views.xml @@ -0,0 +1,48 @@ + + + + + ir.access.fast.form + ir.access.fast + +
+
+ + + + + + + + + + + + + ir.access.fast.tree + ir.access.fast + + + + + + + + + + + Access Fast + ir.access.fast + tree,form + [] + {} + + + + Access Fast + + + + + +