From 070f459f9bc77221ab6470fb655ed36e724cd271 Mon Sep 17 00:00:00 2001 From: Serpentcs Date: Fri, 30 Dec 2016 14:53:38 +0530 Subject: [PATCH 1/9] [ADD] dynamically added message_ids in search view --- mail_message_name_search/README.rst | 83 +++++++++++++++++++ mail_message_name_search/README.rst~ | 83 +++++++++++++++++++ mail_message_name_search/__init__.py | 7 ++ mail_message_name_search/__openerp__.py | 20 +++++ .../data/trgm_index_data.xml | 24 ++++++ mail_message_name_search/models/__init__.py | 7 ++ .../models/mail_message.py | 54 ++++++++++++ 7 files changed, 278 insertions(+) create mode 100644 mail_message_name_search/README.rst create mode 100644 mail_message_name_search/README.rst~ create mode 100644 mail_message_name_search/__init__.py create mode 100644 mail_message_name_search/__openerp__.py create mode 100644 mail_message_name_search/data/trgm_index_data.xml create mode 100644 mail_message_name_search/models/__init__.py create mode 100644 mail_message_name_search/models/mail_message.py diff --git a/mail_message_name_search/README.rst b/mail_message_name_search/README.rst new file mode 100644 index 00000000..ae473a84 --- /dev/null +++ b/mail_message_name_search/README.rst @@ -0,0 +1,83 @@ +.. 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 + +======================== +Mail message name search +======================== + +This module adds the capability to search for mail messages by subject or +body of the message. This will be useful in models that make intense use of +messages, like project issues or helpdesk tickets. + +This module will add dynamically the message_ids to the search view of +any model that inherits from the mail.thread and will incorporate the +capability to search for content in the mail messages. + + +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/8.0/base_search_fuzzy/README.rst + +This module installs by default the indexes that are required to +perform the searches on mail messages. + + +Configuration +============= + +No configuration is needed. + +Usage +===== + +A project issue or helpdesk ticket can contain tens of mails associated, +based on the conversations that the person responsible for the ticket +maintains with the person that raised the issue. One need to search +in mail messages, as much as he/she needs to search in their mail for +past conversations. So this module will be useful for the user to search +messages by subject or body. + +.. 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. + +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/mail_message_name_search/README.rst~ b/mail_message_name_search/README.rst~ new file mode 100644 index 00000000..92364995 --- /dev/null +++ b/mail_message_name_search/README.rst~ @@ -0,0 +1,83 @@ +.. 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 + +======================== +Mail message name search +======================== + +This module adds the capability to search for mail messages by subject or +body of the message. This will be useful in models that make intense use of +messages, like project issues or helpdesk tickets. + +This module will add dynamically the message_ids to the search view of +any model that inherits from the mail.thread and will incorporate the +capability to search for content in the mail messages. + + +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/8.0/base_search_fuzzy/README.rst + +This module installs by default the indexes that are required to +perform the searches on mail messages. + + +Configuration +============= + +No configuration is needed. + +Usage +===== + +A project issue or helpdesk ticket can contain tens of mails associated, +based on the conversations that the person responsible for the ticket +maintains with the person that raised the issue. One need to search +in mail messages, as much as he/she needs to search in their mail for +past conversations. So this module will be useful for the user to search +messages by subject or body. + +.. 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/8.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. + +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/mail_message_name_search/__init__.py b/mail_message_name_search/__init__.py new file mode 100644 index 00000000..ae34718d --- /dev/null +++ b/mail_message_name_search/__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/mail_message_name_search/__openerp__.py b/mail_message_name_search/__openerp__.py new file mode 100644 index 00000000..279cccaa --- /dev/null +++ b/mail_message_name_search/__openerp__.py @@ -0,0 +1,20 @@ +# -*- 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": "Mail message name search", + "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"], + "depends": ["mail", + "base_search_fuzzy"], + "license": "AGPL-3", + 'installable': True, +} diff --git a/mail_message_name_search/data/trgm_index_data.xml b/mail_message_name_search/data/trgm_index_data.xml new file mode 100644 index 00000000..b60b0666 --- /dev/null +++ b/mail_message_name_search/data/trgm_index_data.xml @@ -0,0 +1,24 @@ + + + + + + gin + + + + + gin + + + + + gin + + + + + diff --git a/mail_message_name_search/models/__init__.py b/mail_message_name_search/models/__init__.py new file mode 100644 index 00000000..0b53dd7c --- /dev/null +++ b/mail_message_name_search/models/__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 mail_message diff --git a/mail_message_name_search/models/mail_message.py b/mail_message_name_search/models/mail_message.py new file mode 100644 index 00000000..2de2cb3a --- /dev/null +++ b/mail_message_name_search/models/mail_message.py @@ -0,0 +1,54 @@ +# -*- 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, models +from lxml import etree +from openerp.osv import expression + + +_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): + # 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_ids'): + doc = etree.XML(res['arch']) + for node in doc.xpath("//field[1]"): + elem = etree.Element('field', { + 'name': 'message_ids', + 'domain': "[('model','=', %s)]" % self._model + }) + node.addnext(elem) + res['fields'].update({ + 'message_ids': { + 'type': 'many2one', + 'relation': 'mail.message', + 'string': 'Messages', + } + }) + res['arch'] = etree.tostring(doc) + return res + +models.BaseModel.fields_view_get = _custom_fields_view_get + + +class MailMessage(models.Model): + + _inherit = 'mail.message' + + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + args = args or [] + domain = ['|', '|', ('record_name', operator, name), + ('subject', operator, name), ('body', operator, name)] + if operator in expression.NEGATIVE_TERM_OPERATORS: + domain = domain[2:] + rec = self.search(domain + args, limit=limit) + return rec.name_get() From a4404e78a22b6b7d8c60e7be7beb973760b62aaa Mon Sep 17 00:00:00 2001 From: Serpentcs Date: Fri, 30 Dec 2016 16:29:22 +0530 Subject: [PATCH 2/9] [ADD] Added oca dependencies --- mail_message_name_search/models/mail_message.py | 4 ++-- oca_dependencies.txt | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 oca_dependencies.txt diff --git a/mail_message_name_search/models/mail_message.py b/mail_message_name_search/models/mail_message.py index 2de2cb3a..bfdacd39 100644 --- a/mail_message_name_search/models/mail_message.py +++ b/mail_message_name_search/models/mail_message.py @@ -31,8 +31,8 @@ def _custom_fields_view_get(self, view_id=None, view_type='form', 'type': 'many2one', 'relation': 'mail.message', 'string': 'Messages', - } - }) + } + }) res['arch'] = etree.tostring(doc) return res diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 00000000..4947496f --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1,7 @@ +crm +stock-logistics-workflow +stock-logistics-transport +account-closing +bank-statement-reconcile +server-tools +project From 38ac18c8538d64fdecb3ada65c62a528c135618d Mon Sep 17 00:00:00 2001 From: Serpentcs Date: Fri, 30 Dec 2016 17:01:34 +0530 Subject: [PATCH 3/9] [FIX] travis --- mail_message_name_search/models/mail_message.py | 1 + oca_dependencies.txt | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/mail_message_name_search/models/mail_message.py b/mail_message_name_search/models/mail_message.py index bfdacd39..0c7f6a47 100644 --- a/mail_message_name_search/models/mail_message.py +++ b/mail_message_name_search/models/mail_message.py @@ -36,6 +36,7 @@ def _custom_fields_view_get(self, view_id=None, view_type='form', res['arch'] = etree.tostring(doc) return res + models.BaseModel.fields_view_get = _custom_fields_view_get diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 4947496f..9c8c9172 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,7 +1 @@ -crm -stock-logistics-workflow -stock-logistics-transport -account-closing -bank-statement-reconcile server-tools -project From a389eb63d6b55055454203f2e8466f1ad0afd3a7 Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Fri, 30 Dec 2016 18:43:13 +0530 Subject: [PATCH 4/9] [FIX] proper reference --- mail_message_name_search/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail_message_name_search/README.rst b/mail_message_name_search/README.rst index ae473a84..5d7d37d5 100644 --- a/mail_message_name_search/README.rst +++ b/mail_message_name_search/README.rst @@ -20,7 +20,7 @@ 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/8.0/base_search_fuzzy/README.rst +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. From b879bcb78186b57c9c8a1beb5a5e87eb078f5fe1 Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Mon, 2 Jan 2017 16:16:39 +0530 Subject: [PATCH 5/9] [FIX] field type --- mail_message_name_search/models/mail_message.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mail_message_name_search/models/mail_message.py b/mail_message_name_search/models/mail_message.py index 0c7f6a47..0250e427 100644 --- a/mail_message_name_search/models/mail_message.py +++ b/mail_message_name_search/models/mail_message.py @@ -15,20 +15,26 @@ _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_ids'): doc = etree.XML(res['arch']) for node in doc.xpath("//field[1]"): + # Add message_ids in search view elem = etree.Element('field', { 'name': 'message_ids', 'domain': "[('model','=', %s)]" % self._model }) node.addnext(elem) + # Register message_ids in fields res['fields'].update({ 'message_ids': { - 'type': 'many2one', + 'type': 'one2many', 'relation': 'mail.message', 'string': 'Messages', } @@ -46,6 +52,7 @@ class MailMessage(models.Model): @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): + """Override to search on multiple fields""" args = args or [] domain = ['|', '|', ('record_name', operator, name), ('subject', operator, name), ('body', operator, name)] From a082d1f71b44b32089b5cf44d6636a2ff14cc8a2 Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Wed, 4 Jan 2017 17:54:23 +0530 Subject: [PATCH 6/9] [IMP] new field to perform search --- mail_message_name_search/models/__init__.py | 1 + .../models/mail_message.py | 67 +++++++++++-------- .../models/res_partner.py | 13 ++++ 3 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 mail_message_name_search/models/res_partner.py diff --git a/mail_message_name_search/models/__init__.py b/mail_message_name_search/models/__init__.py index 0b53dd7c..ee15c669 100644 --- a/mail_message_name_search/models/__init__.py +++ b/mail_message_name_search/models/__init__.py @@ -5,3 +5,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import mail_message +from . import res_partner diff --git a/mail_message_name_search/models/mail_message.py b/mail_message_name_search/models/mail_message.py index 0250e427..0c8ca94b 100644 --- a/mail_message_name_search/models/mail_message.py +++ b/mail_message_name_search/models/mail_message.py @@ -4,9 +4,37 @@ # © 2016 Serpent Consulting Services Pvt. Ltd. () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, models +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): + domain = [('model', '=', self._name), '|', '|', + ('record_name', operator, value), + ('subject', operator, value), ('body', operator, value)] + + if operator in expression.NEGATIVE_TERM_OPERATORS: + domain = domain[2:] + recs = self.env['mail.message'].search(domain) + return [('id', 'in', 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='Messages', + 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 @@ -22,41 +50,24 @@ def _custom_fields_view_get(self, view_id=None, view_type='form', # 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_ids'): + 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_ids in search view elem = etree.Element('field', { - 'name': 'message_ids', - 'domain': "[('model','=', %s)]" % self._model + 'name': 'message_content', }) + setup_modifiers(elem) node.addnext(elem) - # Register message_ids in fields - res['fields'].update({ - 'message_ids': { - 'type': 'one2many', - 'relation': 'mail.message', - 'string': 'Messages', - } - }) res['arch'] = etree.tostring(doc) return res models.BaseModel.fields_view_get = _custom_fields_view_get - - -class MailMessage(models.Model): - - _inherit = 'mail.message' - - @api.model - def name_search(self, name='', args=None, operator='ilike', limit=100): - """Override to search on multiple fields""" - args = args or [] - domain = ['|', '|', ('record_name', operator, name), - ('subject', operator, name), ('body', operator, name)] - if operator in expression.NEGATIVE_TERM_OPERATORS: - domain = domain[2:] - rec = self.search(domain + args, limit=limit) - return rec.name_get() diff --git a/mail_message_name_search/models/res_partner.py b/mail_message_name_search/models/res_partner.py new file mode 100644 index 00000000..6aa6da6c --- /dev/null +++ b/mail_message_name_search/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'] From 957714146c9f465fa3264d05d74fcba3861f3d5c Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Tue, 10 Jan 2017 14:50:26 +0530 Subject: [PATCH 7/9] [ADD] renamed module to base_search_mail_content --- .../README.rst | 0 .../__init__.py | 0 .../__openerp__.py | 0 .../data/trgm_index_data.xml | 0 .../models/__init__.py | 2 +- .../models/mail_thread.py | 0 .../models/res_partner.py | 0 mail_message_name_search/README.rst~ | 83 ------------------- 8 files changed, 1 insertion(+), 84 deletions(-) rename {mail_message_name_search => base_search_mail_content}/README.rst (100%) rename {mail_message_name_search => base_search_mail_content}/__init__.py (100%) rename {mail_message_name_search => base_search_mail_content}/__openerp__.py (100%) rename {mail_message_name_search => base_search_mail_content}/data/trgm_index_data.xml (100%) rename {mail_message_name_search => base_search_mail_content}/models/__init__.py (91%) rename mail_message_name_search/models/mail_message.py => base_search_mail_content/models/mail_thread.py (100%) rename {mail_message_name_search => base_search_mail_content}/models/res_partner.py (100%) delete mode 100644 mail_message_name_search/README.rst~ diff --git a/mail_message_name_search/README.rst b/base_search_mail_content/README.rst similarity index 100% rename from mail_message_name_search/README.rst rename to base_search_mail_content/README.rst diff --git a/mail_message_name_search/__init__.py b/base_search_mail_content/__init__.py similarity index 100% rename from mail_message_name_search/__init__.py rename to base_search_mail_content/__init__.py diff --git a/mail_message_name_search/__openerp__.py b/base_search_mail_content/__openerp__.py similarity index 100% rename from mail_message_name_search/__openerp__.py rename to base_search_mail_content/__openerp__.py diff --git a/mail_message_name_search/data/trgm_index_data.xml b/base_search_mail_content/data/trgm_index_data.xml similarity index 100% rename from mail_message_name_search/data/trgm_index_data.xml rename to base_search_mail_content/data/trgm_index_data.xml diff --git a/mail_message_name_search/models/__init__.py b/base_search_mail_content/models/__init__.py similarity index 91% rename from mail_message_name_search/models/__init__.py rename to base_search_mail_content/models/__init__.py index ee15c669..780d0d14 100644 --- a/mail_message_name_search/models/__init__.py +++ b/base_search_mail_content/models/__init__.py @@ -4,5 +4,5 @@ # © 2016 Serpent Consulting Services Pvt. Ltd. () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from . import mail_message +from . import mail_thread from . import res_partner diff --git a/mail_message_name_search/models/mail_message.py b/base_search_mail_content/models/mail_thread.py similarity index 100% rename from mail_message_name_search/models/mail_message.py rename to base_search_mail_content/models/mail_thread.py diff --git a/mail_message_name_search/models/res_partner.py b/base_search_mail_content/models/res_partner.py similarity index 100% rename from mail_message_name_search/models/res_partner.py rename to base_search_mail_content/models/res_partner.py diff --git a/mail_message_name_search/README.rst~ b/mail_message_name_search/README.rst~ deleted file mode 100644 index 92364995..00000000 --- a/mail_message_name_search/README.rst~ +++ /dev/null @@ -1,83 +0,0 @@ -.. 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 - -======================== -Mail message name search -======================== - -This module adds the capability to search for mail messages by subject or -body of the message. This will be useful in models that make intense use of -messages, like project issues or helpdesk tickets. - -This module will add dynamically the message_ids to the search view of -any model that inherits from the mail.thread and will incorporate the -capability to search for content in the mail messages. - - -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/8.0/base_search_fuzzy/README.rst - -This module installs by default the indexes that are required to -perform the searches on mail messages. - - -Configuration -============= - -No configuration is needed. - -Usage -===== - -A project issue or helpdesk ticket can contain tens of mails associated, -based on the conversations that the person responsible for the ticket -maintains with the person that raised the issue. One need to search -in mail messages, as much as he/she needs to search in their mail for -past conversations. So this module will be useful for the user to search -messages by subject or body. - -.. 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/8.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. - -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. From fba0d9a189c16f08402c4c04b013c990c32724ca Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 10 Jan 2017 12:37:11 +0100 Subject: [PATCH 8/9] [IMP] search by email_from and reply_to Introduce search of html fields Create indexes Update Readme --- base_search_mail_content/README.rst | 45 ++++++++++--------- base_search_mail_content/__openerp__.py | 5 ++- .../data/trgm_index_data.xml | 12 +++++ .../models/mail_thread.py | 6 ++- .../views/trgm_index_view.xml | 17 +++++++ 5 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 base_search_mail_content/views/trgm_index_view.xml diff --git a/base_search_mail_content/README.rst b/base_search_mail_content/README.rst index 5d7d37d5..dfa436c9 100644 --- a/base_search_mail_content/README.rst +++ b/base_search_mail_content/README.rst @@ -3,43 +3,45 @@ :alt: License: AGPL-3 ======================== -Mail message name search +Base Search Mail Content ======================== -This module adds the capability to search for mail messages by subject or -body of the message. This will be useful in models that make intense use of -messages, like project issues or helpdesk tickets. +This module adds the capability to find any object (e.g. project issues or +helpdesk ticket) based on the conversation threads associated to them. -This module will add dynamically the message_ids to the search view of -any model that inherits from the mail.thread and will incorporate the -capability to search for content in the mail messages. +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 +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. - -Configuration -============= - -No configuration is needed. - Usage ===== -A project issue or helpdesk ticket can contain tens of mails associated, -based on the conversations that the person responsible for the ticket -maintains with the person that raised the issue. One need to search -in mail messages, as much as he/she needs to search in their mail for -past conversations. So this module will be useful for the user to search -messages by subject or body. +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 @@ -66,6 +68,9 @@ Contributors * Jordi Ballester Alomar * Serpent Consulting Services Pvt. Ltd. +* Lois Rilo Antelo +* Aaron Henriquez + Maintainer ---------- diff --git a/base_search_mail_content/__openerp__.py b/base_search_mail_content/__openerp__.py index 279cccaa..4da3ff28 100644 --- a/base_search_mail_content/__openerp__.py +++ b/base_search_mail_content/__openerp__.py @@ -5,14 +5,15 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { - "name": "Mail message name search", + "name": "Base Mail Search 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"], + "data": ["data/trgm_index_data.xml", + "views/trgm_index_view.xml"], "depends": ["mail", "base_search_fuzzy"], "license": "AGPL-3", diff --git a/base_search_mail_content/data/trgm_index_data.xml b/base_search_mail_content/data/trgm_index_data.xml index b60b0666..0a84c926 100644 --- a/base_search_mail_content/data/trgm_index_data.xml +++ b/base_search_mail_content/data/trgm_index_data.xml @@ -20,5 +20,17 @@ search="[('model','=','mail.message'),('name','=','record_name')]"/> + + gin + + + + + gin + + + diff --git a/base_search_mail_content/models/mail_thread.py b/base_search_mail_content/models/mail_thread.py index 0c8ca94b..90e8efe1 100644 --- a/base_search_mail_content/models/mail_thread.py +++ b/base_search_mail_content/models/mail_thread.py @@ -15,9 +15,11 @@ class MailThread(models.AbstractModel): _inherit = 'mail.thread' def _search_message_content(self, operator, value): - domain = [('model', '=', self._name), '|', '|', + domain = [('model', '=', self._name), '|', '|', '|', '|', ('record_name', operator, value), - ('subject', operator, value), ('body', operator, value)] + ('subject', operator, value), ('body', operator, value), + ('email_from', operator, value), + ('reply_to', operator, value)] if operator in expression.NEGATIVE_TERM_OPERATORS: domain = domain[2:] 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..2534f649 --- /dev/null +++ b/base_search_mail_content/views/trgm_index_view.xml @@ -0,0 +1,17 @@ + + + + + + trgm.index.view.form + trgm.index + + + + [('ttype', 'in', ['char', 'text', 'html'])] + + + + + + From 22064be4dd86cf9d47c5e54de9671ca6d4332945 Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Tue, 17 Jan 2017 12:26:51 +0530 Subject: [PATCH 9/9] [IMP] advanced search for negative expression --- base_search_mail_content/README.rst | 2 +- base_search_mail_content/__openerp__.py | 2 +- base_search_mail_content/models/mail_thread.py | 16 ++++++++++------ .../views/trgm_index_view.xml | 12 ++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/base_search_mail_content/README.rst b/base_search_mail_content/README.rst index dfa436c9..5934ec02 100644 --- a/base_search_mail_content/README.rst +++ b/base_search_mail_content/README.rst @@ -6,7 +6,7 @@ Base Search Mail Content ======================== -This module adds the capability to find any object (e.g. project issues or +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, diff --git a/base_search_mail_content/__openerp__.py b/base_search_mail_content/__openerp__.py index 4da3ff28..db6d9b2d 100644 --- a/base_search_mail_content/__openerp__.py +++ b/base_search_mail_content/__openerp__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { - "name": "Base Mail Search Content", + "name": "Base Search Mail Content", "version": "9.0.1.0.0", "author": "Eficent," "SerpentCS," diff --git a/base_search_mail_content/models/mail_thread.py b/base_search_mail_content/models/mail_thread.py index 90e8efe1..b8a0f116 100644 --- a/base_search_mail_content/models/mail_thread.py +++ b/base_search_mail_content/models/mail_thread.py @@ -15,16 +15,20 @@ 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)] - - if operator in expression.NEGATIVE_TERM_OPERATORS: - domain = domain[2:] recs = self.env['mail.message'].search(domain) - return [('id', 'in', recs.mapped('res_id'))] + return [('id', main_operator, recs.mapped('res_id'))] @api.multi def _compute_message_content(self): @@ -33,7 +37,7 @@ class MailThread(models.AbstractModel): return '' message_content = fields.Text( - string='Messages', + string='Message Content', help='Message content, to be used only in searches', compute="_compute_message_content", search='_search_message_content') @@ -62,7 +66,7 @@ def _custom_fields_view_get(self, view_id=None, view_type='form', }) for node in doc.xpath("//field[1]"): - # Add message_ids in search view + # Add message_content in search view elem = etree.Element('field', { 'name': 'message_content', }) diff --git a/base_search_mail_content/views/trgm_index_view.xml b/base_search_mail_content/views/trgm_index_view.xml index 2534f649..304a8365 100644 --- a/base_search_mail_content/views/trgm_index_view.xml +++ b/base_search_mail_content/views/trgm_index_view.xml @@ -9,6 +9,18 @@ [('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'."