Skip to content

Commit

Permalink
[ADD]document_url_google_drive: attach document from Google Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
DemchukM authored and ivs-cetmix committed Feb 6, 2024
1 parent 82b8383 commit a6458b3
Show file tree
Hide file tree
Showing 28 changed files with 961 additions and 0 deletions.
141 changes: 141 additions & 0 deletions document_url_google_drive/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
===========================
Google Drive URL Attachment
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:deb01521530a7f8d5aab1ef3941cdf3294c3860128751afe42a4dd6d6ed46efe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
:target: https://github.com/OCA/knowledge/tree/16.0/document_url_google_drive
:alt: OCA/knowledge
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-document_url_google_drive
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of the document_url module and
allows you to attach a link to a file from your Google Drive

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

- Go to Settings -> General Settings and scroll down to the
Integrations section.

- Enable "Google API", save. Setup instructions
https://developers.google.com/drive/picker/guides/overview

- "Google Client ID" - enter the client ID from the Google API
console:
https://developers.google.com/identity/oauth2/web/guides/get-google-api-clientid
- "Google API key" - enter the API key from the Google API console.
- "Google App ID" - enter the ID of the Google application. The
default value is ``odoo``.

You will be asked to authenticate when you add a link for the first
time.

|Configuration|

**To modify your personal login credentials later**

- Open your user profile and set up personal access credentials on the
"Google API" tab.

- field "Google Scope" - enter the scope for the Google API. The
default value is
``https://www.googleapis.com/auth/drive.readonly``.
- 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. Example:
``application/pdf, image/jpeg, image/png``. By default, all files
are selected

You can always log off from the current Google Account by clicking
the "logout" icon right to the "Add GDrive link".

.. |Configuration| image:: https://raw.githubusercontent.com/OCA/knowledge/16.0/document_url_google_drive/static/img/google_api_settings.png

Usage
=====

To use this module, you need to:

1. Open the form view of an object (Example: Customer Invoice
INV/2019/0007).
2. Go to the chatter and click on the attached icon.
3. Click **Add GDrive link**.
4. Fill the wizard fields and click on Add button.
5. In the open window, select the files you need and press the select
button.
6. You will see a new **URL attachment** in the set of attachments
related to the object.
7. In order to log in under another google user, click on the logout
icon located after **Add GDrive link**

|Google Drive Link|

.. |Google Drive Link| image:: https://raw.githubusercontent.com/OCA/knowledge/16.0/document_url_google_drive/static/img/gdrive_link.png

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url_google_drive%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Cetmix

Contributors
------------

Cetmix <cetmix.com> Ivan Sokolov Mykola Demchuk

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/16.0/document_url_google_drive>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions document_url_google_drive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models, wizard
27 changes: 27 additions & 0 deletions document_url_google_drive/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Google Drive URL Attachment",
"summary": "Attach Google Drive link to Odoo document using Google Drive Picker",
"version": "16.0.1.0.0",
"category": "Tools",
"website": "https://github.com/OCA/knowledge",
"author": "Cetmix, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"document_url",
"google_account",
],
"data": [
"views/res_users_view.xml",
"views/res_config_settings_view.xml",
],
"assets": {
"web.assets_backend": [
"document_url_google_drive/static/src/js/attachment_google_picker.esm.js",
"document_url_google_drive/static/src/xml/google_picker_url.xml",
"document_url_google_drive/static/src/xml/attachment_google_picker.xml",
],
},
}
4 changes: 4 additions & 0 deletions document_url_google_drive/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import res_users, res_config_settings
26 changes: 26 additions & 0 deletions document_url_google_drive/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

is_active_google_api = fields.Boolean(
string="Google APIs",
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",
)
58 changes: 58 additions & 0 deletions document_url_google_drive/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (C) 2023 Cetmix OÜ
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResUsers(models.Model):
_inherit = "res.users"

google_picker_scope = fields.Char(
string="Google Scope",
default="https://www.googleapis.com/auth/drive.readonly",
)
google_picker_access_token = fields.Char(string="Google Access Token")
google_picker_expires_date = fields.Integer(string="Google Expires Date")
google_picker_mime_types = fields.Char(string="Google Mime Types")
google_picker_active = fields.Boolean(
compute="_compute_google_picker_active",
)

def get_google_picker_params(self):
"""
Get Google Picker params
:return: dict
"""
self.ensure_one()
config = self.env["ir.config_parameter"].sudo()
google_service = self.env["google.service"]

if not self.google_picker_active:
return {}
return {
"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,
"access_token": self.google_picker_access_token,
"expires_date": self.google_picker_expires_date,
"mime_types": self.google_picker_mime_types,
}

def save_google_picker_access_token(self, access_token, expires_date):
"""
Save Google Picker access token
:param access_token: str
:return: None
"""
self.ensure_one()
self.google_picker_access_token = access_token
self.google_picker_expires_date = expires_date

Check warning on line 50 in document_url_google_drive/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

document_url_google_drive/models/res_users.py#L48-L50

Added lines #L48 - L50 were not covered by tests

def _compute_google_picker_active(self):
"""
Compute Google Picker Active
:return: None
"""
conf = self.env["ir.config_parameter"].sudo()
self.google_picker_active = conf.get_param("is_active_google_api")
31 changes: 31 additions & 0 deletions document_url_google_drive/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
To configure this module, you need to:

- Go to Settings -> General Settings and scroll down to the Integrations section.

- Enable "Google API", save. Setup instructions https://developers.google.com/drive/picker/guides/overview

- "Google Client ID" - enter the client ID from the Google API console: https://developers.google.com/identity/oauth2/web/guides/get-google-api-clientid
- "Google API key" - enter the API key from the Google API console.
- "Google App ID" - enter the ID of the Google application. The default value is
`odoo`.

You will be asked to authenticate when you add a link for the first time.

![Configuration](../static/img/google_api_settings.png)

**To modify your personal login credentials later**

- Open your user profile and set up personal access credentials on the "Google
API" tab.

- field "Google Scope" - enter the scope for the Google API. The default value is
`https://www.googleapis.com/auth/drive.readonly`.
- 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.
Example: `application/pdf, image/jpeg, image/png`. By default, all files are
selected

You can always log off from the current Google Account by clicking the "logout" icon right to the "Add GDrive link".


3 changes: 3 additions & 0 deletions document_url_google_drive/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cetmix <cetmix.com>
Ivan Sokolov
Mykola Demchuk
2 changes: 2 additions & 0 deletions document_url_google_drive/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the functionality of the document_url module and allows you to
attach a link to a file from your Google Drive
11 changes: 11 additions & 0 deletions document_url_google_drive/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To use this module, you need to:

1. Open the form view of an object (Example: Customer Invoice INV/2019/0007).
1. Go to the chatter and click on the attached icon.
1. Click **Add GDrive link**.
1. Fill the wizard fields and click on Add button.
1. In the open window, select the files you need and press the select button.
1. You will see a new **URL attachment** in the set of attachments related to the object.
1. In order to log in under another google user, click on the logout icon located after **Add GDrive link**

![Google Drive Link](../static/img/gdrive_link.png)
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a6458b3

Please sign in to comment.