66from odoo .api import Environment
77from odoo .exceptions import AccessDenied
88
9- from odoo .addons .base .models .res_partner import Partner
10- from odoo .addons .base .models .res_users import Users
9+ from odoo .addons .base .models .res_partner import ResPartner
10+ from odoo .addons .base .models .res_users import ResUsers
1111
1212from fastapi import Depends , Header , HTTPException , Query , status
1313from fastapi .security import HTTPBasic , HTTPBasicCredentials
@@ -35,29 +35,31 @@ def odoo_env(company_id: Annotated[int | None, Depends(company_id)]) -> Environm
3535 yield env
3636
3737
38- def authenticated_partner_impl () -> Partner :
38+ def authenticated_partner_impl () -> ResPartner :
3939 """This method has to be overriden when you create your fastapi app
4040 to declare the way your partner will be provided. In some case, this
4141 partner will come from the authentication mechanism (ex jwt token) in other cases
4242 it could comme from a lookup on an email received into an HTTP header ...
4343 See the fastapi_endpoint_demo for an example"""
4444
4545
46- def optionally_authenticated_partner_impl () -> Partner | None :
46+ def optionally_authenticated_partner_impl () -> ResPartner | None :
4747 """This method has to be overriden when you create your fastapi app
4848 and you need to get an optional authenticated partner into your endpoint.
4949 """
5050
5151
5252def authenticated_partner_env (
53- partner : Annotated [Partner , Depends (authenticated_partner_impl )],
53+ partner : Annotated [ResPartner , Depends (authenticated_partner_impl )],
5454) -> Environment :
5555 """Return an environment with the authenticated partner id in the context"""
5656 return partner .with_context (authenticated_partner_id = partner .id ).env
5757
5858
5959def optionally_authenticated_partner_env (
60- partner : Annotated [Partner | None , Depends (optionally_authenticated_partner_impl )],
60+ partner : Annotated [
61+ ResPartner | None , Depends (optionally_authenticated_partner_impl )
62+ ],
6163 env : Annotated [Environment , Depends (odoo_env )],
6264) -> Environment :
6365 """Return an environment with the authenticated partner id in the context if
@@ -69,9 +71,9 @@ def optionally_authenticated_partner_env(
6971
7072
7173def authenticated_partner (
72- partner : Annotated [Partner , Depends (authenticated_partner_impl )],
74+ partner : Annotated [ResPartner , Depends (authenticated_partner_impl )],
7375 partner_env : Annotated [Environment , Depends (authenticated_partner_env )],
74- ) -> Partner :
76+ ) -> ResPartner :
7577 """If you need to get access to the authenticated partner into your
7678 endpoint, you can add a dependency into the endpoint definition on this
7779 method.
@@ -85,9 +87,11 @@ def authenticated_partner(
8587
8688
8789def optionally_authenticated_partner (
88- partner : Annotated [Partner | None , Depends (optionally_authenticated_partner_impl )],
90+ partner : Annotated [
91+ ResPartner | None , Depends (optionally_authenticated_partner_impl )
92+ ],
8993 partner_env : Annotated [Environment , Depends (optionally_authenticated_partner_env )],
90- ) -> Partner | None :
94+ ) -> ResPartner | None :
9195 """If you need to get access to the authenticated partner if the call is
9296 authenticated, you can add a dependency into the endpoint definition on this
9397 method.
@@ -110,21 +114,20 @@ def paging(
110114def basic_auth_user (
111115 credential : Annotated [HTTPBasicCredentials , Depends (HTTPBasic ())],
112116 env : Annotated [Environment , Depends (odoo_env )],
113- ) -> Users :
117+ ) -> ResUsers :
114118 username = credential .username
115119 password = credential .password
116120 try :
117121 response = (
118122 env ["res.users" ]
119123 .sudo ()
120124 .authenticate (
121- db = env .cr .dbname ,
122125 credential = {
123126 "type" : "password" ,
124127 "login" : username ,
125128 "password" : password ,
126129 },
127- user_agent_env = None ,
130+ user_agent_env = { "interactive" : False } ,
128131 )
129132 )
130133 return env ["res.users" ].browse (response .get ("uid" ))
@@ -137,9 +140,9 @@ def basic_auth_user(
137140
138141
139142def authenticated_partner_from_basic_auth_user (
140- user : Annotated [Users , Depends (basic_auth_user )],
143+ user : Annotated [ResUsers , Depends (basic_auth_user )],
141144 env : Annotated [Environment , Depends (odoo_env )],
142- ) -> Partner :
145+ ) -> ResPartner :
143146 return env ["res.partner" ].browse (user .sudo ().partner_id .id )
144147
145148
0 commit comments