odoo-xmlrpc-wrapper 1.0.1__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.
@@ -0,0 +1,16 @@
1
+ MIT License
2
+
3
+ Copyright 2023 Cagatay URESIN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
7
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.1
2
+ Name: odoo_xmlrpc_wrapper
3
+ Version: 1.0.1
4
+ Summary: A simple Python library to make CRUD process easier
5
+ Home-page: https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
6
+ Author: Cagatay URESIN
7
+ Author-email: Cagatay URESIN <cagatayuresin@gmail.com>
8
+ Maintainer-email: Cagatay URESIN <cagatayuresin@gmail.com>
9
+ License: MIT License
10
+
11
+ Copyright 2023 Cagatay URESIN
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
14
+ documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
15
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ persons to whom the Software is furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
19
+ Software.
20
+
21
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
22
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ Project-URL: Homepage, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
27
+ Project-URL: Bug Reports, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper/issues
28
+ Project-URL: Buy Me A Coffee, https://www.buymeacoffee.com/cagatayuresin
29
+ Project-URL: Source, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
30
+ Keywords: odoo,external,api,xmlrpc,rpc,wrapper
31
+ Classifier: Development Status :: 5 - Production/Stable
32
+ Classifier: Environment :: Console
33
+ Classifier: Framework :: Odoo
34
+ Classifier: Framework :: Odoo :: 16.0
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: System Administrators
37
+ Classifier: License :: Freeware
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Operating System :: OS Independent
40
+ Classifier: Programming Language :: Python :: 3 :: Only
41
+ Classifier: Programming Language :: Python :: 3.7
42
+ Classifier: Topic :: Office/Business
43
+ Classifier: Topic :: Software Development :: Libraries
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Requires-Python: >=3.7
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+
49
+ <a href="https://www.buymeacoffee.com/cagatayuresin" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
50
+ # Odoo XMLRPC Wrapper
51
+ ***
52
+ A small wrapper for oversimplifying CRUD operations and connecting to the Odoo External API
53
+ with the Python xmlrpc module.
54
+ ***
55
+ ## Index
56
+ * [Getting Started](#getting-started)
57
+ * [Installing via pip](#installing-via-pip)
58
+ * [A Simple Connection](#a-simple-connection)
59
+ * [CRUD Operations](#crud-operations)
60
+ * [Create](#create)
61
+ * [Read](#read)
62
+ * [Update](#update)
63
+ * [Delete](#delete)
64
+ * [Miscellaneous](#miscellaneous)
65
+ * [Search](#search)
66
+ * [Search and Read](#search-and-read)
67
+ * [Count](#count)
68
+ * [Get Fields](#get-fields)
69
+ * [A Little Detail](#a-little-detail)
70
+ * [Bot Instance](#bot-instance)
71
+ * [Active Model](#active-model)
72
+ * [Contribution](#contribution)
73
+ * [License](#license)
74
+ ***
75
+ ## Getting Started
76
+ ### Installing via pip
77
+ ```bash
78
+ pip install odoo-xmlrpc-wrapper
79
+ ```
80
+ ### A Simple Connection
81
+ ```python
82
+ from odoo_xmlrpc_wrapper import odoo_xmlrpc_wrapper as oxw
83
+
84
+
85
+ HOST = "odoo.myhost.com"
86
+ DB = "my_test_db"
87
+ USERLOGIN = "mymailtologin@odoo.com"
88
+ PASSWORD = "mypass"
89
+
90
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD)
91
+ ```
92
+ Prints:
93
+ ```commandline
94
+ Successfully Logged
95
+ Name: Mitchell Admin
96
+ DB: my_test_db
97
+ HOST: https://odoo.myhost.com
98
+ VERSION: saas~16.1
99
+ ```
100
+ ### CRUD Operations
101
+ Once the model to be processed in the CRUD functions is entered, the following other
102
+ You do not need to specify the model again as long as the model does not change to
103
+ the operation functions.
104
+ #### Create
105
+ ```python
106
+ bot.create("res.partner", {"name": "John Doe"})
107
+ ```
108
+ #### Read
109
+ ```python
110
+ bot.read(ids=[84], fields=["name"])
111
+ ```
112
+ Returns: `[{"id": 84, "name": "John Doe"}]`
113
+ #### Update
114
+ ```python
115
+ bot.update(the_id=84, the_obj={"name": "Jane Doe"})
116
+ ```
117
+ #### Delete
118
+ ```python
119
+ bot.delete(ids=[84])
120
+ ```
121
+ ### Miscellaneous
122
+ #### Search
123
+ ```python
124
+ bot.search(constraints=[("name", "=", "Mitchell Admin")])
125
+ ```
126
+ Returns:
127
+ `[2]`
128
+ #### Search and Read
129
+ ```python
130
+ bot.search_read(constraints=[("name", "=", "Mitchell Admin")])
131
+ ```
132
+ Returns: `[{'id': 2, 'name': 'Mitchell Admin'}]`
133
+ #### Count
134
+ ```python
135
+ bot.count()
136
+ ```
137
+ Returns: `78`
138
+ #### Get Fields
139
+ ```python
140
+ bot.get_fields("res.partner.title", attributes=["type"])
141
+ ```
142
+ Output:
143
+ ```commandline
144
+ {
145
+ "name": {"type": "char"},
146
+ "shortcut": {"type": "char"},
147
+ "id": {"type": "integer"},
148
+ "display_name": {"type": "char"},
149
+ "create_uid": {"type": "many2one"},
150
+ "create_date": {"type": "datetime"},
151
+ "write_uid": {"type": "many2one"},
152
+ "write_date": {"type": "datetime"},
153
+ }
154
+ ```
155
+ ## A Little Detail
156
+ ### Bot Instance
157
+ ```python
158
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD) # Simple Connection
159
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD, secured=False) # For http:// (no-ssl) (localhost)
160
+ bot = oxw.Bot(test=True) # For XMLRPC Tests from Odoo saas
161
+ ```
162
+ If you are going to connect to a host with an unencrypted http protocol such as localhost,
163
+ `secured=False` must be specified.
164
+
165
+ `test=True` allows you to connect to one of Odoo's own xmlrpc test servers. Odoo assigns
166
+ you a random host, database, user and password from the demo servers. You don't need other
167
+ attributes when test option is selected.
168
+ ### Active Model
169
+ The default model when a bot instance is initialized is `"res.users"`. So when you command
170
+ `bot.count()` it returns active users total as an integer.
171
+
172
+ You can assign the active model at any time with `bot.model = "model.name"` or when calling
173
+ any next method, such as `bot.count("res.partner")`
174
+
175
+ ## Contribution
176
+ Feel free to contribute. This project needs a fine exception handling.
177
+ ## License
178
+ [MIT License](https://en.wikipedia.org/wiki/MIT_License)
179
+
180
+ Copyright 2023 Cagatay URESIN
181
+
182
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
183
+ software and associated documentation files (the “Software”), to deal in the Software
184
+ without restriction, including without limitation the rights to use, copy, modify, merge,
185
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
186
+ to whom the Software is furnished to do so, subject to the following conditions:
187
+
188
+ The above copyright notice and this permission notice shall be included in all copies or
189
+ substantial portions of the Software.
190
+
191
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
192
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
193
+ PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
194
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
195
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
196
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,148 @@
1
+ <a href="https://www.buymeacoffee.com/cagatayuresin" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
2
+ # Odoo XMLRPC Wrapper
3
+ ***
4
+ A small wrapper for oversimplifying CRUD operations and connecting to the Odoo External API
5
+ with the Python xmlrpc module.
6
+ ***
7
+ ## Index
8
+ * [Getting Started](#getting-started)
9
+ * [Installing via pip](#installing-via-pip)
10
+ * [A Simple Connection](#a-simple-connection)
11
+ * [CRUD Operations](#crud-operations)
12
+ * [Create](#create)
13
+ * [Read](#read)
14
+ * [Update](#update)
15
+ * [Delete](#delete)
16
+ * [Miscellaneous](#miscellaneous)
17
+ * [Search](#search)
18
+ * [Search and Read](#search-and-read)
19
+ * [Count](#count)
20
+ * [Get Fields](#get-fields)
21
+ * [A Little Detail](#a-little-detail)
22
+ * [Bot Instance](#bot-instance)
23
+ * [Active Model](#active-model)
24
+ * [Contribution](#contribution)
25
+ * [License](#license)
26
+ ***
27
+ ## Getting Started
28
+ ### Installing via pip
29
+ ```bash
30
+ pip install odoo-xmlrpc-wrapper
31
+ ```
32
+ ### A Simple Connection
33
+ ```python
34
+ from odoo_xmlrpc_wrapper import odoo_xmlrpc_wrapper as oxw
35
+
36
+
37
+ HOST = "odoo.myhost.com"
38
+ DB = "my_test_db"
39
+ USERLOGIN = "mymailtologin@odoo.com"
40
+ PASSWORD = "mypass"
41
+
42
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD)
43
+ ```
44
+ Prints:
45
+ ```commandline
46
+ Successfully Logged
47
+ Name: Mitchell Admin
48
+ DB: my_test_db
49
+ HOST: https://odoo.myhost.com
50
+ VERSION: saas~16.1
51
+ ```
52
+ ### CRUD Operations
53
+ Once the model to be processed in the CRUD functions is entered, the following other
54
+ You do not need to specify the model again as long as the model does not change to
55
+ the operation functions.
56
+ #### Create
57
+ ```python
58
+ bot.create("res.partner", {"name": "John Doe"})
59
+ ```
60
+ #### Read
61
+ ```python
62
+ bot.read(ids=[84], fields=["name"])
63
+ ```
64
+ Returns: `[{"id": 84, "name": "John Doe"}]`
65
+ #### Update
66
+ ```python
67
+ bot.update(the_id=84, the_obj={"name": "Jane Doe"})
68
+ ```
69
+ #### Delete
70
+ ```python
71
+ bot.delete(ids=[84])
72
+ ```
73
+ ### Miscellaneous
74
+ #### Search
75
+ ```python
76
+ bot.search(constraints=[("name", "=", "Mitchell Admin")])
77
+ ```
78
+ Returns:
79
+ `[2]`
80
+ #### Search and Read
81
+ ```python
82
+ bot.search_read(constraints=[("name", "=", "Mitchell Admin")])
83
+ ```
84
+ Returns: `[{'id': 2, 'name': 'Mitchell Admin'}]`
85
+ #### Count
86
+ ```python
87
+ bot.count()
88
+ ```
89
+ Returns: `78`
90
+ #### Get Fields
91
+ ```python
92
+ bot.get_fields("res.partner.title", attributes=["type"])
93
+ ```
94
+ Output:
95
+ ```commandline
96
+ {
97
+ "name": {"type": "char"},
98
+ "shortcut": {"type": "char"},
99
+ "id": {"type": "integer"},
100
+ "display_name": {"type": "char"},
101
+ "create_uid": {"type": "many2one"},
102
+ "create_date": {"type": "datetime"},
103
+ "write_uid": {"type": "many2one"},
104
+ "write_date": {"type": "datetime"},
105
+ }
106
+ ```
107
+ ## A Little Detail
108
+ ### Bot Instance
109
+ ```python
110
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD) # Simple Connection
111
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD, secured=False) # For http:// (no-ssl) (localhost)
112
+ bot = oxw.Bot(test=True) # For XMLRPC Tests from Odoo saas
113
+ ```
114
+ If you are going to connect to a host with an unencrypted http protocol such as localhost,
115
+ `secured=False` must be specified.
116
+
117
+ `test=True` allows you to connect to one of Odoo's own xmlrpc test servers. Odoo assigns
118
+ you a random host, database, user and password from the demo servers. You don't need other
119
+ attributes when test option is selected.
120
+ ### Active Model
121
+ The default model when a bot instance is initialized is `"res.users"`. So when you command
122
+ `bot.count()` it returns active users total as an integer.
123
+
124
+ You can assign the active model at any time with `bot.model = "model.name"` or when calling
125
+ any next method, such as `bot.count("res.partner")`
126
+
127
+ ## Contribution
128
+ Feel free to contribute. This project needs a fine exception handling.
129
+ ## License
130
+ [MIT License](https://en.wikipedia.org/wiki/MIT_License)
131
+
132
+ Copyright 2023 Cagatay URESIN
133
+
134
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
135
+ software and associated documentation files (the “Software”), to deal in the Software
136
+ without restriction, including without limitation the rights to use, copy, modify, merge,
137
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
138
+ to whom the Software is furnished to do so, subject to the following conditions:
139
+
140
+ The above copyright notice and this permission notice shall be included in all copies or
141
+ substantial portions of the Software.
142
+
143
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
144
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
145
+ PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
146
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
147
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
148
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "odoo_xmlrpc_wrapper"
3
+ version = "1.0.1"
4
+ description = "A simple Python library to make CRUD process easier"
5
+ readme = "README.md"
6
+ requires-python = ">=3.7"
7
+ license = {file = "LICENSE"}
8
+ keywords = ["odoo", "external", "api", "xmlrpc", "rpc", "wrapper"]
9
+ authors = [
10
+ {name = "Cagatay URESIN", email = "cagatayuresin@gmail.com"}
11
+ ]
12
+ maintainers = [
13
+ {name = "Cagatay URESIN", email = "cagatayuresin@gmail.com"}
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Environment :: Console",
18
+ "Framework :: Odoo",
19
+ "Framework :: Odoo :: 16.0",
20
+ "Intended Audience :: Developers",
21
+ "Intended Audience :: System Administrators",
22
+ "License :: Freeware",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Programming Language :: Python :: 3.7",
27
+ "Topic :: Office/Business",
28
+ "Topic :: Software Development :: Libraries",
29
+ "Topic :: Software Development :: Libraries :: Python Modules",
30
+ ]
31
+ [project.urls]
32
+ "Homepage" = "https://github.com/cagatayuresin/odoo-xmlrpc-wrapper"
33
+ "Bug Reports" = "https://github.com/cagatayuresin/odoo-xmlrpc-wrapper/issues"
34
+ "Buy Me A Coffee" = "https://www.buymeacoffee.com/cagatayuresin"
35
+ "Source" = "https://github.com/cagatayuresin/odoo-xmlrpc-wrapper"
36
+ [build-system]
37
+ requires = ["setuptools>=43.0.0", "wheel"]
38
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,41 @@
1
+ [metadata]
2
+ name = odoo_xmlrpc_wrapper
3
+ version = 1.0.1
4
+ author = Cagatay URESIN
5
+ author_email = cagatayuresin@gmail.com
6
+ description = A simple Python library to make CRUD process easier
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
10
+ project_urls =
11
+ Bug Tracker = https://github.com/cagatayuresin/odoo-xmlrpc-wrapper/-/issues
12
+ repository = https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
13
+ classifiers =
14
+ Development Status :: 5 - Production/Stable
15
+ Environment :: Console
16
+ Framework :: Odoo
17
+ Framework :: Odoo :: 16.0
18
+ Intended Audience :: Developers
19
+ Intended Audience :: System Administrators
20
+ License :: Freeware
21
+ License :: OSI Approved :: MIT License
22
+ Operating System :: OS Independent
23
+ Programming Language :: Python :: 3 :: Only
24
+ Programming Language :: Python :: 3.7
25
+ Topic :: Office/Business
26
+ Topic :: Software Development :: Libraries
27
+ Topic :: Software Development :: Libraries :: Python Modules
28
+
29
+ [options]
30
+ package_dir =
31
+ = src
32
+ packages = find:
33
+ python_requires = >=3.7
34
+
35
+ [options.packages.find]
36
+ where = src
37
+
38
+ [egg_info]
39
+ tag_build =
40
+ tag_date = 0
41
+
@@ -0,0 +1,36 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="odoo_xmlrpc_wrapper",
8
+ version="1.0.1",
9
+ description="A simple Python library to make CRUD process easier.",
10
+ long_description=long_description,
11
+ long_description_content_type="text/markdown",
12
+ url="https://github.com/cagatayuresin/odoo-xmlrpc-wrapper",
13
+ author="Cagatay URESIN",
14
+ author_email="cagatayuresin@gmail.com",
15
+ license="MIT",
16
+ classifiers=[
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Environment :: Console",
19
+ "Framework :: Odoo",
20
+ "Framework :: Odoo :: 16.0",
21
+ "Intended Audience :: Developers",
22
+ "Intended Audience :: System Administrators",
23
+ "License :: Freeware",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.7",
28
+ "Topic :: Office/Business",
29
+ "Topic :: Software Development :: Libraries",
30
+ "Topic :: Software Development :: Libraries :: Python Modules",
31
+ ],
32
+ package_dir={"": "src"},
33
+ packages=find_packages(where="src"),
34
+ python_requires=">=3.7",
35
+ keywords="odoo external api xmlrpc rpc wrapper",
36
+ )
@@ -0,0 +1,8 @@
1
+ """
2
+ Odoo XMLRPC Wrapper
3
+
4
+ A simple Python to make CRUD process easier
5
+ """
6
+
7
+ __version__ = "1.0.1"
8
+ __author__ = 'Cagatay URESIN'
@@ -0,0 +1,264 @@
1
+ import xmlrpc.client
2
+
3
+
4
+ class Bot:
5
+ """
6
+ A bot class to rule them all.
7
+ """
8
+
9
+ def __init__(
10
+ self,
11
+ host: str = None,
12
+ db: str = None,
13
+ userlogin: str = None,
14
+ password: str = None,
15
+ secured: bool = True,
16
+ test: bool = False,
17
+ ) -> None:
18
+ """
19
+ Bot instance initializer: If test = True other arguments muted. For http:// secured = False
20
+
21
+ Args:
22
+ host (str, optional): The host 'odoo.yourhost.com'. Defaults to None.
23
+ db (str, optional): Database to login. Defaults to None.
24
+ userlogin (str, optional): Login string. Defaults to None.
25
+ password (str, optional): Password. Defaults to None.
26
+ secured (bool, optional): http:// or https://. Defaults to True.
27
+ test (bool, optional): To use Odoo's own test servers. Defaults to False.
28
+ """
29
+ self.__test_info = (
30
+ xmlrpc.client.ServerProxy("https://demo.odoo.com/start").start()
31
+ if test
32
+ else "Not Test"
33
+ )
34
+ self.HOST = self.__test_info["host"][8:] if test else host
35
+ self.URL = (
36
+ f"https://{self.HOST}/xmlrpc/2"
37
+ if secured
38
+ else f"http://{self.HOST}/xmlrpc/2"
39
+ )
40
+ self.DB = self.__test_info["database"] if test else db
41
+ self.USERLOGIN = self.__test_info["user"] if test else userlogin
42
+ self.__PASSWORD = self.__test_info["password"] if test else password
43
+ self.model = None
44
+ self.__common = xmlrpc.client.ServerProxy(f"{self.URL}/common")
45
+ self.version = self.__common.version()
46
+ self.uid = self.__common.authenticate(
47
+ self.DB, self.USERLOGIN, self.__PASSWORD, {}
48
+ )
49
+ if not self.uid:
50
+ raise Exception(
51
+ f"Wrong one ({self.HOST}, {self.DB}, {self.USERLOGIN}, PASSWORD)"
52
+ )
53
+ self.__orm = xmlrpc.client.ServerProxy(f"{self.URL}/object")
54
+ self.profile = self.read("res.users", ids=self.uid, fields=["name"])[0]
55
+ self.name = self.profile["name"]
56
+ self.successful = True
57
+ print(
58
+ f"Successfully Logged\n"
59
+ f"Name: {self.name}\n"
60
+ f"DB: {self.DB}\n"
61
+ f"HOST: {self.HOST}\n"
62
+ f"VERSION: {self.version['server_version']}"
63
+ )
64
+
65
+ def search_read(
66
+ self,
67
+ model: str = None,
68
+ constraints: list = None,
69
+ fields: list = None,
70
+ limit: int = None,
71
+ ) -> list:
72
+ """
73
+ Searches with constraints amd reads the results fields.
74
+
75
+ Args:
76
+ model (str, optional): Model name. Defaults to None.
77
+ constraints (list, optional): Search constraints. Defaults to None.
78
+ fields (list, optional): Desired fields to read. Defaults to ["name"].
79
+ limit (int, optional): Result limit. Defaults to None.
80
+
81
+ Returns:
82
+ list: A list of results as dicts with desired fields.
83
+ """
84
+ if model:
85
+ self.model = model
86
+ if fields is None:
87
+ fields = ["name"]
88
+ if constraints is None:
89
+ constraints = [[]]
90
+ else:
91
+ constraints = [constraints]
92
+ return self.__orm.execute_kw(
93
+ self.DB,
94
+ self.uid,
95
+ self.__PASSWORD,
96
+ self.model,
97
+ "search_read",
98
+ constraints,
99
+ {"fields": fields} if limit is None else {"fields": fields, "limit": limit},
100
+ )
101
+
102
+ def search(
103
+ self,
104
+ model: str = None,
105
+ constraints: list = None,
106
+ offset: int = None,
107
+ limit: int = None,
108
+ ) -> list:
109
+ """
110
+ Searches with constraints and returns results ids.
111
+
112
+ Args:
113
+ model (str, optional): Model name. Defaults to None.
114
+ constraints (list, optional): Search constraints. Defaults to None.
115
+ offset (int, optional): Offset. Defaults to None.
116
+ limit (int, optional): Result limit. Defaults to None.
117
+
118
+ Returns:
119
+ list: A list of record ids as integers.
120
+ """
121
+ if model:
122
+ self.model = model
123
+ if constraints is None:
124
+ constraints = [[]]
125
+ else:
126
+ constraints = [constraints]
127
+ return self.__orm.execute_kw(
128
+ self.DB,
129
+ self.uid,
130
+ self.__PASSWORD,
131
+ self.model,
132
+ "search",
133
+ constraints,
134
+ {"offset": offset, "limit": limit}
135
+ if offset and limit
136
+ else {"offset": offset}
137
+ if offset
138
+ else {"limit": limit}
139
+ if limit
140
+ else {},
141
+ )
142
+
143
+ def count(self, model: str = None, constraints: list = None) -> int:
144
+ """
145
+ Length of records with constraints.
146
+
147
+ Args:
148
+ model (str, optional): Model name. Defaults to None.
149
+ constraints (list, optional): Search constraints. Defaults to None.
150
+
151
+ Returns:
152
+ int: Count of records.
153
+ """
154
+ return len(self.search(model, constraints))
155
+
156
+ def read(self, model: str = None, ids: list = None, fields: list = None) -> list:
157
+ """
158
+ Reads ids with desired fields.
159
+
160
+ Args:
161
+ model (str, optional): Model name. Defaults to None.
162
+ ids (list, optional): List of ids to read. Defaults to None.
163
+ fields (list, optional): Desired fields to read. Defaults to None.
164
+
165
+ Returns:
166
+ list: A list of results as dicts with desired fields.
167
+ """
168
+ if model:
169
+ self.model = model
170
+ return self.__orm.execute_kw(
171
+ self.DB,
172
+ self.uid,
173
+ self.__PASSWORD,
174
+ self.model,
175
+ "read",
176
+ [ids],
177
+ {"fields": fields} if fields else {},
178
+ )
179
+
180
+ def delete(self, model: str = None, ids: list = None) -> None:
181
+ """
182
+ ID list to delete.
183
+
184
+ Args:
185
+ model (str, optional): Model name. Defaults to None.
186
+ ids (list, optional): List of ids to delete. Defaults to None.
187
+ """
188
+ if model:
189
+ self.model = model
190
+ self.__orm.execute_kw(
191
+ self.DB,
192
+ self.uid,
193
+ self.__PASSWORD,
194
+ self.model,
195
+ "unlink",
196
+ [ids] if isinstance(ids, list) else [[ids]],
197
+ )
198
+
199
+ def create(self, model: str = None, the_obj: dict = None) -> None:
200
+ """
201
+ Creates new record.
202
+
203
+ Args:
204
+ model (str, optional): Model name. Defaults to None.
205
+ the_obj (dict, optional): The object as dict to create. Defaults to None.
206
+
207
+ Raises:
208
+ ValueError: No Object
209
+ """
210
+ if the_obj is None:
211
+ raise ValueError("No Object")
212
+ if model:
213
+ self.model = model
214
+ self.__orm.execute_kw(
215
+ self.DB, self.uid, self.__PASSWORD, self.model, "create", [the_obj]
216
+ )
217
+
218
+ def update(
219
+ self, model: str = None, the_id: int = None, the_obj: dict = None
220
+ ) -> None:
221
+ """
222
+ Updates a record.
223
+
224
+ Args:
225
+ model (str, optional): Model name. Defaults to None.
226
+ the_id (int, optional): The id as integer of the record. Defaults to None.
227
+ the_obj (dict, optional): The object as dict to update. Defaults to None.
228
+
229
+ Raises:
230
+ ValueError: No ID
231
+ ValueError: No Object
232
+ """
233
+ if id is None:
234
+ raise ValueError("No ID")
235
+ if the_obj is None:
236
+ raise ValueError("No Object")
237
+ if model:
238
+ self.model = model
239
+ self.__orm.execute_kw(
240
+ self.DB, self.uid, self.__PASSWORD, self.model, "write", [[the_id], the_obj]
241
+ )
242
+
243
+ def get_fields(self, model: str = None, attributes: list = None) -> dict:
244
+ """
245
+ Model fields with desired infos.
246
+
247
+ Args:
248
+ model (str, optional): Model name. Defaults to None.
249
+ attributes (list, optional): Desired attributes of the fields. Defaults to None.
250
+
251
+ Returns:
252
+ dict: Fields of the model.
253
+ """
254
+ if model:
255
+ self.model = model
256
+ return self.__orm.execute_kw(
257
+ self.DB,
258
+ self.uid,
259
+ self.__PASSWORD,
260
+ self.model,
261
+ "fields_get",
262
+ [],
263
+ {"attributes": attributes} if attributes else {},
264
+ )
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.1
2
+ Name: odoo-xmlrpc-wrapper
3
+ Version: 1.0.1
4
+ Summary: A simple Python library to make CRUD process easier
5
+ Home-page: https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
6
+ Author: Cagatay URESIN
7
+ Author-email: Cagatay URESIN <cagatayuresin@gmail.com>
8
+ Maintainer-email: Cagatay URESIN <cagatayuresin@gmail.com>
9
+ License: MIT License
10
+
11
+ Copyright 2023 Cagatay URESIN
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
14
+ documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
15
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ persons to whom the Software is furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
19
+ Software.
20
+
21
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
22
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ Project-URL: Homepage, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
27
+ Project-URL: Bug Reports, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper/issues
28
+ Project-URL: Buy Me A Coffee, https://www.buymeacoffee.com/cagatayuresin
29
+ Project-URL: Source, https://github.com/cagatayuresin/odoo-xmlrpc-wrapper
30
+ Keywords: odoo,external,api,xmlrpc,rpc,wrapper
31
+ Classifier: Development Status :: 5 - Production/Stable
32
+ Classifier: Environment :: Console
33
+ Classifier: Framework :: Odoo
34
+ Classifier: Framework :: Odoo :: 16.0
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: System Administrators
37
+ Classifier: License :: Freeware
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Operating System :: OS Independent
40
+ Classifier: Programming Language :: Python :: 3 :: Only
41
+ Classifier: Programming Language :: Python :: 3.7
42
+ Classifier: Topic :: Office/Business
43
+ Classifier: Topic :: Software Development :: Libraries
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Requires-Python: >=3.7
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+
49
+ <a href="https://www.buymeacoffee.com/cagatayuresin" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
50
+ # Odoo XMLRPC Wrapper
51
+ ***
52
+ A small wrapper for oversimplifying CRUD operations and connecting to the Odoo External API
53
+ with the Python xmlrpc module.
54
+ ***
55
+ ## Index
56
+ * [Getting Started](#getting-started)
57
+ * [Installing via pip](#installing-via-pip)
58
+ * [A Simple Connection](#a-simple-connection)
59
+ * [CRUD Operations](#crud-operations)
60
+ * [Create](#create)
61
+ * [Read](#read)
62
+ * [Update](#update)
63
+ * [Delete](#delete)
64
+ * [Miscellaneous](#miscellaneous)
65
+ * [Search](#search)
66
+ * [Search and Read](#search-and-read)
67
+ * [Count](#count)
68
+ * [Get Fields](#get-fields)
69
+ * [A Little Detail](#a-little-detail)
70
+ * [Bot Instance](#bot-instance)
71
+ * [Active Model](#active-model)
72
+ * [Contribution](#contribution)
73
+ * [License](#license)
74
+ ***
75
+ ## Getting Started
76
+ ### Installing via pip
77
+ ```bash
78
+ pip install odoo-xmlrpc-wrapper
79
+ ```
80
+ ### A Simple Connection
81
+ ```python
82
+ from odoo_xmlrpc_wrapper import odoo_xmlrpc_wrapper as oxw
83
+
84
+
85
+ HOST = "odoo.myhost.com"
86
+ DB = "my_test_db"
87
+ USERLOGIN = "mymailtologin@odoo.com"
88
+ PASSWORD = "mypass"
89
+
90
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD)
91
+ ```
92
+ Prints:
93
+ ```commandline
94
+ Successfully Logged
95
+ Name: Mitchell Admin
96
+ DB: my_test_db
97
+ HOST: https://odoo.myhost.com
98
+ VERSION: saas~16.1
99
+ ```
100
+ ### CRUD Operations
101
+ Once the model to be processed in the CRUD functions is entered, the following other
102
+ You do not need to specify the model again as long as the model does not change to
103
+ the operation functions.
104
+ #### Create
105
+ ```python
106
+ bot.create("res.partner", {"name": "John Doe"})
107
+ ```
108
+ #### Read
109
+ ```python
110
+ bot.read(ids=[84], fields=["name"])
111
+ ```
112
+ Returns: `[{"id": 84, "name": "John Doe"}]`
113
+ #### Update
114
+ ```python
115
+ bot.update(the_id=84, the_obj={"name": "Jane Doe"})
116
+ ```
117
+ #### Delete
118
+ ```python
119
+ bot.delete(ids=[84])
120
+ ```
121
+ ### Miscellaneous
122
+ #### Search
123
+ ```python
124
+ bot.search(constraints=[("name", "=", "Mitchell Admin")])
125
+ ```
126
+ Returns:
127
+ `[2]`
128
+ #### Search and Read
129
+ ```python
130
+ bot.search_read(constraints=[("name", "=", "Mitchell Admin")])
131
+ ```
132
+ Returns: `[{'id': 2, 'name': 'Mitchell Admin'}]`
133
+ #### Count
134
+ ```python
135
+ bot.count()
136
+ ```
137
+ Returns: `78`
138
+ #### Get Fields
139
+ ```python
140
+ bot.get_fields("res.partner.title", attributes=["type"])
141
+ ```
142
+ Output:
143
+ ```commandline
144
+ {
145
+ "name": {"type": "char"},
146
+ "shortcut": {"type": "char"},
147
+ "id": {"type": "integer"},
148
+ "display_name": {"type": "char"},
149
+ "create_uid": {"type": "many2one"},
150
+ "create_date": {"type": "datetime"},
151
+ "write_uid": {"type": "many2one"},
152
+ "write_date": {"type": "datetime"},
153
+ }
154
+ ```
155
+ ## A Little Detail
156
+ ### Bot Instance
157
+ ```python
158
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD) # Simple Connection
159
+ bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD, secured=False) # For http:// (no-ssl) (localhost)
160
+ bot = oxw.Bot(test=True) # For XMLRPC Tests from Odoo saas
161
+ ```
162
+ If you are going to connect to a host with an unencrypted http protocol such as localhost,
163
+ `secured=False` must be specified.
164
+
165
+ `test=True` allows you to connect to one of Odoo's own xmlrpc test servers. Odoo assigns
166
+ you a random host, database, user and password from the demo servers. You don't need other
167
+ attributes when test option is selected.
168
+ ### Active Model
169
+ The default model when a bot instance is initialized is `"res.users"`. So when you command
170
+ `bot.count()` it returns active users total as an integer.
171
+
172
+ You can assign the active model at any time with `bot.model = "model.name"` or when calling
173
+ any next method, such as `bot.count("res.partner")`
174
+
175
+ ## Contribution
176
+ Feel free to contribute. This project needs a fine exception handling.
177
+ ## License
178
+ [MIT License](https://en.wikipedia.org/wiki/MIT_License)
179
+
180
+ Copyright 2023 Cagatay URESIN
181
+
182
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
183
+ software and associated documentation files (the “Software”), to deal in the Software
184
+ without restriction, including without limitation the rights to use, copy, modify, merge,
185
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
186
+ to whom the Software is furnished to do so, subject to the following conditions:
187
+
188
+ The above copyright notice and this permission notice shall be included in all copies or
189
+ substantial portions of the Software.
190
+
191
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
192
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
193
+ PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
194
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
195
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
196
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ src/odoo_xmlrpc_wrapper/__init__.py
7
+ src/odoo_xmlrpc_wrapper/odoo_xmlrpc_wrapper.py
8
+ src/odoo_xmlrpc_wrapper.egg-info/PKG-INFO
9
+ src/odoo_xmlrpc_wrapper.egg-info/SOURCES.txt
10
+ src/odoo_xmlrpc_wrapper.egg-info/dependency_links.txt
11
+ src/odoo_xmlrpc_wrapper.egg-info/top_level.txt
12
+ tests/test_odoo_xmlrpc_wapper.py
@@ -0,0 +1 @@
1
+ odoo_xmlrpc_wrapper
@@ -0,0 +1,48 @@
1
+ import unittest
2
+ from src.odoo_xmlrpc_wrapper import odoo_xmlrpc_wrapper as oxw
3
+
4
+
5
+ class TestOXW(unittest.TestCase):
6
+ bot = oxw.Bot(test=True)
7
+
8
+ def test_case_0(self):
9
+ self.assertEqual(self.bot.successful, True)
10
+
11
+ def test_case_1(self):
12
+ self.bot.create("res.partner", {"name": "John Doe"})
13
+ self.assertEqual(
14
+ self.bot.search_read(constraints=[("name", "=", "John Doe")]),
15
+ [{"id": 84, "name": "John Doe"}],
16
+ )
17
+ self.assertEqual(
18
+ self.bot.search(constraints=[("name", "=", "John Doe")]),
19
+ [84],
20
+ )
21
+
22
+ def test_case_2(self):
23
+ self.bot.update(the_id=84, the_obj={"name": "Jane Doe"})
24
+ self.assertEqual(
25
+ self.bot.read(ids=[84], fields=["name"]), [{"id": 84, "name": "Jane Doe"}]
26
+ )
27
+
28
+ def test_case_3(self):
29
+ self.assertEqual(self.bot.count(), 79)
30
+
31
+ def test_case_4(self):
32
+ self.assertDictEqual(
33
+ self.bot.get_fields("res.partner.title", attributes=["type"]),
34
+ {
35
+ "name": {"type": "char"},
36
+ "shortcut": {"type": "char"},
37
+ "id": {"type": "integer"},
38
+ "display_name": {"type": "char"},
39
+ "create_uid": {"type": "many2one"},
40
+ "create_date": {"type": "datetime"},
41
+ "write_uid": {"type": "many2one"},
42
+ "write_date": {"type": "datetime"},
43
+ },
44
+ )
45
+
46
+
47
+ if __name__ == "__main__":
48
+ unittest.main()