mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-19 11:52:18 -06:00
[ADD]document_url_google_drive: attach document from Google Drive
This commit is contained in:
committed by
Ivan Sokolov
parent
82b8383a8d
commit
ea29d68258
26
document_url_google_drive/wizard/document_url.py
Normal file
26
document_url_google_drive/wizard/document_url.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2023 Cetmix OÜ
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from urllib import parse
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class AddUrlWizard(models.TransientModel):
|
||||
_inherit = "ir.attachment.add_url"
|
||||
|
||||
@api.model
|
||||
def add_attachment_google_drive(self, url, name, active_model, active_ids):
|
||||
attachment_obj = self.env["ir.attachment"]
|
||||
url_parse = parse.urlparse(url)
|
||||
if not url_parse.scheme:
|
||||
url_parse = parse.urlparse("{}{}".format("http://", url))
|
||||
for active_id in active_ids:
|
||||
attachment = {
|
||||
"name": name,
|
||||
"type": "url",
|
||||
"url": url_parse.geturl(),
|
||||
"res_id": active_id,
|
||||
"res_model": active_model,
|
||||
}
|
||||
attachment_obj.create(attachment)
|
||||
Reference in New Issue
Block a user