opt client

This commit is contained in:
Ivan Office
2024-12-05 04:00:12 +08:00
parent 0b3e3be378
commit a2ad59b66a
4 changed files with 12 additions and 6 deletions

View File

@@ -26,7 +26,7 @@
{ {
'name': 'odooapp.cn SaaS Client.Odoo中文应用商店SaaS云服务客户端', 'name': 'odooapp.cn SaaS Client.Odoo中文应用商店SaaS云服务客户端',
'version': '16.24.11.08', 'version': '16.24.12.05',
'author': 'odooai.cn', 'author': 'odooai.cn',
'category': 'Base', 'category': 'Base',
'website': 'https://www.odooai.cn', 'website': 'https://www.odooai.cn',

View File

@@ -12,3 +12,5 @@ class AuthOAuthProvider(models.Model):
# 取code的url主要针对国内的先取code再拿Token的方式 # 取code的url主要针对国内的先取code再拿Token的方式
code_endpoint = fields.Char(string='Token by Code Endpoint', help='Get Token from Code. Only for Code response type.') code_endpoint = fields.Char(string='Token by Code Endpoint', help='Get Token from Code. Only for Code response type.')
user_template_id = fields.Many2one('res.users', string='New User Template',
domain=[('active', '=', False)])

View File

@@ -38,6 +38,7 @@ class ResUsers(models.Model):
# 这里原生是已取 token实际用 code 时要另取token # 这里原生是已取 token实际用 code 时要另取token
access_token = params.get('access_token') access_token = params.get('access_token')
oauth_provider = self.env['auth.oauth.provider'].browse(provider) oauth_provider = self.env['auth.oauth.provider'].browse(provider)
kw = {}
if oauth_provider.code_endpoint and oauth_provider.scope.find('odoo') >= 0: if oauth_provider.code_endpoint and oauth_provider.scope.find('odoo') >= 0:
# odoo 特殊处理用code取token # odoo 特殊处理用code取token
if not access_token and params.get('code'): if not access_token and params.get('code'):
@@ -52,10 +53,10 @@ class ResUsers(models.Model):
response = requests.get(oauth_provider.code_endpoint, params=params, timeout=20) response = requests.get(oauth_provider.code_endpoint, params=params, timeout=20)
if response.ok: if response.ok:
ret = response.json() ret = response.json()
res = {**ret, **params} kw = {**ret, **params}
res.pop('code') kw.pop('code')
self = self.with_context(auth_extra=params) self = self.with_context(auth_extra=kw)
res = super(ResUsers, self).auth_oauth(provider, res) res = super(ResUsers, self).auth_oauth(provider, kw)
return res return res
def _create_user_from_template(self, values): def _create_user_from_template(self, values):
@@ -88,7 +89,7 @@ class ResUsers(models.Model):
@api.model @api.model
def _generate_signup_values(self, provider, validation, params): def _generate_signup_values(self, provider, validation, params):
# 此处生成 创建 odoo user 的初始值,增加字段如头像 # 此处生成 创建 odoo user 的初始值,增加字段如头像
res = super(ResUsers, self)._generate_signup_values(provider, validation, params) res = super()._generate_signup_values(provider, validation, params)
# 后置增加字段,包括 headimgurl # 后置增加字段,包括 headimgurl
if validation.get('mobile'): if validation.get('mobile'):
res['mobile'] = validation.get('mobile') res['mobile'] = validation.get('mobile')

View File

@@ -8,6 +8,9 @@
<xpath expr="//field[@name='auth_endpoint']" position="after"> <xpath expr="//field[@name='auth_endpoint']" position="after">
<field name="code_endpoint"/> <field name="code_endpoint"/>
</xpath> </xpath>
<xpath expr="//field[@name='data_endpoint']" position="before">
<field name="user_template_id"/>
</xpath>
</field> </field>
</record> </record>
</odoo> </odoo>