diff --git a/odex30_base/smile_attachment/README.rst b/odex30_base/smile_attachment/README.rst new file mode 100644 index 0000000..b5e2ad3 --- /dev/null +++ b/odex30_base/smile_attachment/README.rst @@ -0,0 +1,84 @@ +===================== +Search in Attachments +===================== + +.. |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-Smile_SA%2Fodoo_addons-lightgray.png?logo=github + :target: https://github.com/Smile-SA/odoo_addons/tree/14.0/smile_attachment + :alt: Smile-SA/odoo_addons + +|badge2| |badge3| + +This module allows to search in attachments (for all models). It allows you to search, in addition to the file name, on the indexed content of .docx, .xlsx, .pptx, .odt, .ods documents. + +Features: + +* Users can search in attachments from the search bar of the current model. +* Users can search by using a keyword from the name or the content of attachments. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +If you have a document inserted in your model, and you want to search for it: + +#. Go to the ``Search bar``; +#. Type a keyword from the document's name or content; +#. Select ``Search Attachments for:``; +#. The record containing the document will be displayed. + +.. figure:: static/description/search_in_attachments.png + :alt: Search in attachments + :width: 900px + +.. figure:: static/description/search_in_attachments_result.png + :alt: Search in attachments result + :width: 900px + +.. figure:: static/description/search_in_attachments_doc.png + :alt: Search in attachments document + :width: 900px + +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 smashing it by providing a detailed and welcomed feedback +`here `_. + +Do not contact contributors directly about support or help with technical issues. + +GDPR / EU Privacy +================= + +This addons does not collect any data and does not set any browser cookies. + +Credits +======= + +Contributors +------------ + +* Corentin POUHET-BRUNERIE + +Maintainer +---------- + +This module is maintained by Smile SA. + +Since 1991 Smile has been a pioneer of technology and also the European expert in open source solutions. + +.. image:: https://avatars0.githubusercontent.com/u/572339?s=200&v=4 + :alt: Smile SA + :target: http://smile.fr + +This module is part of the `odoo-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/odex30_base/smile_attachment/__init__.py b/odex30_base/smile_attachment/__init__.py new file mode 100644 index 0000000..dbf69d6 --- /dev/null +++ b/odex30_base/smile_attachment/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (C) 2019 Smile () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/odex30_base/smile_attachment/__manifest__.py b/odex30_base/smile_attachment/__manifest__.py new file mode 100644 index 0000000..21b2303 --- /dev/null +++ b/odex30_base/smile_attachment/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# (C) 2019 Smile () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Search in attachments", + "version": "18.0.1.0.0", + "sequence": 100, + "category": "Odex30-base", + "author": "Smile", + "license": 'LGPL-3', + "website": 'http://www.smile.fr', + "description": "", + "depends": ["attachment_indexation"], + "data": [], + 'installable': True, + 'auto_install': True, + 'application': False, +} diff --git a/odex30_base/smile_attachment/models/__init__.py b/odex30_base/smile_attachment/models/__init__.py new file mode 100644 index 0000000..98d20b8 --- /dev/null +++ b/odex30_base/smile_attachment/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# (C) 2019 Smile () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import base +from . import ir_attachment diff --git a/odex30_base/smile_attachment/models/base.py b/odex30_base/smile_attachment/models/base.py new file mode 100644 index 0000000..a376deb --- /dev/null +++ b/odex30_base/smile_attachment/models/base.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# (C) 2019 Smile () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +# flake8: noqa +# do not check flake8 because of F811 error +from lxml import etree + +from odoo import api, fields, models + + +class Base(models.AbstractModel): + _inherit = "base" + + def _get_attachments_field_name(self): + name = 'attachment_ids' + if self._inherits: + name = 'attachment_%s_ids' % self._table + return name + + @api.depends() + def _get_attachments(self): + for record in self: + name = record._get_attachments_field_name() + setattr(record, name, False) + + def _search_attachments(self, operator, value): + + attachments = self.env['ir.attachment'].search([ + ('res_model', '=', self._name), + ('name', operator, value) + ]) + + if not attachments: + return [('id', '=', 0)] + + return [('id', 'in', attachments.mapped('res_id'))] + + @api.model + def _setup_fields(self): + name = self._get_attachments_field_name() + if name not in self._fields and \ + not self._abstract and not self._transient: + new_field = fields.One2many( + 'ir.attachment', string='Attachments', + compute='_get_attachments', search='_search_attachments') + setattr(type(self), name, new_field) + self._add_field(name, new_field) + super(Base, self)._setup_fields() + + @api.model + def fields_view_get(self, view_id=None, view_type='form', + toolbar=False, submenu=False): + res = super(Base, self).fields_view_get( + view_id=view_id, view_type=view_type, + toolbar=toolbar, submenu=submenu) + if view_type == 'search' and \ + hasattr(self, '_get_attachments_field_name'): + name = self._get_attachments_field_name() + if name in self._fields: + View = self.env['ir.ui.view'] + arch_etree = etree.fromstring(res['arch']) + element = etree.Element('field', name=name) + arch_etree.insert(-1, element) + res['arch'], res['fields'] = View.postprocess_and_fields(arch_etree, self._name) + return res + + @api.model + def fields_get(self, allfields=None, attributes=None): + res = super(Base, self).fields_get(allfields, attributes) + if hasattr(self, '_get_attachments_field_name') and \ + (not allfields or 'attachment_ids' in allfields): + name = self._get_attachments_field_name() + if name in res: + res[name]['string'] = 'Attachments' + return res + diff --git a/odex30_base/smile_attachment/models/ir_attachment.py b/odex30_base/smile_attachment/models/ir_attachment.py new file mode 100644 index 0000000..907996c --- /dev/null +++ b/odex30_base/smile_attachment/models/ir_attachment.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# (C) 2019 Smile () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + res_model = fields.Char(index=True) + res_field = fields.Char(index=True) + res_id = fields.Many2oneReference(index=True) diff --git a/odex30_base/smile_attachment/static/description/icon.png b/odex30_base/smile_attachment/static/description/icon.png new file mode 100644 index 0000000..17984e2 Binary files /dev/null and b/odex30_base/smile_attachment/static/description/icon.png differ diff --git a/odex30_base/smile_attachment/static/description/index.html b/odex30_base/smile_attachment/static/description/index.html new file mode 100644 index 0000000..e332d28 --- /dev/null +++ b/odex30_base/smile_attachment/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Search in Attachments + + + +
+

Search in Attachments

+ +

License: AGPL-3 Smile-SA/odoo_addons

+

This module allows to search in attachments (for all models). It allows you to search, in addition to the file name, on the indexed content of .docx, .xlsx, .pptx, .odt, .ods documents.

+

Features:

+
    +
  • Users can search in attachments from the search bar of the current model.
  • +
  • Users can search by using a keyword from the name or the content of attachments.
  • +
+

Table of contents

+ +
+

Usage

+

If you have a document inserted in your model, and you want to search for it:

+
    +
  1. Go to the Search bar;
  2. +
  3. Type a keyword from the document's name or content;
  4. +
  5. Select Search Attachments for:;
  6. +
  7. The record containing the document will be displayed.
  8. +
+
+Search in attachments +
+
+Search in attachments result +
+
+Search in attachments document +
+
+
+

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 smashing it by providing a detailed and welcomed feedback +here.

+

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

+
+
+

GDPR / EU Privacy

+

This addons does not collect any data and does not set any browser cookies.

+
+
+

Credits

+
+

Contributors

+
    +
  • Corentin POUHET-BRUNERIE
  • +
+
+
+

Maintainer

+

This module is maintained by Smile SA.

+

Since 1991 Smile has been a pioneer of technology and also the European expert in open source solutions.

+Smile SA +

This module is part of the odoo-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/odex30_base/smile_attachment/static/description/search_in_attachments.png b/odex30_base/smile_attachment/static/description/search_in_attachments.png new file mode 100644 index 0000000..9401a3c Binary files /dev/null and b/odex30_base/smile_attachment/static/description/search_in_attachments.png differ diff --git a/odex30_base/smile_attachment/static/description/search_in_attachments_doc.png b/odex30_base/smile_attachment/static/description/search_in_attachments_doc.png new file mode 100644 index 0000000..891b95b Binary files /dev/null and b/odex30_base/smile_attachment/static/description/search_in_attachments_doc.png differ diff --git a/odex30_base/smile_attachment/static/description/search_in_attachments_result.png b/odex30_base/smile_attachment/static/description/search_in_attachments_result.png new file mode 100644 index 0000000..ba2a00a Binary files /dev/null and b/odex30_base/smile_attachment/static/description/search_in_attachments_result.png differ