diff --git a/base_search_mail_content/README.rst b/base_search_mail_content/README.rst new file mode 100644 index 00000000..5934ec02 --- /dev/null +++ b/base_search_mail_content/README.rst @@ -0,0 +1,88 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================== +Base Search Mail Content +======================== + +This module adds the capability to find on any object (e.g. project issues or +helpdesk ticket) based on the conversation threads associated to them. + +This will be useful in models that make intense use of messages, +like project issues or helpdesk tickets. + +A project issue or helpdesk ticket can contain tens of mails or notes +associated, based on the feedback that the person responsible for the ticket +maintains, including conversations with the person that raised the issue. + +A user may often want to find issues or tickets, based on the past +conversations that were recorded, as much as he/she needs to search +in their mail for past conversations. + +This module will add dynamically a field 'message_content' to the search view of +any model that inherits from the mail.thread. + +The current search capabilities include searching into the subject, body, +email from, reply to and record name. + +Installation +============ + +This module depends on the module 'base_search_fuzzy' to ensure that +searches on emails are based on indexes. Please read carefully the install +instructions: +https://github.com/OCA/server-tools/blob/9.0/base_search_fuzzy/README.rst + +This module installs by default the indexes that are required to +perform the searches on mail messages. + +Usage +===== + +Go to any model that contains a chatter (e.g. Partners, Leads, ...). Search +for content in field 'Message Content'. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/server-tools/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Serpent Consulting Services Pvt. Ltd. +* Lois Rilo Antelo +* Aaron Henriquez + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/base_search_mail_content/__init__.py b/base_search_mail_content/__init__.py new file mode 100644 index 00000000..ae34718d --- /dev/null +++ b/base_search_mail_content/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# © 2016 Serpent Consulting Services Pvt. Ltd. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/base_search_mail_content/__openerp__.py b/base_search_mail_content/__openerp__.py new file mode 100644 index 00000000..db6d9b2d --- /dev/null +++ b/base_search_mail_content/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# © 2016 Serpent Consulting Services Pvt. Ltd. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Base Search Mail Content", + "version": "9.0.1.0.0", + "author": "Eficent," + "SerpentCS," + "Odoo Community Association (OCA)", + "website": "http://www.eficent.com", + "category": "Social", + "data": ["data/trgm_index_data.xml", + "views/trgm_index_view.xml"], + "depends": ["mail", + "base_search_fuzzy"], + "license": "AGPL-3", + 'installable': True, +} diff --git a/base_search_mail_content/data/trgm_index_data.xml b/base_search_mail_content/data/trgm_index_data.xml new file mode 100644 index 00000000..0a84c926 --- /dev/null +++ b/base_search_mail_content/data/trgm_index_data.xml @@ -0,0 +1,36 @@ + + + + + + gin + + + + + gin + + + + + gin + + + + + gin + + + + + gin + + + + + diff --git a/base_search_mail_content/models/__init__.py b/base_search_mail_content/models/__init__.py new file mode 100644 index 00000000..780d0d14 --- /dev/null +++ b/base_search_mail_content/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# © 2016 Serpent Consulting Services Pvt. Ltd. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import mail_thread +from . import res_partner diff --git a/base_search_mail_content/models/mail_thread.py b/base_search_mail_content/models/mail_thread.py new file mode 100644 index 00000000..b8a0f116 --- /dev/null +++ b/base_search_mail_content/models/mail_thread.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# © 2016 Serpent Consulting Services Pvt. Ltd. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models +from lxml import etree +from openerp.osv import expression +from openerp.osv.orm import setup_modifiers + + +class MailThread(models.AbstractModel): + + _inherit = 'mail.thread' + + def _search_message_content(self, operator, value): + + main_operator = 'in' + if operator in expression.NEGATIVE_TERM_OPERATORS: + main_operator = 'not in' + operators = {'!=': '=', 'not like': 'like', + 'not ilike': 'ilike', 'not in': 'in'} + operator = operators[operator] + domain = [('model', '=', self._name), '|', '|', '|', '|', + ('record_name', operator, value), + ('subject', operator, value), ('body', operator, value), + ('email_from', operator, value), + ('reply_to', operator, value)] + recs = self.env['mail.message'].search(domain) + return [('id', main_operator, recs.mapped('res_id'))] + + @api.multi + def _compute_message_content(self): + """ We don't really need to show any content. This field is to be + used only by searches""" + return '' + + message_content = fields.Text( + string='Message Content', + help='Message content, to be used only in searches', + compute="_compute_message_content", + search='_search_message_content') + + +_base_fields_view_get = models.BaseModel.fields_view_get + + +@api.model +def _custom_fields_view_get(self, view_id=None, view_type='form', + toolbar=False, submenu=False): + """ + Override to add message_ids field in all the objects + that inherits mail.thread + """ + # Tricky super call + res = _base_fields_view_get(self, view_id=view_id, view_type=view_type, + toolbar=toolbar, submenu=submenu) + if view_type == 'search' and self._fields.get('message_content'): + doc = etree.XML(res['arch']) + res['fields'].update({ + 'message_content': { + 'type': 'char', + 'string': 'Message content', + } + }) + + for node in doc.xpath("//field[1]"): + # Add message_content in search view + elem = etree.Element('field', { + 'name': 'message_content', + }) + setup_modifiers(elem) + node.addnext(elem) + res['arch'] = etree.tostring(doc) + return res + + +models.BaseModel.fields_view_get = _custom_fields_view_get diff --git a/base_search_mail_content/models/res_partner.py b/base_search_mail_content/models/res_partner.py new file mode 100644 index 00000000..6aa6da6c --- /dev/null +++ b/base_search_mail_content/models/res_partner.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# © 2016 Serpent Consulting Services Pvt. Ltd. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import models + + +class Partner(models.Model): + + _name = 'res.partner' + _inherit = ['res.partner', 'mail.thread'] diff --git a/base_search_mail_content/views/trgm_index_view.xml b/base_search_mail_content/views/trgm_index_view.xml new file mode 100644 index 00000000..304a8365 --- /dev/null +++ b/base_search_mail_content/views/trgm_index_view.xml @@ -0,0 +1,29 @@ + + + + + + trgm.index.view.form + trgm.index + + + + [('ttype', 'in', ['char', 'text', 'html'])] + "You can either select a field of type 'text', 'char' or 'html'." + + + + + + trgm.index.view.tree + trgm.index + + + + "You can either select a field of type 'text', 'char' or 'html'." + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 00000000..9c8c9172 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +server-tools