Skip to content

Commit 025d1bf

Browse files
committed
Merge PR #492 into 18.0
Signed-off-by simahawk
2 parents 622227e + b6751e1 commit 025d1bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5436
-0
lines changed

component/README.rst

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
==========
2+
Components
3+
==========
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:a17ffda475316eda129ff24559c5cd3822c3698fa06e1f22e4e64e400a446e2a
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Production/Stable
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector-lightgray.png?logo=github
20+
:target: https://github.com/OCA/connector/tree/18.0/component
21+
:alt: OCA/connector
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/connector-18-0/connector-18-0-component
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module implements a component system and is a base block for the
32+
Connector Framework. It can be used without using the full Connector
33+
though.
34+
35+
Documentation: http://odoo-connector.com/
36+
37+
You may also want to check the `Introduction to Odoo
38+
Components <https://dev.to/guewen/introduction-to-odoo-components-bn0>`__
39+
by @guewen.
40+
41+
**Table of contents**
42+
43+
.. contents::
44+
:local:
45+
46+
Usage
47+
=====
48+
49+
As a developer, you have access to a component system. You can find the
50+
documentation in the code or on http://odoo-connector.com
51+
52+
In a nutshell, you can create components:
53+
54+
::
55+
56+
from odoo.addons.component.core import Component
57+
58+
class MagentoPartnerAdapter(Component):
59+
_name = 'magento.partner.adapter'
60+
_inherit = 'magento.adapter'
61+
62+
_usage = 'backend.adapter'
63+
_collection = 'magento.backend'
64+
_apply_on = ['res.partner']
65+
66+
And later, find the component you need at runtime (dynamic dispatch at
67+
component level):
68+
69+
::
70+
71+
def run(self, external_id):
72+
backend_adapter = self.component(usage='backend.adapter')
73+
external_data = backend_adapter.read(external_id)
74+
75+
In order for tests using components to work, you will need to use the
76+
base class provided by \`odoo.addons.component.tests.common\`:
77+
78+
- TransactionComponentCase
79+
80+
There are also some specific base classes for testing the component
81+
registry, using the ComponentRegistryCase as a base class. See the
82+
docstrings in tests/common.py.
83+
84+
Changelog
85+
=========
86+
87+
16.0.1.0.0 (2022-10-04)
88+
-----------------------
89+
90+
- [MIGRATION] from 15.0
91+
92+
15.0.1.0.0 (2021-11-25)
93+
-----------------------
94+
95+
- [MIGRATION] from 14.0
96+
97+
14.0.1.0.0 (2020-10-22)
98+
-----------------------
99+
100+
- [MIGRATION] from 13.0
101+
102+
13.0.1.0.0 (2019-10-23)
103+
-----------------------
104+
105+
- [MIGRATION] from 12.0
106+
107+
12.0.1.0.0 (2018-10-02)
108+
-----------------------
109+
110+
- [MIGRATION] from 11.0 branched at rev. 324e006
111+
112+
Bug Tracker
113+
===========
114+
115+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector/issues>`_.
116+
In case of trouble, please check there if your issue has already been reported.
117+
If you spotted it first, help us to smash it by providing a detailed and welcomed
118+
`feedback <https://github.com/OCA/connector/issues/new?body=module:%20component%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
119+
120+
Do not contact contributors directly about support or help with technical issues.
121+
122+
Credits
123+
=======
124+
125+
Authors
126+
-------
127+
128+
* Camptocamp
129+
130+
Contributors
131+
------------
132+
133+
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
134+
- Laurent Mignon <laurent.mignon@acsone.eu>
135+
- Simone Orsi <simone.orsi@camptocamp.com>
136+
- Thien Vo <thienvh@trobz.com>
137+
138+
Other credits
139+
-------------
140+
141+
The migration of this module from 17.0 to 18.0 was financially supported
142+
by Camptocamp.
143+
144+
Maintainers
145+
-----------
146+
147+
This module is maintained by the OCA.
148+
149+
.. image:: https://odoo-community.org/logo.png
150+
:alt: Odoo Community Association
151+
:target: https://odoo-community.org
152+
153+
OCA, or the Odoo Community Association, is a nonprofit organization whose
154+
mission is to support the collaborative development of Odoo features and
155+
promote its widespread use.
156+
157+
.. |maintainer-guewen| image:: https://github.com/guewen.png?size=40px
158+
:target: https://github.com/guewen
159+
:alt: guewen
160+
161+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
162+
163+
|maintainer-guewen|
164+
165+
This module is part of the `OCA/connector <https://github.com/OCA/connector/tree/18.0/component>`_ project on GitHub.
166+
167+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

component/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import core
2+
3+
from . import components
4+
from . import builder
5+
from . import models

component/__manifest__.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2017 Camptocamp SA
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
{
5+
"name": "Components",
6+
"summary": "Add capabilities to register and use decoupled components,"
7+
" as an alternative to model classes",
8+
"version": "18.0.1.0.0",
9+
"author": "Camptocamp," "Odoo Community Association (OCA)",
10+
"website": "https://github.com/OCA/connector",
11+
"license": "LGPL-3",
12+
"category": "Generic Modules",
13+
"depends": ["base"],
14+
"external_dependencies": {
15+
"python": [
16+
"cachetools",
17+
]
18+
},
19+
"installable": True,
20+
"development_status": "Production/Stable",
21+
"maintainers": ["guewen"],
22+
}

component/builder.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2019 Camptocamp SA
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
"""
5+
6+
Components Builder
7+
==================
8+
9+
Build the components at the build of a registry.
10+
11+
"""
12+
13+
import odoo
14+
from odoo import models
15+
16+
from .core import DEFAULT_CACHE_SIZE, ComponentRegistry, _component_databases
17+
18+
19+
class ComponentBuilder(models.AbstractModel):
20+
"""Build the component classes
21+
22+
And register them in a global registry.
23+
24+
Every time an Odoo registry is built, the know components are cleared and
25+
rebuilt as well. The Component classes are built using the same mechanism
26+
than Odoo's Models: a final class is created, taking every Components with
27+
a ``_name`` and applying Components with an ``_inherits`` upon them.
28+
29+
The final Component classes are registered in global registry.
30+
31+
This class is an Odoo model, allowing us to hook the build of the
32+
components at the end of the Odoo's registry loading, using
33+
``_register_hook``. This method is called after all modules are loaded, so
34+
we are sure that we have all the components Classes and in the correct
35+
order.
36+
37+
"""
38+
39+
_name = "component.builder"
40+
_description = "Component Builder"
41+
42+
_components_registry_cache_size = DEFAULT_CACHE_SIZE
43+
44+
def _register_hook(self):
45+
# This method is called by Odoo when the registry is built,
46+
# so in case the registry is rebuilt (cache invalidation, ...),
47+
# we have to to rebuild the components. We use a new
48+
# registry so we have an empty cache and we'll add components in it.
49+
components_registry = self._init_global_registry()
50+
self.build_registry(components_registry)
51+
components_registry.ready = True
52+
53+
def _init_global_registry(self):
54+
components_registry = ComponentRegistry(
55+
cachesize=self._components_registry_cache_size
56+
)
57+
_component_databases[self.env.cr.dbname] = components_registry
58+
return components_registry
59+
60+
def build_registry(self, components_registry, states=None, exclude_addons=None):
61+
if not states:
62+
states = ("installed", "to upgrade")
63+
# lookup all the installed (or about to be) addons and generate
64+
# the graph, so we can load the components following the order
65+
# of the addons' dependencies
66+
graph = odoo.modules.graph.Graph()
67+
graph.add_module(self.env.cr, "base")
68+
69+
query = "SELECT name " "FROM ir_module_module " "WHERE state IN %s "
70+
params = [tuple(states)]
71+
if exclude_addons:
72+
query += " AND name NOT IN %s "
73+
params.append(tuple(exclude_addons))
74+
self.env.cr.execute(query, params)
75+
76+
module_list = [name for (name,) in self.env.cr.fetchall() if name not in graph]
77+
graph.add_modules(self.env.cr, module_list)
78+
79+
for module in graph:
80+
self.load_components(module.name, components_registry=components_registry)
81+
82+
def load_components(self, module, components_registry=None):
83+
"""Build every component known by MetaComponent for an odoo module
84+
85+
The final component (composed by all the Component classes in this
86+
module) will be pushed into the registry.
87+
88+
:param module: the name of the addon for which we want to load
89+
the components
90+
:type module: str | unicode
91+
:param registry: the registry in which we want to put the Component
92+
:type registry: :py:class:`~.core.ComponentRegistry`
93+
"""
94+
components_registry = (
95+
components_registry or _component_databases[self.env.cr.dbname]
96+
)
97+
components_registry.load_components(module)

component/components/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import base

component/components/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2017 Camptocamp SA
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
4+
from ..core import AbstractComponent
5+
6+
7+
class BaseComponent(AbstractComponent):
8+
"""This is the base component for every component
9+
10+
It is implicitely inherited by all components.
11+
12+
All your base are belong to us
13+
"""
14+
15+
_name = "base"

0 commit comments

Comments
 (0)