-
-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathdependencies.py
More file actions
28 lines (22 loc) · 903 Bytes
/
dependencies.py
File metadata and controls
28 lines (22 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright 2025 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from typing import Annotated
from odoo.api import Environment
from odoo.addons.fastapi import context, dependencies
from fastapi import Depends
def odoo_env_with_context(
company_id: Annotated[int | None, Depends(dependencies.company_id)],
fastapi_endpoint_id: Annotated[int, Depends(dependencies.fastapi_endpoint_id)],
) -> Environment:
# Add a per endpoint customizable odoo environment context
env = context.odoo_env_ctx.get()
endpoint = env["fastapi.endpoint"].browse(fastapi_endpoint_id)
env = env(
context=dict(
env.context,
**endpoint._get_app_context(),
**({"allow_company_ids": [company_id]} if company_id else {}),
)
)
yield env