[FIX]document_url_google_drive: Moved part of settings from res.users to general settings adn add used and added use module google_account

This commit is contained in:
Demchuk Mykola 2023-11-06 22:01:32 +02:00
parent e5ce59e9b2
commit 0864db0ae0
8 changed files with 63 additions and 29 deletions

View File

@ -11,6 +11,7 @@
"installable": True,
"depends": [
"document_url",
"google_account",
],
"data": [
"views/res_users_view.xml",

View File

@ -9,5 +9,18 @@ class ResConfigSettings(models.TransientModel):
is_active_google_api = fields.Boolean(
string="Google APIs",
config_parameter="document_url_google_drive.is_active_google_api",
config_parameter="is_active_google_api",
)
google_picker_client_id = fields.Char(
string="Google Client ID",
config_parameter="google_picker_client_id",
)
google_picker_api_key = fields.Char(
string="Google API Key",
config_parameter="google_picker_api_key",
)
google_picker_app_id = fields.Char(
string="Google App ID",
config_parameter="google_picker_app_id",
default="odoo",
)

View File

@ -6,16 +6,11 @@ from odoo import fields, models
class ResUsers(models.Model):
_inherit = "res.users"
google_picker_client_id = fields.Char(string="Google Client ID")
google_picker_api_key = fields.Char(string="Google API Key")
google_picker_scope = fields.Char(
string="Google Scope",
default="https://www.googleapis.com/auth/drive.readonly",
)
google_picker_app_id = fields.Char(
string="Google App ID",
default="odoo",
)
google_picker_access_token = fields.Char(string="Google Access Token")
google_picker_mime_types = fields.Char(string="Google Mime Types")
@ -25,18 +20,17 @@ class ResUsers(models.Model):
:return: dict
"""
self.ensure_one()
is_active_google_api = (
self.env["ir.config_parameter"]
.sudo()
.get_param("document_url_google_drive.is_active_google_api")
)
config = self.env["ir.config_parameter"].sudo()
google_service = self.env["google.service"]
is_active_google_api = config.get_param("is_active_google_api")
if not is_active_google_api:
return {}
return {
"client_id": self.google_picker_client_id,
"api_key": self.google_picker_api_key,
"client_id": google_service._get_client_id("picker"),
"api_key": config.get_param("google_picker_api_key"),
"app_id": config.get_param("google_picker_app_id"),
"scope": self.google_picker_scope,
"app_id": self.google_picker_app_id,
"access_token": self.google_picker_access_token,
"mime_types": self.google_picker_mime_types,
}

View File

@ -4,15 +4,16 @@ To configure this module, you need to:
- Enable "Google API", save.
- field "Google Client ID" - enter the client ID from the Google API console.
- field "Google API key" - enter the API key from the Google API console.
- field "Google App ID" - enter the ID of the Google application. The default value is
`odoo`.
- Next, open your user profile and set up personal access credentials on the "Google
API" tab.
- field "Google Client ID" - enter the client ID from the Google API console.
- field "Google API key" - enter the API key from the Google API console.
- field "Google Scope" - enter the scope for the Google API. The default value is
`https://www.googleapis.com/auth/drive.readonly`.
- field "Google App ID" - enter the ID of the Google application. The default value is
`odoo`.
- field "Google Access Token" - your token will be displayed here. It is necessary to
edit it.
- field "Google Mime Types" - enter the file formats to be filtered when selecting.

View File

@ -66,7 +66,6 @@ export class AttachmentGooglePicker extends Component {
this.state.accessToken = null;
await this.saveUserAuthAccessToken();
}
// --------------------------------------------------------------------------
// Private
// --------------------------------------------------------------------------
@ -84,7 +83,7 @@ export class AttachmentGooglePicker extends Component {
}
async saveUserAuthAccessToken() {
this.orm.call("res.users", "save_google_picker_access_token", [
await this.orm.call("res.users", "save_google_picker_access_token", [
this.user.userId,
this.state.accessToken,
]);
@ -150,15 +149,15 @@ export class AttachmentGooglePicker extends Component {
async pickerCallback(data) {
if (data.action === window.google.picker.Action.PICKED) {
data[window.google.picker.Response.DOCUMENTS].forEach((document) => {
this.createAttachment(document);
});
for (const document of data.docs) {
await this.createAttachment(document);
}
await this._onAddedUrl();
}
}
async createAttachment(document) {
this.orm.call("ir.attachment.add_url", "add_attachment_google_drive", [
await this.orm.call("ir.attachment.add_url", "add_attachment_google_drive", [
document.url,
document.name,
this.props.record.chatter.thread.model,

View File

@ -19,6 +19,35 @@
<div class="text-muted">
Use google integration.
</div>
<div
class="content-group"
attrs="{'invisible': [('is_active_google_api','=',False)]}"
>
<div class="mt16 row">
<label
for="google_picker_client_id"
string="Google Client ID"
class="col-3 col-lg-3 o_light_label"
/>
<field name="google_picker_client_id" nolabel="1" />
</div>
<div class="mt16 row">
<label
for="google_picker_api_key"
string="Google Api Key"
class="col-3 col-lg-3 o_light_label"
/>
<field name="google_picker_api_key" nolabel="1" />
</div>
<div class="mt16 row">
<label
for="google_picker_app_id"
string="Google App Id"
class="col-3 col-lg-3 o_light_label"
/>
<field name="google_picker_app_id" nolabel="1" />
</div>
</div>
</div>
</div>
</xpath>

View File

@ -11,10 +11,7 @@
<xpath expr="//notebook" position="inside">
<page string="Google API">
<group>
<field name="google_picker_client_id" />
<field name="google_picker_api_key" />
<field name="google_picker_scope" />
<field name="google_picker_app_id" />
<field name="google_picker_access_token" readonly="1" />
<field name="google_picker_mime_types" />
</group>