-
-
Notifications
You must be signed in to change notification settings - Fork 361
[14.0][ADD] extendable: New addon to alllow usage of the Extendable python … #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| ========== | ||
| Extendable | ||
| ========== | ||
|
|
||
| .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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-LGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
| :alt: License: LGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/rest-framework/tree/14.0/extendable | ||
| :alt: OCA/rest-framework | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/rest-framework-14-0/rest-framework-14-0-extendable | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
| :target: https://runbot.odoo-community.org/runbot/271/14.0 | ||
| :alt: Try me on Runbot | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This addon allows you to use the `Extendable library`_ within Odoo. | ||
|
|
||
| .. _Extendable library: : <https://pypi.org/project/extendable/> | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| By default, all extendable classes defined into your odoo addons are automatically | ||
| loaded by the current addon according to the dependency graph computed by Odoo. | ||
|
|
||
| Known issues / Roadmap | ||
| ====================== | ||
|
|
||
| The `roadmap <https://github.com/OCA/odoo-addon-extendable/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Aextendable>`_ | ||
| and `known issues <https://github.com/OCA/odoo-addon-extendable/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aextendable>`_ can | ||
| be found on GitHub. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20extendable%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ~~~~~~~ | ||
|
|
||
| * ACSONE SA/NV | ||
|
|
||
| Contributors | ||
| ~~~~~~~~~~~~ | ||
|
|
||
| * Laurent Mignon <laurent.mignon@acsone.eu> | ||
|
|
||
| Maintainers | ||
| ~~~~~~~~~~~ | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| .. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px | ||
| :target: https://github.com/lmignon | ||
| :alt: lmignon | ||
|
|
||
| Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
|
||
| |maintainer-lmignon| | ||
|
|
||
| This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/14.0/extendable>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2022 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) | ||
|
|
||
| { | ||
| "name": "Extendable", | ||
| "summary": """ | ||
| Extendable classes registry loader for Odoo""", | ||
| "version": "14.0.1.0.0", | ||
| "development_status": "Beta", | ||
| "maintainers": ["lmignon"], | ||
| "license": "LGPL-3", | ||
| "author": "ACSONE SA/NV, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/rest-framework", | ||
| "depends": [], | ||
| "external_dependencies": {"python": ["extendable"]}, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import extendable_registry_loader | ||
| from . import ir_http |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Copyright 2022 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) | ||
|
|
||
| """ | ||
|
|
||
| Extendale classes Loader | ||
| ======================== | ||
|
|
||
| Load the extendable classes at the build of a registry. | ||
|
|
||
| """ | ||
| from typing import List, Optional | ||
|
|
||
| import odoo | ||
| from odoo import api, models | ||
|
|
||
| from extendable.registry import ExtendableClassesRegistry | ||
|
|
||
| from ..registry import _extendable_registries_database | ||
|
|
||
|
|
||
| class ExtendableRegistryLoader(models.AbstractModel): | ||
| _name = "extendable.registry.loader" | ||
| _description = "Extendable Registry Loader" | ||
|
|
||
| def _register_hook(self): | ||
| # This method is called by Odoo when the registry is built, | ||
| # so in case the registry is rebuilt (cache invalidation, ...), | ||
| # we have to to rebuild the extendable classes. We use a new | ||
| # registry so we have an empty cache and we'll add extendable classes | ||
| # in it. | ||
| registry = self._init_global_registry() | ||
| self.build_registry(registry) | ||
|
|
||
| @api.model | ||
| def _init_global_registry(self): | ||
| registry = ExtendableClassesRegistry() | ||
| _extendable_registries_database[self.env.cr.dbname] = registry | ||
| return registry | ||
|
|
||
| @api.model | ||
| def build_registry( | ||
| self, | ||
| registry: ExtendableClassesRegistry, | ||
| states: Optional[List[str]] = None, | ||
| exclude_addons: Optional[List[str]] = None, | ||
| ): | ||
| if not states: | ||
| states = ("installed", "to upgrade") | ||
| # lookup all the installed (or about to be) addons and generate | ||
| # the graph, so we can load the components following the order | ||
| # of the addons' dependencies | ||
| graph = odoo.modules.graph.Graph() | ||
| graph.add_module(self.env.cr, "base") | ||
|
|
||
| query = "SELECT name " "FROM ir_module_module " "WHERE state IN %s " | ||
| params = [tuple(states)] | ||
| if exclude_addons: | ||
| query += " AND name NOT IN %s " | ||
| params.append(tuple(exclude_addons)) | ||
| self.env.cr.execute(query, params) | ||
|
|
||
| module_list = [name for (name,) in self.env.cr.fetchall() if name not in graph] | ||
| graph.add_modules(self.env.cr, module_list) | ||
| module_matchings = [] | ||
| for m in graph: | ||
| module_matchings.append(f"odoo.addons.{m.name}.*") | ||
| registry.init_registry(module_matchings) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Copyright 2022 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) | ||
|
|
||
| from contextlib import contextmanager | ||
|
|
||
| from odoo import models | ||
| from odoo.http import request | ||
|
|
||
| from extendable import context | ||
|
|
||
| from ..registry import _extendable_registries_database | ||
|
|
||
|
|
||
| class IrHttp(models.AbstractModel): | ||
| _inherit = "ir.http" | ||
|
|
||
| @classmethod | ||
| def _dispatch(cls): | ||
| with cls._extendable_context_registry(): | ||
| return super()._dispatch() | ||
|
|
||
| @classmethod | ||
| @contextmanager | ||
| def _extendable_context_registry(cls): | ||
| registry = _extendable_registries_database.get(request.env.cr.dbname, {}) | ||
| token = context.extendable_registry.set(registry) | ||
| try: | ||
| yield | ||
| finally: | ||
| context.extendable_registry.reset(token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Laurent Mignon <laurent.mignon@acsone.eu> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This addon allows you to use the `Extendable library`_ within Odoo. | ||
|
|
||
| .. _Extendable library: : <https://pypi.org/project/extendable/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The `roadmap <https://github.com/OCA/odoo-addon-extendable/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement+label%3Aextendable>`_ | ||
| and `known issues <https://github.com/OCA/odoo-addon-extendable/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aextendable>`_ can | ||
| be found on GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| By default, all extendable classes defined into your odoo addons are automatically | ||
| loaded by the current addon according to the dependency graph computed by Odoo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright 2022 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) | ||
|
|
||
|
|
||
| class ExtendableRegistriesDatabase(dict): | ||
| """Holds an extendable classses registry for each database""" | ||
|
|
||
|
|
||
| _extendable_registries_database = ExtendableRegistriesDatabase() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.