Odooly 3.0.2__tar.gz → 3.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {odooly-3.0.2 → odooly-3.0.4}/CHANGES.rst +21 -0
- odooly-3.0.4/LICENSE +28 -0
- {odooly-3.0.2 → odooly-3.0.4/Odooly.egg-info}/PKG-INFO +1 -1
- {odooly-3.0.2/Odooly.egg-info → odooly-3.0.4}/PKG-INFO +1 -1
- {odooly-3.0.2 → odooly-3.0.4}/docs/api.rst +2 -2
- {odooly-3.0.2 → odooly-3.0.4}/docs/index.rst +1 -1
- {odooly-3.0.2 → odooly-3.0.4}/docs/tutorial.rst +4 -4
- {odooly-3.0.2 → odooly-3.0.4}/odooly/__init__.py +1 -1
- {odooly-3.0.2 → odooly-3.0.4}/odooly/__main__.py +1 -1
- {odooly-3.0.2 → odooly-3.0.4}/odooly/colorize.py +2 -2
- {odooly-3.0.2 → odooly-3.0.4}/odooly/environment.py +12 -4
- {odooly-3.0.2 → odooly-3.0.4}/odooly/helpers.py +0 -14
- {odooly-3.0.2 → odooly-3.0.4}/odooly/http.py +1 -1
- {odooly-3.0.2 → odooly-3.0.4}/odooly/models.py +7 -3
- {odooly-3.0.2 → odooly-3.0.4}/odooly/run.py +68 -51
- {odooly-3.0.2 → odooly-3.0.4}/odooly/service.py +26 -2
- {odooly-3.0.2 → odooly-3.0.4}/tests/test_client.py +16 -6
- {odooly-3.0.2 → odooly-3.0.4}/tests/test_model.py +5 -2
- odooly-3.0.2/LICENSE +0 -28
- {odooly-3.0.2 → odooly-3.0.4}/Odooly.egg-info/SOURCES.txt +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/Odooly.egg-info/dependency_links.txt +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/Odooly.egg-info/entry_points.txt +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/Odooly.egg-info/requires.txt +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/Odooly.egg-info/top_level.txt +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/README.rst +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/docs/Makefile +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/docs/conf.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/docs/developer.rst +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/docs/intro.rst +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/odooly/_demo.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/odooly/client.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/odooly/exceptions.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/odooly/printer.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/odooly.ini +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/pyproject.toml +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/setup.cfg +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/tests/__init__.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/tests/_common.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/tests/test_interact.py +0 -0
- {odooly-3.0.2 → odooly-3.0.4}/tests/test_util.py +0 -0
|
@@ -2,6 +2,27 @@ Changelog
|
|
|
2
2
|
---------
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
3.0.4 (2026-11-15)
|
|
6
|
+
~~~~~~~~~~~~~~~~~~
|
|
7
|
+
|
|
8
|
+
* Rename method ``Model.access`` to :meth:`Model.has_access` to align with
|
|
9
|
+
new method of Odoo 18. For Odoo >= 18, method is also available on
|
|
10
|
+
:class:`Record` and :class:`RecordList`.
|
|
11
|
+
|
|
12
|
+
* Add ``Record/RecordList`` method ``has_access`` to the known base methods.
|
|
13
|
+
|
|
14
|
+
* When ``--demo`` or ``--test`` is used, it takes precedence
|
|
15
|
+
over local configuration, if two environments have the same name.
|
|
16
|
+
|
|
17
|
+
* Catch and print early error on connection.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
3.0.3 (2026-11-13)
|
|
21
|
+
~~~~~~~~~~~~~~~~~~
|
|
22
|
+
|
|
23
|
+
* Fix: read configured environments in ``odooly.ini``
|
|
24
|
+
|
|
25
|
+
|
|
5
26
|
3.0.2 (2026-11-13)
|
|
6
27
|
~~~~~~~~~~~~~~~~~~
|
|
7
28
|
|
odooly-3.0.4/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright © 2019 Florent Xicluna
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -141,7 +141,7 @@ Env
|
|
|
141
141
|
~~~
|
|
142
142
|
|
|
143
143
|
.. autoclass:: Env
|
|
144
|
-
:members: lang,
|
|
144
|
+
:members: lang, has_access, models, ref, __getitem__, odoo_env, registry
|
|
145
145
|
:undoc-members:
|
|
146
146
|
|
|
147
147
|
.. attribute:: db_name
|
|
@@ -262,7 +262,7 @@ Example: ``client.env['res.company']`` returns a :class:`Model`.
|
|
|
262
262
|
|
|
263
263
|
.. automethod:: field
|
|
264
264
|
|
|
265
|
-
.. automethod::
|
|
265
|
+
.. automethod:: has_access
|
|
266
266
|
|
|
267
267
|
.. automethod:: search(domain, offset=0, limit=None, order=None)
|
|
268
268
|
|
|
@@ -29,7 +29,7 @@ Authentication methods per Odoo version, and per API:
|
|
|
29
29
|
============= ============== ========= ========== ============ ============
|
|
30
30
|
Odoo \\ API Webclient Public JSON-2 *JSON-RPC* *XML-RPC*
|
|
31
31
|
============= ============== ========= ========== ============ ============
|
|
32
|
-
22.0 + | Login 2FA API Key
|
|
32
|
+
22.0 + | Login 2FA API Key
|
|
33
33
|
| *or* Login no-auth
|
|
34
34
|
------------- -------------- --------- ---------- -------------------------
|
|
35
35
|
19.0 to 21.0 | Login 2FA API Key | API Key *(deprecated)*
|
|
@@ -307,25 +307,25 @@ Among these 140 objects, some of them are ``read-only``, others are
|
|
|
307
307
|
.. sourcecode:: pycon
|
|
308
308
|
|
|
309
309
|
>>> # Read-only models
|
|
310
|
-
>>> len([m for m in all_models if not env[m].
|
|
310
|
+
>>> len([m for m in all_models if not env[m].has_access('write')])
|
|
311
311
|
116
|
|
312
312
|
>>> #
|
|
313
313
|
>>> # Writable but cannot delete
|
|
314
|
-
>>> [m for m in all_models if env[m].
|
|
314
|
+
>>> [m for m in all_models if env[m].has_access('write') and not env[m].has_access('unlink')]
|
|
315
315
|
['base.language.export',
|
|
316
316
|
'base.partner.merge.automatic.wizard',
|
|
317
317
|
'base_import.import',
|
|
318
318
|
'res.users.identitycheck']
|
|
319
319
|
>>> #
|
|
320
320
|
>>> # Unreadable models
|
|
321
|
-
>>> len([m for m in all_models if not env[m].
|
|
321
|
+
>>> len([m for m in all_models if not env[m].has_access('read')])
|
|
322
322
|
94
|
|
323
323
|
>>> #
|
|
324
324
|
>>> # Now print the number of entries in all (readable) models
|
|
325
325
|
>>> for m in all_models:
|
|
326
326
|
... if m == 'res.users.apikeys.show':
|
|
327
327
|
... continue # This one returns an error
|
|
328
|
-
... mcount = env[m].
|
|
328
|
+
... mcount = env[m].has_access('read') and env[m].search_count()
|
|
329
329
|
... if not mcount:
|
|
330
330
|
... continue
|
|
331
331
|
... print('%4d %s' % (mcount, m))
|
|
@@ -2,7 +2,7 @@ import os.path
|
|
|
2
2
|
import sys
|
|
3
3
|
|
|
4
4
|
# Support running without installing, from wheel file:
|
|
5
|
-
# python odooly-
|
|
5
|
+
# python odooly-3.0.4-py3-none-any.whl/odooly --help
|
|
6
6
|
|
|
7
7
|
_dir = os.path.dirname(__file__)
|
|
8
8
|
_wheel_dir = os.path.dirname(_dir)
|
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
import re
|
|
5
5
|
|
|
6
6
|
__all__ = ["color_bold", "color_comment", "color_json", "color_python", "color_repr",
|
|
7
|
-
"decolor", "
|
|
7
|
+
"decolor", "setup_colors", "THEME"]
|
|
8
8
|
|
|
9
9
|
KEYWORDS = {*keyword.kwlist}
|
|
10
10
|
J_SPECIAL = {'false', 'null', 'true'}
|
|
@@ -155,7 +155,7 @@ def _init_colors():
|
|
|
155
155
|
return result
|
|
156
156
|
|
|
157
157
|
|
|
158
|
-
def
|
|
158
|
+
def setup_colors(global_vars):
|
|
159
159
|
"""Set functions to color output."""
|
|
160
160
|
global THEME, _bold, _comment, _python
|
|
161
161
|
|
|
@@ -7,12 +7,13 @@ from . import __version__
|
|
|
7
7
|
from .colorize import color_bold
|
|
8
8
|
from .exceptions import Error, ServerError
|
|
9
9
|
from .helpers import issearchdomain, literal_eval, memoize, partial, searchargs
|
|
10
|
-
from .service import Json2
|
|
10
|
+
from .service import Json2, get_base_method_params
|
|
11
11
|
from .models import Model, Record
|
|
12
12
|
|
|
13
13
|
__all__ = ["Env", "ADMIN_USER", "SYSTEM_USER"]
|
|
14
14
|
|
|
15
15
|
ADMIN_USER = 'admin'
|
|
16
|
+
DEMO_USER = 'demo'
|
|
16
17
|
SYSTEM_USER = '__system__'
|
|
17
18
|
|
|
18
19
|
_pending_state = ('state', 'not in',
|
|
@@ -151,6 +152,7 @@ class Env:
|
|
|
151
152
|
self._doc('res.device')
|
|
152
153
|
except ServerError:
|
|
153
154
|
self._doc = None
|
|
155
|
+
self._base_method_params = get_base_method_params(self.client)
|
|
154
156
|
prev_protocol = getattr(getattr(self, '_execute_kw', 0), '_protocol_name', ...)
|
|
155
157
|
if self.client._object: # RPC endpoint if available
|
|
156
158
|
self._execute_kw = env_auth(self.client._object.execute_kw)
|
|
@@ -360,7 +362,7 @@ class Env:
|
|
|
360
362
|
res = [resdic.get(id_, False) for id_ in order_ids]
|
|
361
363
|
return (res or [None])[0] if single_id else res
|
|
362
364
|
|
|
363
|
-
def
|
|
365
|
+
def has_access(self, model_name, mode="read"):
|
|
364
366
|
"""Check if the user has access to this model.
|
|
365
367
|
|
|
366
368
|
Optional argument `mode` is the access mode to check. Valid values
|
|
@@ -368,11 +370,17 @@ class Env:
|
|
|
368
370
|
the ``read`` mode is checked. Return a boolean.
|
|
369
371
|
"""
|
|
370
372
|
try:
|
|
371
|
-
self.
|
|
372
|
-
|
|
373
|
+
if self.client.version_info < 18.0:
|
|
374
|
+
self.execute('ir.model.access', 'check', model_name, mode)
|
|
375
|
+
return True
|
|
376
|
+
return self.execute(model_name, 'has_access', [], mode)
|
|
373
377
|
except Exception:
|
|
374
378
|
return False
|
|
375
379
|
|
|
380
|
+
def access(self, model_name, mode="read"):
|
|
381
|
+
# Deprecated
|
|
382
|
+
raise Error("Method was renamed 'has_access' to align with Odoo >= 18.0")
|
|
383
|
+
|
|
376
384
|
def _models_get(self, name, check, transient):
|
|
377
385
|
if name not in self._model_names:
|
|
378
386
|
if check:
|
|
@@ -18,20 +18,6 @@ _term_re = re.compile(
|
|
|
18
18
|
r'(?![?!=<>])\s*(.+)')
|
|
19
19
|
_cause_message = ("\nThe above exception was the direct cause "
|
|
20
20
|
"of the following exception:\n\n")
|
|
21
|
-
base_method_params = [
|
|
22
|
-
('action_archive', ['ids']),
|
|
23
|
-
('action_unarchive', ['ids']),
|
|
24
|
-
('copy', ['ids', 'default']),
|
|
25
|
-
('create', ['vals_list']),
|
|
26
|
-
('get_external_id', ['ids']),
|
|
27
|
-
('get_metadata', ['ids']),
|
|
28
|
-
('read', ['ids', 'fields', 'load']),
|
|
29
|
-
('search', ['domain', 'offset', 'limit', 'order']),
|
|
30
|
-
('search_count', ['domain', 'limit']),
|
|
31
|
-
('search_read', ['domain', 'fields', 'offset', 'limit', 'order']),
|
|
32
|
-
('unlink', ['ids']),
|
|
33
|
-
('write', ['ids', 'vals']),
|
|
34
|
-
]
|
|
35
21
|
|
|
36
22
|
|
|
37
23
|
def memoize(inst, attr, value, doc_values=None):
|
|
@@ -84,7 +84,7 @@ class HTTPSession:
|
|
|
84
84
|
if result and status_code in {401, 403, 404, 422, 500}:
|
|
85
85
|
# Unauthorized, Forbidden, NotFound, UnprocessableContent, InternalServerError
|
|
86
86
|
if isinstance(result, str):
|
|
87
|
-
lines = re.findall(r'>([
|
|
87
|
+
lines = re.findall(r'>([^\n]+)<', result) or (status_code, result)
|
|
88
88
|
result = {'name': exc.__class__.__name__, 'debug': None,
|
|
89
89
|
'arguments': (f'{lines[0]} - {lines[-1]}',)}
|
|
90
90
|
raise ServerError({'code': status_code, 'data': result})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import re
|
|
2
2
|
from string import Formatter
|
|
3
3
|
|
|
4
|
-
from .helpers import
|
|
4
|
+
from .helpers import issearchdomain, memoize, partial, searchargs
|
|
5
5
|
|
|
6
6
|
__all__ = ["BaseModel", "BaseRecord", "Id1", "Ids", "Model", "Record", "RecordList"]
|
|
7
7
|
|
|
@@ -109,16 +109,20 @@ class Model(BaseModel):
|
|
|
109
109
|
try:
|
|
110
110
|
method_params = self._parse_doc_methods(self._doc)
|
|
111
111
|
except Exception:
|
|
112
|
-
method_params =
|
|
112
|
+
method_params = self.env._base_method_params
|
|
113
113
|
return {key: args for (key, args) in method_params if name in key}
|
|
114
114
|
|
|
115
|
-
def
|
|
115
|
+
def has_access(self, mode="read"):
|
|
116
116
|
"""Check if the user has access to this model.
|
|
117
117
|
|
|
118
118
|
Optional argument `mode` is the access mode to check. Valid values
|
|
119
119
|
are ``read``, ``write``, ``create`` and ``unlink``. If omitted,
|
|
120
120
|
the ``read`` mode is checked. Return a boolean.
|
|
121
121
|
"""
|
|
122
|
+
return self.env.has_access(self._name, mode)
|
|
123
|
+
|
|
124
|
+
def access(self, mode="read"):
|
|
125
|
+
# Deprecated, raise Error: Method was renamed 'has_access'
|
|
122
126
|
return self.env.access(self._name, mode)
|
|
123
127
|
|
|
124
128
|
def browse(self, ids=()):
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import atexit
|
|
3
|
+
import builtins
|
|
3
4
|
import os
|
|
4
5
|
import shlex
|
|
5
6
|
import signal
|
|
6
7
|
import sys
|
|
7
8
|
from configparser import ConfigParser
|
|
9
|
+
from contextlib import contextmanager
|
|
8
10
|
from pathlib import Path
|
|
9
11
|
|
|
10
12
|
from . import __doc__, __version__
|
|
11
13
|
from .client import Client
|
|
12
|
-
from .environment import ADMIN_USER, Env
|
|
14
|
+
from .environment import ADMIN_USER, DEMO_USER, Env
|
|
13
15
|
from .helpers import format_exception
|
|
14
|
-
from .colorize import color_bold, color_repr,
|
|
16
|
+
from .colorize import color_bold, color_repr, setup_colors
|
|
15
17
|
from .exceptions import Error
|
|
16
18
|
from .printer import Printer, convert_to_width, pp, set_output_width
|
|
17
19
|
|
|
@@ -24,23 +26,20 @@ Usage (some commands):
|
|
|
24
26
|
env[name].keys() # List field names of the model
|
|
25
27
|
env[name].fields(names=None) # Return details for the fields
|
|
26
28
|
env[name].field(name) # Return details for the field
|
|
27
|
-
env[name].browse(
|
|
28
|
-
env[name].search(domain)
|
|
29
|
+
env[name].browse([id1, id2])
|
|
30
|
+
env[name].search(domain) # Return a RecordList
|
|
29
31
|
env[name].search(domain, offset=0, limit=None, order=None)
|
|
30
|
-
# Return a RecordList
|
|
31
|
-
|
|
32
32
|
rec = env[name].get(domain) # Get the Record matching domain
|
|
33
33
|
rec.some_field # Return the value of this field
|
|
34
|
-
rec.read(
|
|
34
|
+
rec.read("{field1} - {field2}") # Format values for the fields
|
|
35
35
|
|
|
36
36
|
client.login(user) # Login with another user
|
|
37
37
|
client.connect(env_name) # Connect to another env.
|
|
38
38
|
client.connect(server=None) # Connect to another server
|
|
39
39
|
env.models(name) # List models matching pattern
|
|
40
40
|
env.modules(name) # List modules matching pattern
|
|
41
|
-
env.install(module1,
|
|
41
|
+
env.install(module1, ...) # Install or upgrade the modules
|
|
42
42
|
env.upgrade(module1, module2, ...)
|
|
43
|
-
# Install or upgrade the modules
|
|
44
43
|
env.upgrade_cancel() # Reset failed upgrade/install
|
|
45
44
|
"""
|
|
46
45
|
|
|
@@ -86,17 +85,18 @@ class InteractiveClient(Client):
|
|
|
86
85
|
See :meth:`InteractiveClient.read_config` for details of the configuration file format.
|
|
87
86
|
"""
|
|
88
87
|
assert environment
|
|
89
|
-
saved_config = {**cls.
|
|
90
|
-
if environment
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
saved_config = {**cls._saved_config, **cls._saved_config_demo}
|
|
89
|
+
if environment in saved_config:
|
|
90
|
+
return saved_config[environment]
|
|
91
|
+
try:
|
|
92
|
+
cls._saved_config[environment] = cls.read_config(environment)
|
|
93
|
+
except Exception:
|
|
94
|
+
envs = [env for env in cls.read_config() if env not in saved_config]
|
|
95
|
+
err_msg = "No such environment.\nAvailable: " + " ".join(envs)
|
|
96
|
+
if saved_config:
|
|
97
|
+
err_msg += "\n " + " ".join(saved_config)
|
|
98
|
+
raise Error(err_msg)
|
|
99
|
+
return cls._saved_config[environment]
|
|
100
100
|
|
|
101
101
|
@classmethod
|
|
102
102
|
def from_config(cls, environment, *, user=None, database=None, verbose=False):
|
|
@@ -176,7 +176,7 @@ class InteractiveClient(Client):
|
|
|
176
176
|
return super().login(user, password=password, database=database, api_key=api_key)
|
|
177
177
|
try:
|
|
178
178
|
register = super().login(user, password=password, database=database, api_key=api_key)
|
|
179
|
-
except Error as exc:
|
|
179
|
+
except (Error, EOFError, KeyboardInterrupt) as exc:
|
|
180
180
|
print(exc)
|
|
181
181
|
register = 'client' not in self._globals
|
|
182
182
|
# Register the globals()
|
|
@@ -211,9 +211,17 @@ class InteractiveClient(Client):
|
|
|
211
211
|
return cls._globals is not None
|
|
212
212
|
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
@contextmanager
|
|
215
|
+
def except_handler(error_class=Exception):
|
|
216
|
+
try:
|
|
217
|
+
yield
|
|
218
|
+
except error_class as exc:
|
|
219
|
+
msg = ''.join(format_exception(exc.__class__, exc, None, chain=False))
|
|
220
|
+
print(color_bold(color_repr(msg.rstrip())))
|
|
221
|
+
raise sys.exit(1)
|
|
216
222
|
|
|
223
|
+
|
|
224
|
+
def _interact(global_vars, use_pprint=True, usage=USAGE):
|
|
217
225
|
if use_pyrepl := not os.getenv("PYTHON_BASIC_REPL"):
|
|
218
226
|
try:
|
|
219
227
|
from _pyrepl.main import CAN_USE_PYREPL as use_pyrepl
|
|
@@ -246,6 +254,33 @@ def _interact(global_vars, use_pprint=True, usage=USAGE):
|
|
|
246
254
|
except Exception:
|
|
247
255
|
pass # No history in case of error
|
|
248
256
|
|
|
257
|
+
builtins.usage = type('Usage', (), {'__call__': lambda s: print(usage),
|
|
258
|
+
'__repr__': lambda s: usage})()
|
|
259
|
+
|
|
260
|
+
console = Console(global_vars, filename="<stdin>")
|
|
261
|
+
setup_displayhook(use_pprint=use_pprint, colorize=use_pyrepl and console.can_colorize)
|
|
262
|
+
run(console) if use_pyrepl else console.interact('', '')
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def handle_resize(signum, frame):
|
|
266
|
+
term = os.get_terminal_size()
|
|
267
|
+
if not term.columns:
|
|
268
|
+
return
|
|
269
|
+
client = InteractiveClient._globals.get('client')
|
|
270
|
+
if client and client.verbose:
|
|
271
|
+
client.verbose = term.columns
|
|
272
|
+
set_output_width(term.columns)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def setup_signal_handler():
|
|
276
|
+
assert InteractiveClient._is_interactive()
|
|
277
|
+
signal.signal(signal.SIGWINCH, handle_resize)
|
|
278
|
+
signal.raise_signal(signal.SIGWINCH)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def setup_displayhook(use_pprint=True, colorize=True):
|
|
282
|
+
exfmt = {"colorize": True} if colorize else {}
|
|
283
|
+
|
|
249
284
|
if use_pprint:
|
|
250
285
|
def displayhook(value, _printer=pp, _builtins=builtins):
|
|
251
286
|
# Pretty-format the output
|
|
@@ -260,13 +295,6 @@ def _interact(global_vars, use_pprint=True, usage=USAGE):
|
|
|
260
295
|
print(color_repr(msg.rstrip()))
|
|
261
296
|
sys.excepthook = excepthook
|
|
262
297
|
|
|
263
|
-
builtins.usage = type('Usage', (), {'__call__': lambda s: print(usage),
|
|
264
|
-
'__repr__': lambda s: usage})()
|
|
265
|
-
|
|
266
|
-
console = Console(global_vars, filename="<stdin>")
|
|
267
|
-
exfmt = {"colorize": console.can_colorize} if use_pyrepl else {}
|
|
268
|
-
run(console) if use_pyrepl else console.interact('', '')
|
|
269
|
-
|
|
270
298
|
|
|
271
299
|
def get_parser():
|
|
272
300
|
parser = argparse.ArgumentParser(description='Interact with Odoo')
|
|
@@ -282,7 +310,7 @@ def get_parser():
|
|
|
282
310
|
help=f'specify alternate config file (default: {CONF_FILE})')
|
|
283
311
|
parser.add_argument(
|
|
284
312
|
'--server', default=None,
|
|
285
|
-
help=
|
|
313
|
+
help='full URL of the server')
|
|
286
314
|
parser.add_argument('-d', '--db', default=None, help='database')
|
|
287
315
|
parser.add_argument('-u', '--user', default=None, help='username')
|
|
288
316
|
parser.add_argument(
|
|
@@ -306,13 +334,16 @@ def get_parser():
|
|
|
306
334
|
|
|
307
335
|
|
|
308
336
|
def connect_client(args):
|
|
337
|
+
# Argument 'args' is argparse Namespace with mandatory attributes:
|
|
338
|
+
# args, env, config, server, db, user, password, api_key, demo, verbose
|
|
309
339
|
if (env_name := args.demo or args.env):
|
|
310
340
|
kwargs = {
|
|
311
341
|
"user": args.user,
|
|
312
342
|
"database": args.db,
|
|
313
343
|
"verbose": args.verbose,
|
|
314
344
|
}
|
|
315
|
-
|
|
345
|
+
with except_handler():
|
|
346
|
+
client = InteractiveClient.from_config(env_name, **kwargs)
|
|
316
347
|
else:
|
|
317
348
|
if args.server:
|
|
318
349
|
server = args.server
|
|
@@ -327,25 +358,11 @@ def connect_client(args):
|
|
|
327
358
|
"api_key": args.api_key,
|
|
328
359
|
"verbose": args.verbose,
|
|
329
360
|
}
|
|
330
|
-
|
|
361
|
+
with except_handler():
|
|
362
|
+
client = InteractiveClient(server, args.db, args.user or ADMIN_USER, **kwargs)
|
|
331
363
|
return client
|
|
332
364
|
|
|
333
365
|
|
|
334
|
-
def handle_resize(signum, frame):
|
|
335
|
-
term = os.get_terminal_size()
|
|
336
|
-
if not InteractiveClient._is_interactive() or not term.columns:
|
|
337
|
-
return
|
|
338
|
-
client = InteractiveClient._globals.get('client')
|
|
339
|
-
if client and client.verbose:
|
|
340
|
-
client.verbose = term.columns
|
|
341
|
-
set_output_width(term.columns)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
def install_signal_handler():
|
|
345
|
-
signal.signal(signal.SIGWINCH, handle_resize)
|
|
346
|
-
signal.raise_signal(signal.SIGWINCH)
|
|
347
|
-
|
|
348
|
-
|
|
349
366
|
def main(interact=_interact):
|
|
350
367
|
"""Configure client, and decide if interactive.
|
|
351
368
|
|
|
@@ -360,7 +377,7 @@ def main(interact=_interact):
|
|
|
360
377
|
if args.demo:
|
|
361
378
|
from ._demo import _retrieve_servers
|
|
362
379
|
|
|
363
|
-
client_class._saved_config_demo = _retrieve_servers(user=args.user or
|
|
380
|
+
client_class._saved_config_demo = _retrieve_servers(user=args.user or DEMO_USER)
|
|
364
381
|
if args.list_env:
|
|
365
382
|
print('Available settings: ' + ' '.join(client_class.read_config()))
|
|
366
383
|
if args.demo:
|
|
@@ -385,7 +402,7 @@ def main(interact=_interact):
|
|
|
385
402
|
if not interact:
|
|
386
403
|
return connect_client(args)._globals
|
|
387
404
|
usage = os.getenv('ODOOLY_USAGE', USAGE)
|
|
388
|
-
|
|
389
|
-
|
|
405
|
+
setup_colors(client_class._globals)
|
|
406
|
+
setup_signal_handler()
|
|
390
407
|
print(color_repr(usage))
|
|
391
408
|
return interact(connect_client(args)._globals, usage=usage)
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
from urllib.parse import urljoin
|
|
4
4
|
|
|
5
5
|
from .exceptions import ServerError
|
|
6
|
-
from .helpers import
|
|
6
|
+
from .helpers import format_params, memoize
|
|
7
7
|
from .http import HTTPSession
|
|
8
8
|
from .models import Id1, Ids, Model
|
|
9
9
|
|
|
@@ -23,6 +23,29 @@ _rpc_methods = {
|
|
|
23
23
|
'common': ['login', 'authenticate', 'version'],
|
|
24
24
|
'object': ['execute', 'execute_kw'],
|
|
25
25
|
}
|
|
26
|
+
# Base model
|
|
27
|
+
_model_methods = [
|
|
28
|
+
('action_archive', ['ids']),
|
|
29
|
+
('action_unarchive', ['ids']),
|
|
30
|
+
('copy', ['ids', 'default']),
|
|
31
|
+
('create', ['vals_list']),
|
|
32
|
+
('get_external_id', ['ids']),
|
|
33
|
+
('get_metadata', ['ids']),
|
|
34
|
+
('has_access', ['ids', 'operation']),
|
|
35
|
+
('read', ['ids', 'fields', 'load']),
|
|
36
|
+
('search', ['domain', 'offset', 'limit', 'order']),
|
|
37
|
+
('search_count', ['domain', 'limit']),
|
|
38
|
+
('search_read', ['domain', 'fields', 'offset', 'limit', 'order']),
|
|
39
|
+
('unlink', ['ids']),
|
|
40
|
+
('write', ['ids', 'vals']),
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_base_method_params(client):
|
|
45
|
+
method_params = [*_model_methods]
|
|
46
|
+
if client.version_info < 18.0:
|
|
47
|
+
assert method_params.pop(6)[0] == 'has_access'
|
|
48
|
+
return method_params
|
|
26
49
|
|
|
27
50
|
|
|
28
51
|
def start_odoo_services(options=None, appname=None):
|
|
@@ -164,6 +187,7 @@ class Json2:
|
|
|
164
187
|
'X-Odoo-Database': database or '',
|
|
165
188
|
}
|
|
166
189
|
self._printer = client._printer
|
|
190
|
+
self._base_method_params = dict(get_base_method_params(client))
|
|
167
191
|
self.reset()
|
|
168
192
|
|
|
169
193
|
def doc(self, model):
|
|
@@ -175,7 +199,7 @@ class Json2:
|
|
|
175
199
|
return model_doc
|
|
176
200
|
|
|
177
201
|
def reset(self):
|
|
178
|
-
self._method_params = {'base':
|
|
202
|
+
self._method_params = {'base': self._base_method_params}
|
|
179
203
|
|
|
180
204
|
def _methods(self, model):
|
|
181
205
|
if model not in self._method_params:
|
|
@@ -465,8 +465,11 @@ class TestClientApi(JsonRpcTestCase):
|
|
|
465
465
|
self.assertOutput('')
|
|
466
466
|
|
|
467
467
|
def test_access(self):
|
|
468
|
-
self.assertTrue(self.env.
|
|
469
|
-
self.
|
|
468
|
+
self.assertTrue(self.env.has_access('foo.bar'))
|
|
469
|
+
if float(self.server_version) < 18.0:
|
|
470
|
+
self.assertCalls(OBJ('ir.model.access', 'check', 'foo.bar', 'read'))
|
|
471
|
+
else:
|
|
472
|
+
self.assertCalls(OBJ('foo.bar', 'has_access', [], 'read'))
|
|
470
473
|
self.assertOutput('')
|
|
471
474
|
|
|
472
475
|
def test_execute_kw(self):
|
|
@@ -574,8 +577,8 @@ class TestClientApi(JsonRpcTestCase):
|
|
|
574
577
|
|
|
575
578
|
self.service.object.execute_kw.side_effect = [ctx_lang, ctx_lang]
|
|
576
579
|
self.service.common.login.side_effect = [1]
|
|
577
|
-
self.assertTrue(env.sudo().
|
|
578
|
-
self.assertFalse(env.
|
|
580
|
+
self.assertTrue(env.sudo().has_access('res.users', 'write'))
|
|
581
|
+
self.assertFalse(env.has_access('res.users', 'write'))
|
|
579
582
|
|
|
580
583
|
expected_calls = [
|
|
581
584
|
call.common.login('database', 'guest', 'xxx'),
|
|
@@ -584,11 +587,18 @@ class TestClientApi(JsonRpcTestCase):
|
|
|
584
587
|
call.common.login('database', 'admin', 'ooo'),
|
|
585
588
|
('object.execute_kw', self.database, 1, 'ooo', 'res.users', 'context_get', ()),
|
|
586
589
|
call.doc._request('res.device'),
|
|
587
|
-
('object.execute_kw', self.database, 1, 'ooo', '
|
|
588
|
-
('object.execute_kw', self.database, 4, 'passwd', '
|
|
590
|
+
('object.execute_kw', self.database, 1, 'ooo', 'res.users', 'has_access', ([], 'write'), {'context': ctx_lang}),
|
|
591
|
+
('object.execute_kw', self.database, 4, 'passwd', 'res.users', 'has_access', ([], 'write'), {'context': ctx_lang}),
|
|
589
592
|
]
|
|
590
593
|
if float(self.server_version) < 19.0:
|
|
591
594
|
del expected_calls[4]
|
|
595
|
+
if float(self.server_version) < 18.0:
|
|
596
|
+
expected_calls[-2:] = [
|
|
597
|
+
('object.execute_kw', self.database, 1, 'ooo',
|
|
598
|
+
'ir.model.access', 'check', ('res.users', 'write'), {'context': ctx_lang}),
|
|
599
|
+
('object.execute_kw', self.database, 4, 'passwd',
|
|
600
|
+
'ir.model.access', 'check', ('res.users', 'write'), {'context': ctx_lang}),
|
|
601
|
+
]
|
|
592
602
|
self.assertCalls(*expected_calls)
|
|
593
603
|
self.assertEqual(getpass.mock_calls,
|
|
594
604
|
[call("Password for 'guest': "), call("Password for 'admin': ")])
|
|
@@ -164,8 +164,11 @@ class TestModel(TestCase):
|
|
|
164
164
|
self.assertOutput('')
|
|
165
165
|
|
|
166
166
|
def test_access(self):
|
|
167
|
-
self.assertTrue(self.env['foo.bar'].
|
|
168
|
-
self.
|
|
167
|
+
self.assertTrue(self.env['foo.bar'].has_access())
|
|
168
|
+
if float(self.server_version) < 18.0:
|
|
169
|
+
self.assertCalls(OBJ('ir.model.access', 'check', 'foo.bar', 'read'))
|
|
170
|
+
else:
|
|
171
|
+
self.assertCalls(OBJ('foo.bar', 'has_access', [], 'read'))
|
|
169
172
|
self.assertOutput('')
|
|
170
173
|
|
|
171
174
|
def test_search(self):
|
odooly-3.0.2/LICENSE
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
Copyright © 2019 Florent Xicluna
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
* Redistributions of source code must retain the above copyright
|
|
8
|
-
notice, this list of conditions and the following disclaimer.
|
|
9
|
-
|
|
10
|
-
* Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in the
|
|
12
|
-
documentation and/or other materials provided with the distribution.
|
|
13
|
-
|
|
14
|
-
* The names of the contributors may not be used to endorse or
|
|
15
|
-
promote products derived from this software without specific
|
|
16
|
-
prior written permission.
|
|
17
|
-
|
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNERS AND CONTRIBUTORS "AS IS"
|
|
19
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
-
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR CONTRIBUTORS BE
|
|
22
|
-
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
23
|
-
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
24
|
-
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
25
|
-
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
26
|
-
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
27
|
-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND DOCUMENTATION, EVEN
|
|
28
|
-
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|