Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions extendable/README.rst
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.
1 change: 1 addition & 0 deletions extendable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions extendable/__manifest__.py
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"]},
}
2 changes: 2 additions & 0 deletions extendable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import extendable_registry_loader
from . import ir_http
68 changes: 68 additions & 0 deletions extendable/models/extendable_registry_loader.py
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)
30 changes: 30 additions & 0 deletions extendable/models/ir_http.py
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)
1 change: 1 addition & 0 deletions extendable/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Laurent Mignon <laurent.mignon@acsone.eu>
3 changes: 3 additions & 0 deletions extendable/readme/DESCRIPTION.rst
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/>
3 changes: 3 additions & 0 deletions extendable/readme/ROADMAP.rst
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.
2 changes: 2 additions & 0 deletions extendable/readme/USAGE.rst
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.
9 changes: 9 additions & 0 deletions extendable/registry.py
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()
Loading