odoo-addon-fastapi-endpoint-context 16.0.1.0.0.2__py3-none-any.whl

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,103 @@
1
+ ========================
2
+ fastapi_endpoint_context
3
+ ========================
4
+
5
+ ..
6
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
+ !! This file is generated by oca-gen-addon-readme !!
8
+ !! changes will be overwritten. !!
9
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10
+ !! source digest: sha256:088fe199709796fff2a016b1442b64d18d60b0aee7af68c52ad5a15f2137da50
11
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12
+
13
+ .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14
+ :target: https://odoo-community.org/page/development-status
15
+ :alt: Beta
16
+ .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18
+ :alt: License: AGPL-3
19
+ .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20
+ :target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context
21
+ :alt: OCA/rest-framework
22
+ .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23
+ :target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_endpoint_context
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/rest-framework&target_branch=16.0
27
+ :alt: Try me on Runboat
28
+
29
+ |badge1| |badge2| |badge3| |badge4| |badge5|
30
+
31
+ This module provides an overridable request context for FastAPI
32
+ endpoints.
33
+
34
+ It allows to customize the behavior of requests deep in the odoo call
35
+ stack according to the current request context without having to
36
+ override routers that may come from external modules.
37
+
38
+ This context contains by default the current endpoint app and id,
39
+ respectively accessible via
40
+ ``self.env.context.get('fastapi_endpoint_app')`` and
41
+ ``self.env.context.get('fastapi_endpoint_id')``.
42
+
43
+ **Table of contents**
44
+
45
+ .. contents::
46
+ :local:
47
+
48
+ Usage
49
+ =====
50
+
51
+ odoo_env dependency is automatically overridden to include FastAPI
52
+ endpoint context values.
53
+
54
+ You can override the ``fastapi.endpoint``->\ ``_get_app_context()``
55
+ method to add custom values to the context for your applications.
56
+
57
+ Bug Tracker
58
+ ===========
59
+
60
+ Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
61
+ In case of trouble, please check there if your issue has already been reported.
62
+ If you spotted it first, help us to smash it by providing a detailed and welcomed
63
+ `feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_endpoint_context%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
64
+
65
+ Do not contact contributors directly about support or help with technical issues.
66
+
67
+ Credits
68
+ =======
69
+
70
+ Authors
71
+ -------
72
+
73
+ * Akretion
74
+
75
+ Contributors
76
+ ------------
77
+
78
+ - Florian Mounier florian.mounier@akretion.com
79
+
80
+ Maintainers
81
+ -----------
82
+
83
+ This module is maintained by the OCA.
84
+
85
+ .. image:: https://odoo-community.org/logo.png
86
+ :alt: Odoo Community Association
87
+ :target: https://odoo-community.org
88
+
89
+ OCA, or the Odoo Community Association, is a nonprofit organization whose
90
+ mission is to support the collaborative development of Odoo features and
91
+ promote its widespread use.
92
+
93
+ .. |maintainer-paradoxxxzero| image:: https://github.com/paradoxxxzero.png?size=40px
94
+ :target: https://github.com/paradoxxxzero
95
+ :alt: paradoxxxzero
96
+
97
+ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
98
+
99
+ |maintainer-paradoxxxzero|
100
+
101
+ This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context>`_ project on GitHub.
102
+
103
+ You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
@@ -0,0 +1 @@
1
+ from . import models
@@ -0,0 +1,17 @@
1
+ # Copyright 2025 Akretion (http://www.akretion.com).
2
+ # @author Florian Mounier <florian.mounier@akretion.com>
3
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
+
5
+ {
6
+ "name": "fastapi_endpoint_context",
7
+ "version": "16.0.1.0.0",
8
+ "author": "Akretion, Odoo Community Association (OCA)",
9
+ "summary": "Provides an overridable request context for FastAPI endpoints",
10
+ "depends": ["fastapi"],
11
+ "website": "https://github.com/OCA/rest-framework",
12
+ "data": [],
13
+ "maintainers": ["paradoxxxzero"],
14
+ "demo": [],
15
+ "installable": True,
16
+ "license": "AGPL-3",
17
+ }
@@ -0,0 +1,28 @@
1
+ # Copyright 2025 Akretion (http://www.akretion.com).
2
+ # @author Florian Mounier <florian.mounier@akretion.com>
3
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
+
5
+ from typing import Annotated
6
+
7
+ from odoo.api import Environment
8
+
9
+ from odoo.addons.fastapi import context, dependencies
10
+
11
+ from fastapi import Depends
12
+
13
+
14
+ def odoo_env_with_context(
15
+ company_id: Annotated[int | None, Depends(dependencies.company_id)],
16
+ fastapi_endpoint_id: Annotated[int, Depends(dependencies.fastapi_endpoint_id)],
17
+ ) -> Environment:
18
+ # Add a per endpoint customizable odoo environment context
19
+ env = context.odoo_env_ctx.get()
20
+ endpoint = env["fastapi.endpoint"].browse(fastapi_endpoint_id)
21
+ env = env(
22
+ context=dict(
23
+ env.context,
24
+ **endpoint._get_app_context(),
25
+ **({"allow_company_ids": [company_id]} if company_id else {}),
26
+ )
27
+ )
28
+ yield env
@@ -0,0 +1,19 @@
1
+ # Translation of Odoo Server.
2
+ # This file contains the translation of the following modules:
3
+ # * fastapi_endpoint_context
4
+ #
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Odoo Server 16.0\n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "Last-Translator: \n"
10
+ "Language-Team: \n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: \n"
14
+ "Plural-Forms: \n"
15
+
16
+ #. module: fastapi_endpoint_context
17
+ #: model:ir.model,name:fastapi_endpoint_context.model_fastapi_endpoint
18
+ msgid "FastAPI Endpoint"
19
+ msgstr ""
@@ -0,0 +1 @@
1
+ from . import fastapi_endpoint
@@ -0,0 +1,25 @@
1
+ # Copyright 2025 Akretion (http://www.akretion.com).
2
+ # @author Florian Mounier <florian.mounier@akretion.com>
3
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
+
5
+ from odoo import models
6
+
7
+ from odoo.addons.fastapi import dependencies
8
+
9
+ from ..dependencies import odoo_env_with_context
10
+
11
+
12
+ class FastapiEndpoint(models.Model):
13
+ _inherit = "fastapi.endpoint"
14
+
15
+ def _get_app_context(self):
16
+ """Add the fastapi app and endpoint id to the odoo env context"""
17
+ return {
18
+ "fastapi_app": self.app,
19
+ "fastapi_endpoint_id": self.id,
20
+ }
21
+
22
+ def _get_app_dependencies_overrides(self):
23
+ res = super()._get_app_dependencies_overrides()
24
+ res.update({dependencies.odoo_env: odoo_env_with_context})
25
+ return res
@@ -0,0 +1 @@
1
+ - Florian Mounier <florian.mounier@akretion.com>
@@ -0,0 +1,9 @@
1
+ This module provides an overridable request context for FastAPI endpoints.
2
+
3
+ It allows to customize the behavior of requests deep in the odoo call stack
4
+ according to the current request context without having to override routers
5
+ that may come from external modules.
6
+
7
+ This context contains by default the current endpoint app and id, respectively
8
+ accessible via `self.env.context.get('fastapi_endpoint_app')` and
9
+ `self.env.context.get('fastapi_endpoint_id')`.
@@ -0,0 +1,3 @@
1
+ odoo_env dependency is automatically overridden to include FastAPI endpoint context values.
2
+
3
+ You can override the `fastapi.endpoint`->`_get_app_context()` method to add custom values to the context for your applications.
@@ -0,0 +1,441 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6
+ <title>fastapi_endpoint_context</title>
7
+ <style type="text/css">
8
+
9
+ /*
10
+ :Author: David Goodger (goodger@python.org)
11
+ :Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
12
+ :Copyright: This stylesheet has been placed in the public domain.
13
+
14
+ Default cascading style sheet for the HTML output of Docutils.
15
+ Despite the name, some widely supported CSS2 features are used.
16
+
17
+ See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
18
+ customize this style sheet.
19
+ */
20
+
21
+ /* used to remove borders from tables and images */
22
+ .borderless, table.borderless td, table.borderless th {
23
+ border: 0 }
24
+
25
+ table.borderless td, table.borderless th {
26
+ /* Override padding for "table.docutils td" with "! important".
27
+ The right padding separates the table cells. */
28
+ padding: 0 0.5em 0 0 ! important }
29
+
30
+ .first {
31
+ /* Override more specific margin styles with "! important". */
32
+ margin-top: 0 ! important }
33
+
34
+ .last, .with-subtitle {
35
+ margin-bottom: 0 ! important }
36
+
37
+ .hidden {
38
+ display: none }
39
+
40
+ .subscript {
41
+ vertical-align: sub;
42
+ font-size: smaller }
43
+
44
+ .superscript {
45
+ vertical-align: super;
46
+ font-size: smaller }
47
+
48
+ a.toc-backref {
49
+ text-decoration: none ;
50
+ color: black }
51
+
52
+ blockquote.epigraph {
53
+ margin: 2em 5em ; }
54
+
55
+ dl.docutils dd {
56
+ margin-bottom: 0.5em }
57
+
58
+ object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
59
+ overflow: hidden;
60
+ }
61
+
62
+ /* Uncomment (and remove this text!) to get bold-faced definition list terms
63
+ dl.docutils dt {
64
+ font-weight: bold }
65
+ */
66
+
67
+ div.abstract {
68
+ margin: 2em 5em }
69
+
70
+ div.abstract p.topic-title {
71
+ font-weight: bold ;
72
+ text-align: center }
73
+
74
+ div.admonition, div.attention, div.caution, div.danger, div.error,
75
+ div.hint, div.important, div.note, div.tip, div.warning {
76
+ margin: 2em ;
77
+ border: medium outset ;
78
+ padding: 1em }
79
+
80
+ div.admonition p.admonition-title, div.hint p.admonition-title,
81
+ div.important p.admonition-title, div.note p.admonition-title,
82
+ div.tip p.admonition-title {
83
+ font-weight: bold ;
84
+ font-family: sans-serif }
85
+
86
+ div.attention p.admonition-title, div.caution p.admonition-title,
87
+ div.danger p.admonition-title, div.error p.admonition-title,
88
+ div.warning p.admonition-title, .code .error {
89
+ color: red ;
90
+ font-weight: bold ;
91
+ font-family: sans-serif }
92
+
93
+ /* Uncomment (and remove this text!) to get reduced vertical space in
94
+ compound paragraphs.
95
+ div.compound .compound-first, div.compound .compound-middle {
96
+ margin-bottom: 0.5em }
97
+
98
+ div.compound .compound-last, div.compound .compound-middle {
99
+ margin-top: 0.5em }
100
+ */
101
+
102
+ div.dedication {
103
+ margin: 2em 5em ;
104
+ text-align: center ;
105
+ font-style: italic }
106
+
107
+ div.dedication p.topic-title {
108
+ font-weight: bold ;
109
+ font-style: normal }
110
+
111
+ div.figure {
112
+ margin-left: 2em ;
113
+ margin-right: 2em }
114
+
115
+ div.footer, div.header {
116
+ clear: both;
117
+ font-size: smaller }
118
+
119
+ div.line-block {
120
+ display: block ;
121
+ margin-top: 1em ;
122
+ margin-bottom: 1em }
123
+
124
+ div.line-block div.line-block {
125
+ margin-top: 0 ;
126
+ margin-bottom: 0 ;
127
+ margin-left: 1.5em }
128
+
129
+ div.sidebar {
130
+ margin: 0 0 0.5em 1em ;
131
+ border: medium outset ;
132
+ padding: 1em ;
133
+ background-color: #ffffee ;
134
+ width: 40% ;
135
+ float: right ;
136
+ clear: right }
137
+
138
+ div.sidebar p.rubric {
139
+ font-family: sans-serif ;
140
+ font-size: medium }
141
+
142
+ div.system-messages {
143
+ margin: 5em }
144
+
145
+ div.system-messages h1 {
146
+ color: red }
147
+
148
+ div.system-message {
149
+ border: medium outset ;
150
+ padding: 1em }
151
+
152
+ div.system-message p.system-message-title {
153
+ color: red ;
154
+ font-weight: bold }
155
+
156
+ div.topic {
157
+ margin: 2em }
158
+
159
+ h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
160
+ h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
161
+ margin-top: 0.4em }
162
+
163
+ h1.title {
164
+ text-align: center }
165
+
166
+ h2.subtitle {
167
+ text-align: center }
168
+
169
+ hr.docutils {
170
+ width: 75% }
171
+
172
+ img.align-left, .figure.align-left, object.align-left, table.align-left {
173
+ clear: left ;
174
+ float: left ;
175
+ margin-right: 1em }
176
+
177
+ img.align-right, .figure.align-right, object.align-right, table.align-right {
178
+ clear: right ;
179
+ float: right ;
180
+ margin-left: 1em }
181
+
182
+ img.align-center, .figure.align-center, object.align-center {
183
+ display: block;
184
+ margin-left: auto;
185
+ margin-right: auto;
186
+ }
187
+
188
+ table.align-center {
189
+ margin-left: auto;
190
+ margin-right: auto;
191
+ }
192
+
193
+ .align-left {
194
+ text-align: left }
195
+
196
+ .align-center {
197
+ clear: both ;
198
+ text-align: center }
199
+
200
+ .align-right {
201
+ text-align: right }
202
+
203
+ /* reset inner alignment in figures */
204
+ div.align-right {
205
+ text-align: inherit }
206
+
207
+ /* div.align-center * { */
208
+ /* text-align: left } */
209
+
210
+ .align-top {
211
+ vertical-align: top }
212
+
213
+ .align-middle {
214
+ vertical-align: middle }
215
+
216
+ .align-bottom {
217
+ vertical-align: bottom }
218
+
219
+ ol.simple, ul.simple {
220
+ margin-bottom: 1em }
221
+
222
+ ol.arabic {
223
+ list-style: decimal }
224
+
225
+ ol.loweralpha {
226
+ list-style: lower-alpha }
227
+
228
+ ol.upperalpha {
229
+ list-style: upper-alpha }
230
+
231
+ ol.lowerroman {
232
+ list-style: lower-roman }
233
+
234
+ ol.upperroman {
235
+ list-style: upper-roman }
236
+
237
+ p.attribution {
238
+ text-align: right ;
239
+ margin-left: 50% }
240
+
241
+ p.caption {
242
+ font-style: italic }
243
+
244
+ p.credits {
245
+ font-style: italic ;
246
+ font-size: smaller }
247
+
248
+ p.label {
249
+ white-space: nowrap }
250
+
251
+ p.rubric {
252
+ font-weight: bold ;
253
+ font-size: larger ;
254
+ color: maroon ;
255
+ text-align: center }
256
+
257
+ p.sidebar-title {
258
+ font-family: sans-serif ;
259
+ font-weight: bold ;
260
+ font-size: larger }
261
+
262
+ p.sidebar-subtitle {
263
+ font-family: sans-serif ;
264
+ font-weight: bold }
265
+
266
+ p.topic-title {
267
+ font-weight: bold }
268
+
269
+ pre.address {
270
+ margin-bottom: 0 ;
271
+ margin-top: 0 ;
272
+ font: inherit }
273
+
274
+ pre.literal-block, pre.doctest-block, pre.math, pre.code {
275
+ margin-left: 2em ;
276
+ margin-right: 2em }
277
+
278
+ pre.code .ln { color: gray; } /* line numbers */
279
+ pre.code, code { background-color: #eeeeee }
280
+ pre.code .comment, code .comment { color: #5C6576 }
281
+ pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
282
+ pre.code .literal.string, code .literal.string { color: #0C5404 }
283
+ pre.code .name.builtin, code .name.builtin { color: #352B84 }
284
+ pre.code .deleted, code .deleted { background-color: #DEB0A1}
285
+ pre.code .inserted, code .inserted { background-color: #A3D289}
286
+
287
+ span.classifier {
288
+ font-family: sans-serif ;
289
+ font-style: oblique }
290
+
291
+ span.classifier-delimiter {
292
+ font-family: sans-serif ;
293
+ font-weight: bold }
294
+
295
+ span.interpreted {
296
+ font-family: sans-serif }
297
+
298
+ span.option {
299
+ white-space: nowrap }
300
+
301
+ span.pre {
302
+ white-space: pre }
303
+
304
+ span.problematic, pre.problematic {
305
+ color: red }
306
+
307
+ span.section-subtitle {
308
+ /* font-size relative to parent (h1..h6 element) */
309
+ font-size: 80% }
310
+
311
+ table.citation {
312
+ border-left: solid 1px gray;
313
+ margin-left: 1px }
314
+
315
+ table.docinfo {
316
+ margin: 2em 4em }
317
+
318
+ table.docutils {
319
+ margin-top: 0.5em ;
320
+ margin-bottom: 0.5em }
321
+
322
+ table.footnote {
323
+ border-left: solid 1px black;
324
+ margin-left: 1px }
325
+
326
+ table.docutils td, table.docutils th,
327
+ table.docinfo td, table.docinfo th {
328
+ padding-left: 0.5em ;
329
+ padding-right: 0.5em ;
330
+ vertical-align: top }
331
+
332
+ table.docutils th.field-name, table.docinfo th.docinfo-name {
333
+ font-weight: bold ;
334
+ text-align: left ;
335
+ white-space: nowrap ;
336
+ padding-left: 0 }
337
+
338
+ /* "booktabs" style (no vertical lines) */
339
+ table.docutils.booktabs {
340
+ border: 0px;
341
+ border-top: 2px solid;
342
+ border-bottom: 2px solid;
343
+ border-collapse: collapse;
344
+ }
345
+ table.docutils.booktabs * {
346
+ border: 0px;
347
+ }
348
+ table.docutils.booktabs th {
349
+ border-bottom: thin solid;
350
+ text-align: left;
351
+ }
352
+
353
+ h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
354
+ h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
355
+ font-size: 100% }
356
+
357
+ ul.auto-toc {
358
+ list-style-type: none }
359
+
360
+ </style>
361
+ </head>
362
+ <body>
363
+ <div class="document" id="fastapi-endpoint-context">
364
+ <h1 class="title">fastapi_endpoint_context</h1>
365
+
366
+ <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367
+ !! This file is generated by oca-gen-addon-readme !!
368
+ !! changes will be overwritten. !!
369
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370
+ !! source digest: sha256:088fe199709796fff2a016b1442b64d18d60b0aee7af68c52ad5a15f2137da50
371
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372
+ <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_endpoint_context"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373
+ <p>This module provides an overridable request context for FastAPI
374
+ endpoints.</p>
375
+ <p>It allows to customize the behavior of requests deep in the odoo call
376
+ stack according to the current request context without having to
377
+ override routers that may come from external modules.</p>
378
+ <p>This context contains by default the current endpoint app and id,
379
+ respectively accessible via
380
+ <tt class="docutils literal"><span class="pre">self.env.context.get('fastapi_endpoint_app')</span></tt> and
381
+ <tt class="docutils literal"><span class="pre">self.env.context.get('fastapi_endpoint_id')</span></tt>.</p>
382
+ <p><strong>Table of contents</strong></p>
383
+ <div class="contents local topic" id="contents">
384
+ <ul class="simple">
385
+ <li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
386
+ <li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
387
+ <li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
388
+ <li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
389
+ <li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
390
+ <li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
391
+ </ul>
392
+ </li>
393
+ </ul>
394
+ </div>
395
+ <div class="section" id="usage">
396
+ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
397
+ <p>odoo_env dependency is automatically overridden to include FastAPI
398
+ endpoint context values.</p>
399
+ <p>You can override the <tt class="docutils literal">fastapi.endpoint</tt>-&gt;<tt class="docutils literal">_get_app_context()</tt>
400
+ method to add custom values to the context for your applications.</p>
401
+ </div>
402
+ <div class="section" id="bug-tracker">
403
+ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
404
+ <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
405
+ In case of trouble, please check there if your issue has already been reported.
406
+ If you spotted it first, help us to smash it by providing a detailed and welcomed
407
+ <a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_endpoint_context%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
408
+ <p>Do not contact contributors directly about support or help with technical issues.</p>
409
+ </div>
410
+ <div class="section" id="credits">
411
+ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
412
+ <div class="section" id="authors">
413
+ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
414
+ <ul class="simple">
415
+ <li>Akretion</li>
416
+ </ul>
417
+ </div>
418
+ <div class="section" id="contributors">
419
+ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
420
+ <ul class="simple">
421
+ <li>Florian Mounier <a class="reference external" href="mailto:florian.mounier&#64;akretion.com">florian.mounier&#64;akretion.com</a></li>
422
+ </ul>
423
+ </div>
424
+ <div class="section" id="maintainers">
425
+ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
426
+ <p>This module is maintained by the OCA.</p>
427
+ <a class="reference external image-reference" href="https://odoo-community.org">
428
+ <img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
429
+ </a>
430
+ <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
431
+ mission is to support the collaborative development of Odoo features and
432
+ promote its widespread use.</p>
433
+ <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
434
+ <p><a class="reference external image-reference" href="https://github.com/paradoxxxzero"><img alt="paradoxxxzero" src="https://github.com/paradoxxxzero.png?size=40px" /></a></p>
435
+ <p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context">OCA/rest-framework</a> project on GitHub.</p>
436
+ <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
437
+ </div>
438
+ </div>
439
+ </div>
440
+ </body>
441
+ </html>
@@ -0,0 +1 @@
1
+ from . import test_fastapi_endpoint_context
@@ -0,0 +1,51 @@
1
+ # Copyright 2025 Akretion (http://www.akretion.com).
2
+ # @author Florian Mounier <florian.mounier@akretion.com>
3
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
+
5
+ from typing import Annotated
6
+
7
+ from requests import Response
8
+
9
+ from odoo.api import Environment
10
+
11
+ from odoo.addons.fastapi.dependencies import odoo_env
12
+ from odoo.addons.fastapi.routers import demo_router
13
+ from odoo.addons.fastapi.tests.common import FastAPITransactionCase
14
+
15
+ from fastapi import Depends, status
16
+
17
+
18
+ # Extend the demo router to have an endpoint that returns the odoo env context
19
+ @demo_router.get("/demo/context")
20
+ async def get_context(env: Annotated[Environment, Depends(odoo_env)]) -> dict:
21
+ """Returns the odoo env context"""
22
+ return env.context
23
+
24
+
25
+ class FastAPIEndpointContextCase(FastAPITransactionCase):
26
+ @classmethod
27
+ def setUpClass(cls) -> None:
28
+ super().setUpClass()
29
+ cls.default_fastapi_router = demo_router
30
+ cls.default_fastapi_running_user = cls.env.ref("fastapi.my_demo_app_user")
31
+ cls.endpoint = cls.env.ref("fastapi.fastapi_endpoint_demo")
32
+ cls.default_fastapi_app = cls.endpoint._get_app()
33
+ cls.default_fastapi_dependency_overrides = {
34
+ k: v
35
+ for k, v in cls.default_fastapi_app.dependency_overrides.items()
36
+ if k.__name__ != "authenticated_partner_impl"
37
+ }
38
+ cls.default_fastapi_authenticated_partner = cls.env["res.partner"].create(
39
+ {"name": "FastAPI Demo"}
40
+ )
41
+
42
+ def test_context(self) -> None:
43
+ with self._create_test_client() as test_client:
44
+ response: Response = test_client.get("/demo/context")
45
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
46
+ ctx = response.json()
47
+ self.assertEqual(
48
+ ctx.get("fastapi_endpoint_id"),
49
+ self.env.ref("fastapi.fastapi_endpoint_demo").id,
50
+ )
51
+ self.assertEqual(ctx.get("fastapi_app"), "demo")
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.1
2
+ Name: odoo-addon-fastapi_endpoint_context
3
+ Version: 16.0.1.0.0.2
4
+ Summary: Provides an overridable request context for FastAPI endpoints
5
+ Home-page: https://github.com/OCA/rest-framework
6
+ Author: Akretion, Odoo Community Association (OCA)
7
+ Author-email: support@odoo-community.org
8
+ License: AGPL-3
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Framework :: Odoo
11
+ Classifier: Framework :: Odoo :: 16.0
12
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: odoo-addon-fastapi<16.1dev,>=16.0dev
15
+ Requires-Dist: odoo<16.1dev,>=16.0a
16
+
17
+ ========================
18
+ fastapi_endpoint_context
19
+ ========================
20
+
21
+ ..
22
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23
+ !! This file is generated by oca-gen-addon-readme !!
24
+ !! changes will be overwritten. !!
25
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26
+ !! source digest: sha256:088fe199709796fff2a016b1442b64d18d60b0aee7af68c52ad5a15f2137da50
27
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28
+
29
+ .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
30
+ :target: https://odoo-community.org/page/development-status
31
+ :alt: Beta
32
+ .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
33
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
34
+ :alt: License: AGPL-3
35
+ .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
36
+ :target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context
37
+ :alt: OCA/rest-framework
38
+ .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
39
+ :target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_endpoint_context
40
+ :alt: Translate me on Weblate
41
+ .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
42
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=16.0
43
+ :alt: Try me on Runboat
44
+
45
+ |badge1| |badge2| |badge3| |badge4| |badge5|
46
+
47
+ This module provides an overridable request context for FastAPI
48
+ endpoints.
49
+
50
+ It allows to customize the behavior of requests deep in the odoo call
51
+ stack according to the current request context without having to
52
+ override routers that may come from external modules.
53
+
54
+ This context contains by default the current endpoint app and id,
55
+ respectively accessible via
56
+ ``self.env.context.get('fastapi_endpoint_app')`` and
57
+ ``self.env.context.get('fastapi_endpoint_id')``.
58
+
59
+ **Table of contents**
60
+
61
+ .. contents::
62
+ :local:
63
+
64
+ Usage
65
+ =====
66
+
67
+ odoo_env dependency is automatically overridden to include FastAPI
68
+ endpoint context values.
69
+
70
+ You can override the ``fastapi.endpoint``->\ ``_get_app_context()``
71
+ method to add custom values to the context for your applications.
72
+
73
+ Bug Tracker
74
+ ===========
75
+
76
+ Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
77
+ In case of trouble, please check there if your issue has already been reported.
78
+ If you spotted it first, help us to smash it by providing a detailed and welcomed
79
+ `feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_endpoint_context%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
80
+
81
+ Do not contact contributors directly about support or help with technical issues.
82
+
83
+ Credits
84
+ =======
85
+
86
+ Authors
87
+ -------
88
+
89
+ * Akretion
90
+
91
+ Contributors
92
+ ------------
93
+
94
+ - Florian Mounier florian.mounier@akretion.com
95
+
96
+ Maintainers
97
+ -----------
98
+
99
+ This module is maintained by the OCA.
100
+
101
+ .. image:: https://odoo-community.org/logo.png
102
+ :alt: Odoo Community Association
103
+ :target: https://odoo-community.org
104
+
105
+ OCA, or the Odoo Community Association, is a nonprofit organization whose
106
+ mission is to support the collaborative development of Odoo features and
107
+ promote its widespread use.
108
+
109
+ .. |maintainer-paradoxxxzero| image:: https://github.com/paradoxxxzero.png?size=40px
110
+ :target: https://github.com/paradoxxxzero
111
+ :alt: paradoxxxzero
112
+
113
+ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
114
+
115
+ |maintainer-paradoxxxzero|
116
+
117
+ This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_endpoint_context>`_ project on GitHub.
118
+
119
+ You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
@@ -0,0 +1,18 @@
1
+ odoo/addons/fastapi_endpoint_context/README.rst,sha256=nVWmVSEwdxUmeYtcnGkkE4ttDciA7qDfnMZX4xXRUtY,3804
2
+ odoo/addons/fastapi_endpoint_context/__init__.py,sha256=X9EJGOE2GtZbS0G82PtSXmWSZ_R8jEM0rlJTDliQjp4,21
3
+ odoo/addons/fastapi_endpoint_context/__manifest__.py,sha256=x6VHMC3Pnw0IZw7ohzAUdOs_u9B4M88j1NCVGtpaWzo,592
4
+ odoo/addons/fastapi_endpoint_context/dependencies.py,sha256=nKrF4ZinPXncIc__NTziXuhnc4pWFjwFTy7rSMXhaYw,903
5
+ odoo/addons/fastapi_endpoint_context/i18n/fastapi_endpoint_context.pot,sha256=IUNykoUlIyFAyYIbrpqAcoBFO0EFFqOfF8RVNaDmwoU,514
6
+ odoo/addons/fastapi_endpoint_context/models/__init__.py,sha256=NF75IvaT9G60mgm2FqAkfw91SzMZ9m7CL41HiOD3rj4,31
7
+ odoo/addons/fastapi_endpoint_context/models/fastapi_endpoint.py,sha256=9reM4qDkZAL7T8W5nH_GgrMDe8DGLo1U0vV2TZZy028,773
8
+ odoo/addons/fastapi_endpoint_context/readme/CONTRIBUTORS.md,sha256=egDhKzBUjelsGYSHOUnJMq3TobE2mlOv39SNKvskZTI,49
9
+ odoo/addons/fastapi_endpoint_context/readme/DESCRIPTION.md,sha256=VQkCvJl0qJIvJgRX60Qt1TPIJvdvJK9qHSufMZfuM_E,458
10
+ odoo/addons/fastapi_endpoint_context/readme/USAGE.md,sha256=S9UTwm-lpayqbwsSTyY4LKS8t3FOk02ZUfm9tD6Dzog,221
11
+ odoo/addons/fastapi_endpoint_context/static/description/icon.png,sha256=CgnOEZCwoe6f1vlLwkqFVfc2q_uwBMU0UnXN8j6X5ag,10254
12
+ odoo/addons/fastapi_endpoint_context/static/description/index.html,sha256=AjqYt4VxRGjggedTjY01Tw9jlsf_3XiI44sJfim9-HY,13514
13
+ odoo/addons/fastapi_endpoint_context/tests/__init__.py,sha256=Iej1Q8_FT_0_oCdteSF9nDg9_H0w25x7XLydN41cP8c,44
14
+ odoo/addons/fastapi_endpoint_context/tests/test_fastapi_endpoint_context.py,sha256=LlEvDgFLJ0TSS-0HQhb13RszNgYQw5_31T804hIHzmw,1934
15
+ odoo_addon_fastapi_endpoint_context-16.0.1.0.0.2.dist-info/METADATA,sha256=EA0rEYShJV2oxhjUJgzHbOO7j6KmW8TePMcIRGAGOYg,4418
16
+ odoo_addon_fastapi_endpoint_context-16.0.1.0.0.2.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
17
+ odoo_addon_fastapi_endpoint_context-16.0.1.0.0.2.dist-info/top_level.txt,sha256=qBj40grFkGOfDZ2WDSw3y1RnDlgG0u8rP8pvGNdbz4w,5
18
+ odoo_addon_fastapi_endpoint_context-16.0.1.0.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.45.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+