diff --git a/dms/static/src/js/views/file_kanban_renderer.xml b/dms/static/src/js/views/file_kanban_renderer.xml index d774506c5..a1bb3c4fa 100644 --- a/dms/static/src/js/views/file_kanban_renderer.xml +++ b/dms/static/src/js/views/file_kanban_renderer.xml @@ -22,29 +22,31 @@ t-inherit-mode="primary" > - - - + + + + + diff --git a/dms/views/dms_file.xml b/dms/views/dms_file.xml index b2bb6ba9a..48785b1ad 100644 --- a/dms/views/dms_file.xml +++ b/dms/views/dms_file.xml @@ -281,7 +281,7 @@ - o_kanban_mobile + o_kanban_mobile mk_file_kanban_view
diff --git a/dms_attachment_link/README.rst b/dms_attachment_link/README.rst new file mode 100644 index 000000000..a9573e8d6 --- /dev/null +++ b/dms_attachment_link/README.rst @@ -0,0 +1,103 @@ +=================== +Dms Attachment Link +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7d11e23d33bcf0bcc4ec886c80804ce0aa6c270a32ba249fa1f87c425f9c117b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fdms-lightgray.png?logo=github + :target: https://github.com/OCA/dms/tree/17.0/dms_attachment_link + :alt: OCA/dms +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/dms-17-0/dms-17-0-dms_attachment_link + :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/dms&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a wizard to be able to link an DMS file as an +attachment of a document. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Open the form view of a document (Example: the contact "Azure + Interior"). +2. Go to the chatter and click on the clip icon. +3. Click **Add DMS File** link. +4. A popup wizard will appear. +5. Search for the desired DMS file (Example: Sydney.jpg) and click on + the "Add" button. +6. A new attachment will be created for the document without duplicating + the content. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - Pedro M. Baeza + - Víctor Martínez + +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. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/dms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/dms_attachment_link/__init__.py b/dms_attachment_link/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/dms_attachment_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/dms_attachment_link/__manifest__.py b/dms_attachment_link/__manifest__.py new file mode 100644 index 000000000..2df545e42 --- /dev/null +++ b/dms_attachment_link/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Dms Attachment Link", + "version": "17.0.1.0.0", + "category": "Document Management", + "website": "https://github.com/OCA/dms", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["dms"], + "data": [ + "views/dms_file_views.xml", + ], + "assets": { + "web.assets_backend": [ + "dms_attachment_link/static/src/js/dms_attachment_link.esm.js", + "dms_attachment_link/static/src/xml/chatter.xml", + ], + }, + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/dms_attachment_link/i18n/dms_attachment_link.pot b/dms_attachment_link/i18n/dms_attachment_link.pot new file mode 100644 index 000000000..a4f479d45 --- /dev/null +++ b/dms_attachment_link/i18n/dms_attachment_link.pot @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * dms_attachment_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: dms_attachment_link +#: model_terms:ir.ui.view,arch_db:dms_attachment_link.view_dms_file_kanban_wizard_selection +msgid "Add" +msgstr "" + +#. module: dms_attachment_link +#. odoo-javascript +#: code:addons/dms_attachment_link/static/src/xml/chatter.xml:0 +#, python-format +msgid "Add DMS File" +msgstr "" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_ir_attachment +msgid "Attachment" +msgstr "" + +#. module: dms_attachment_link +#: model:ir.model.fields,field_description:dms_attachment_link.field_ir_attachment__dms_file_id +msgid "Dms File" +msgstr "" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_dms_file +msgid "File" +msgstr "" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_ir_binary +msgid "File streaming helper model for controllers" +msgstr "" + +#. module: dms_attachment_link +#: model:ir.actions.act_window,name:dms_attachment_link.action_dms_file_wizard_selector_dms_attachment_link +msgid "Files" +msgstr "" diff --git a/dms_attachment_link/i18n/es.po b/dms_attachment_link/i18n/es.po new file mode 100644 index 000000000..a7207915a --- /dev/null +++ b/dms_attachment_link/i18n/es.po @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * dms_attachment_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-13 07:19+0000\n" +"PO-Revision-Date: 2023-07-28 22:09+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: dms_attachment_link +#: model_terms:ir.ui.view,arch_db:dms_attachment_link.view_dms_file_kanban_wizard_selection +msgid "Add" +msgstr "Añadir" + +#. module: dms_attachment_link +#. openerp-web +#: code:addons/dms_attachment_link/static/src/xml/chatter.xml:0 +#, python-format +msgid "Add DMS File" +msgstr "Añadir archivo DMS" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_ir_attachment +msgid "Attachment" +msgstr "Adjunto" + +#. module: dms_attachment_link +#: model:ir.model.fields,field_description:dms_attachment_link.field_ir_attachment__dms_file_id +msgid "Dms File" +msgstr "Archivo Dms" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_dms_file +msgid "File" +msgstr "Archivo" + +#. module: dms_attachment_link +#: model:ir.actions.act_window,name:dms_attachment_link.action_dms_file_wizard_selector_dms_attachment_link +msgid "Files" +msgstr "Archivos" diff --git a/dms_attachment_link/i18n/it.po b/dms_attachment_link/i18n/it.po new file mode 100644 index 000000000..1590213d2 --- /dev/null +++ b/dms_attachment_link/i18n/it.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * dms_attachment_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-11 09:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: dms_attachment_link +#: model_terms:ir.ui.view,arch_db:dms_attachment_link.view_dms_file_kanban_wizard_selection +msgid "Add" +msgstr "Aggiungi" + +#. module: dms_attachment_link +#. openerp-web +#: code:addons/dms_attachment_link/static/src/xml/chatter.xml:0 +#, python-format +msgid "Add DMS File" +msgstr "Aggiungi file DMS" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_ir_attachment +msgid "Attachment" +msgstr "Allegato" + +#. module: dms_attachment_link +#: model:ir.model.fields,field_description:dms_attachment_link.field_ir_attachment__dms_file_id +msgid "Dms File" +msgstr "File DMS" + +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_dms_file +msgid "File" +msgstr "File" + +#. module: dms_attachment_link +#: model:ir.actions.act_window,name:dms_attachment_link.action_dms_file_wizard_selector_dms_attachment_link +msgid "Files" +msgstr "File" diff --git a/dms_attachment_link/models/__init__.py b/dms_attachment_link/models/__init__.py new file mode 100644 index 000000000..c0811a10f --- /dev/null +++ b/dms_attachment_link/models/__init__.py @@ -0,0 +1,3 @@ +from . import dms_file +from . import ir_attachment +from . import ir_binary diff --git a/dms_attachment_link/models/dms_file.py b/dms_attachment_link/models/dms_file.py new file mode 100644 index 000000000..40360447f --- /dev/null +++ b/dms_attachment_link/models/dms_file.py @@ -0,0 +1,19 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class DmsFile(models.Model): + _inherit = "dms.file" + + def _prepare_ir_attachment_values(self): + return { + "dms_file_id": self.id, + "name": self.name, + "res_model": self.env.context.get("active_model"), + "res_id": self.env.context.get("active_id"), + } + + def action_create_attachment_from_record(self): + return self.env["ir.attachment"].create(self._prepare_ir_attachment_values()) diff --git a/dms_attachment_link/models/ir_attachment.py b/dms_attachment_link/models/ir_attachment.py new file mode 100644 index 000000000..d38fa20d5 --- /dev/null +++ b/dms_attachment_link/models/ir_attachment.py @@ -0,0 +1,19 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class IrAttachment(models.Model): + _inherit = "ir.attachment" + + dms_file_id = fields.Many2one(comodel_name="dms.file") + + @api.depends("dms_file_id", "dms_file_id.content") + def _compute_datas(self): + """Get the contents of the attachment directly from the DMS file.""" + _self = self.filtered("dms_file_id") + res = super(IrAttachment, (self - _self))._compute_datas() + for item in _self: + item.datas = item.dms_file_id.content + return res diff --git a/dms_attachment_link/models/ir_binary.py b/dms_attachment_link/models/ir_binary.py new file mode 100644 index 000000000..1ee687ead --- /dev/null +++ b/dms_attachment_link/models/ir_binary.py @@ -0,0 +1,15 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class IrBinary(models.AbstractModel): + _inherit = "ir.binary" + + def _record_to_stream(self, record, field_name): + """We need to overwrite for the download and preview to be correct.""" + if record._name == "ir.attachment" and record.dms_file_id: + record = record.dms_file_id + field_name = "content" + return super()._record_to_stream(record=record, field_name=field_name) diff --git a/dms_attachment_link/pyproject.toml b/dms_attachment_link/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/dms_attachment_link/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/dms_attachment_link/readme/CONTRIBUTORS.md b/dms_attachment_link/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..00fb40664 --- /dev/null +++ b/dms_attachment_link/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com) + - Pedro M. Baeza + - Víctor Martínez diff --git a/dms_attachment_link/readme/DESCRIPTION.md b/dms_attachment_link/readme/DESCRIPTION.md new file mode 100644 index 000000000..193b9bb23 --- /dev/null +++ b/dms_attachment_link/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds a wizard to be able to link an DMS file as an +attachment of a document. diff --git a/dms_attachment_link/readme/USAGE.md b/dms_attachment_link/readme/USAGE.md new file mode 100644 index 000000000..8f72b5dbf --- /dev/null +++ b/dms_attachment_link/readme/USAGE.md @@ -0,0 +1,11 @@ +To use this module, you need to: + +1. Open the form view of a document (Example: the contact "Azure + Interior"). +2. Go to the chatter and click on the clip icon. +3. Click **Add DMS File** link. +4. A popup wizard will appear. +5. Search for the desired DMS file (Example: Sydney.jpg) and click on + the "Add" button. +6. A new attachment will be created for the document without + duplicating the content. diff --git a/dms_attachment_link/static/description/icon.png b/dms_attachment_link/static/description/icon.png new file mode 100644 index 000000000..667d38d36 Binary files /dev/null and b/dms_attachment_link/static/description/icon.png differ diff --git a/dms_attachment_link/static/description/icon.svg b/dms_attachment_link/static/description/icon.svg new file mode 100644 index 000000000..43344af51 --- /dev/null +++ b/dms_attachment_link/static/description/icon.svg @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dms_attachment_link/static/description/index.html b/dms_attachment_link/static/description/index.html new file mode 100644 index 000000000..e6001a8e7 --- /dev/null +++ b/dms_attachment_link/static/description/index.html @@ -0,0 +1,446 @@ + + + + + +Dms Attachment Link + + + + + + diff --git a/dms_attachment_link/static/src/js/dms_attachment_link.esm.js b/dms_attachment_link/static/src/js/dms_attachment_link.esm.js new file mode 100644 index 000000000..0fc8ab930 --- /dev/null +++ b/dms_attachment_link/static/src/js/dms_attachment_link.esm.js @@ -0,0 +1,33 @@ +/** @odoo-module **/ + +import {Chatter} from "@mail/core/web/chatter"; +import {patch} from "@web/core/utils/patch"; + +patch(Chatter.prototype, { + _onAddDmsFile() { + this.action.doAction( + "dms_attachment_link.action_dms_file_wizard_selector_dms_attachment_link", + { + additionalContext: { + active_id: this.state.thread.id, + active_ids: [this.state.thread.id], + active_model: this.state.thread.model, + }, + onClose: async () => { + await this._onAddedDmsFile(); + }, + } + ); + }, + onClickAddAttachments(ev) { + ev.stopPropagation(); + this.state.isAttachmentBoxOpened = !this.state.isAttachmentBoxOpened; + if (this.state.isAttachmentBoxOpened) { + this.rootRef.el.scrollTop = 0; + this.state.thread.scrollTop = "bottom"; + } + }, + async _onAddedDmsFile() { + this.reloadParentView(); + }, +}); diff --git a/dms_attachment_link/static/src/xml/chatter.xml b/dms_attachment_link/static/src/xml/chatter.xml new file mode 100644 index 000000000..6bd996afa --- /dev/null +++ b/dms_attachment_link/static/src/xml/chatter.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/dms_attachment_link/tests/__init__.py b/dms_attachment_link/tests/__init__.py new file mode 100644 index 000000000..b113345c9 --- /dev/null +++ b/dms_attachment_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_dms_attachment_link diff --git a/dms_attachment_link/tests/test_dms_attachment_link.py b/dms_attachment_link/tests/test_dms_attachment_link.py new file mode 100644 index 000000000..84935eae7 --- /dev/null +++ b/dms_attachment_link/tests/test_dms_attachment_link.py @@ -0,0 +1,20 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.base.tests.common import BaseCommon + + +class TestDmsAttachmentLink(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test partner"}) + cls.dms_file = cls.env.ref("dms.file_01_demo") + + def test_add_url_attachment(self): + attachment = self.dms_file.with_context( + active_model=self.partner._name, + active_id=self.partner.id, + ).action_create_attachment_from_record() + self.assertEqual(attachment.name, self.dms_file.name) + self.assertEqual(attachment.datas, self.dms_file.content) diff --git a/dms_attachment_link/views/dms_file_views.xml b/dms_attachment_link/views/dms_file_views.xml new file mode 100644 index 000000000..d438ba455 --- /dev/null +++ b/dms_attachment_link/views/dms_file_views.xml @@ -0,0 +1,36 @@ + + + + dms_file.kanban.wizard.selection.attachment.link + dms.file + 9999 + primary + + + + + Add + + + + + + Files + dms.file + new + kanban + {'create': False} + + +