[MIG] base_search_mail_content: Migration to 10.0

This commit is contained in:
mreficent 2017-07-10 13:28:35 +02:00 committed by Eduardo De Miguel
parent de8e9a20b1
commit fcf2fc696f
11 changed files with 127 additions and 124 deletions

View File

@ -17,7 +17,7 @@ associated, based on the feedback that the person responsible for the ticket
maintains, including conversations with the person that raised the issue. maintains, including conversations with the person that raised the issue.
A user may often want to find issues or tickets, based on the past 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 conversations that were recorded, as much as he or she needs to search
in their mail for past conversations. in their mail for past conversations.
This module will add dynamically a field 'message_content' to the search view of This module will add dynamically a field 'message_content' to the search view of
@ -30,9 +30,8 @@ Installation
============ ============
This module depends on the module 'base_search_fuzzy' to ensure that This module depends on the module 'base_search_fuzzy' to ensure that
searches on emails are based on indexes. Please read carefully the install searches on emails are based on indexes. Please read carefully the
instructions: `install instructions <https://github.com/OCA/server-tools/blob/10.0/base_search_fuzzy/README.rst>`_.
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 This module installs by default the indexes that are required to
perform the searches on mail messages. perform the searches on mail messages.
@ -40,12 +39,12 @@ perform the searches on mail messages.
Usage Usage
===== =====
Go to any model that contains a chatter (e.g. Partners, Leads, ...). Search Go to any model that contains a chatter (e.g. Contacts, ...). Search
for content in field 'Message Content'. for content in field 'Message Content'.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/server-tools/9.0 :target: https://runbot.odoo-community.org/runbot/server-tools/10.0
Bug Tracker Bug Tracker
=========== ===========
@ -71,7 +70,6 @@ Contributors
* Lois Rilo Antelo <lois.rilo@eficent.com> * Lois Rilo Antelo <lois.rilo@eficent.com>
* Aaron Henriquez <ahenriquez@eficent.com> * Aaron Henriquez <ahenriquez@eficent.com>
Maintainer Maintainer
---------- ----------

View File

@ -6,16 +6,15 @@
{ {
"name": "Base Search Mail Content", "name": "Base Search Mail Content",
"version": "9.0.1.0.0", "version": "10.0.1.0.0",
"author": "Eficent," "author": "Eficent,"
"SerpentCS," "SerpentCS,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"website": "http://www.eficent.com", "website": "https://github.com/OCA/social",
"category": "Social", "category": "Social",
"data": ["data/trgm_index_data.xml", "data": ["data/trgm_index_data.xml",
"views/trgm_index_view.xml"], "views/trgm_index_view.xml"],
"depends": ["mail", "depends": ["mail", "base_search_fuzzy"],
"base_search_fuzzy"],
"license": "AGPL-3", "license": "AGPL-3",
'installable': True, 'installable': True,
} }

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <odoo noupdate="1">
<data noupdate="1">
<record id="subject_gin_idx" model="trgm.index"> <record id="subject_gin_idx" model="trgm.index">
<field name="index_type">gin</field> <field name="index_type">gin</field>
@ -32,5 +31,4 @@
search="[('model','=','mail.message'),('name','=','reply_to')]"/> search="[('model','=','mail.message'),('name','=','reply_to')]"/>
</record> </record>
</data> </odoo>
</openerp>

View File

@ -3,15 +3,14 @@
# * base_search_mail_content # * base_search_mail_content
# #
# Translators: # Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017 # enjolras <yo@miguelrevilla.com>, 2018
# Pedro M. Baeza <pedro.baeza@gmail.com>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n" "Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-28 08:19+0000\n" "POT-Creation-Date: 2018-02-26 01:46+0000\n"
"PO-Revision-Date: 2017-03-28 08:19+0000\n" "PO-Revision-Date: 2018-02-26 01:46+0000\n"
"Last-Translator: Pedro M. Baeza <pedro.baeza@gmail.com>, 2017\n" "Last-Translator: enjolras <yo@miguelrevilla.com>, 2018\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" "Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -23,26 +22,35 @@ msgstr ""
#: model:ir.ui.view,arch_db:base_search_mail_content.trgm_index_view_form #: model:ir.ui.view,arch_db:base_search_mail_content.trgm_index_view_form
#: model:ir.ui.view,arch_db:base_search_mail_content.trgm_index_view_tree #: model:ir.ui.view,arch_db:base_search_mail_content.trgm_index_view_tree
msgid "\"You can either select a field of type 'text', 'char' or 'html'.\"" msgid "\"You can either select a field of type 'text', 'char' or 'html'.\""
msgstr "\"Puede seleccionar un campo de tipo 'text', 'char' o 'html'.\"" msgstr "\"Puede elegir un campo de tipo 'text', 'char' o 'html'.\""
#. module: base_search_mail_content #. module: base_search_mail_content
#: model:ir.model,name:base_search_mail_content.model_mail_thread #: model:ir.model,name:base_search_mail_content.model_mail_thread
msgid "Email Thread" msgid "Email Thread"
msgstr "Hilo correo electrónico" msgstr "Hilo de email"
#. module: base_search_mail_content #. module: base_search_mail_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_event_event_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_event_registration_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_mail_channel_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_mail_mass_mailing_contact_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_mail_test_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_mail_thread_message_content #: model:ir.model.fields,field_description:base_search_mail_content.field_mail_thread_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_mail_unsubscription_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_res_partner_message_content #: model:ir.model.fields,field_description:base_search_mail_content.field_res_partner_message_content
#: model:ir.model.fields,field_description:base_search_mail_content.field_res_users_message_content
msgid "Message Content" msgid "Message Content"
msgstr "Contenido del mensaje" msgstr "Contenido del mensaje"
#. module: base_search_mail_content #. module: base_search_mail_content
#: model:ir.model.fields,help:base_search_mail_content.field_event_event_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_event_registration_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_mail_channel_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_mail_mass_mailing_contact_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_mail_test_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_mail_thread_message_content #: model:ir.model.fields,help:base_search_mail_content.field_mail_thread_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_mail_unsubscription_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_res_partner_message_content #: model:ir.model.fields,help:base_search_mail_content.field_res_partner_message_content
#: model:ir.model.fields,help:base_search_mail_content.field_res_users_message_content
msgid "Message content, to be used only in searches" msgid "Message content, to be used only in searches"
msgstr "Contenido del mensaje, para ser usado sólo en búsquedas" msgstr "Contenido del mensaje, para usarse en búsquedas"
#. module: base_search_mail_content
#: model:ir.model,name:base_search_mail_content.model_res_partner
msgid "Partner"
msgstr "Empresa"

View File

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L. # © 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com) # (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>) # © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mail_thread from . import mail_thread
from . import res_partner

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L. # © 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com) # (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>) # © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models from odoo import api, fields, models
from lxml import etree from lxml import etree
from openerp.osv import expression from odoo.osv import expression
from openerp.osv.orm import setup_modifiers from odoo.osv.orm import setup_modifiers
class MailThread(models.AbstractModel): class MailThread(models.AbstractModel):
@ -16,64 +16,52 @@ class MailThread(models.AbstractModel):
def _search_message_content(self, operator, value): def _search_message_content(self, operator, value):
main_operator = 'in' model_domain = [('model', '=', self._name)]
if operator in expression.NEGATIVE_TERM_OPERATORS: if operator not in expression.NEGATIVE_TERM_OPERATORS:
main_operator = 'not in' model_domain += ["|"] * 4
operators = {'!=': '=', 'not like': 'like', model_domain += [
'not ilike': 'ilike', 'not in': 'in'}
operator = operators[operator]
domain = [('model', '=', self._name), '|', '|', '|', '|',
('record_name', operator, value), ('record_name', operator, value),
('subject', operator, value), ('body', operator, value), ('subject', operator, value),
('body', operator, value),
('email_from', operator, value), ('email_from', operator, value),
('reply_to', operator, value)] ('reply_to', operator, value)
recs = self.env['mail.message'].search(domain) ]
return [('id', main_operator, recs.mapped('res_id'))] recs = self.env['mail.message'].search(model_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( message_content = fields.Text(
string='Message Content', string='Message Content',
help='Message content, to be used only in searches', help='Message content, to be used only in searches',
compute="_compute_message_content", compute=lambda self: False,
search='_search_message_content') search='_search_message_content')
@api.model
_base_fields_view_get = models.BaseModel.fields_view_get def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
@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 Override to add message_content field in all the objects
that inherits mail.thread that inherits mail.thread
""" """
# Tricky super call res = super(MailThread, self).fields_view_get(
res = _base_fields_view_get(self, view_id=view_id, view_type=view_type, view_id=view_id, view_type=view_type, toolbar=toolbar,
toolbar=toolbar, submenu=submenu) submenu=submenu)
if view_type == 'search' and self._fields.get('message_content'): if view_type == 'search' and self._fields.get('message_content'):
doc = etree.XML(res['arch']) doc = etree.XML(res['arch'])
res['fields'].update({ res['fields'].update({
'message_content': { 'message_content': {
'type': 'char', 'type': 'char',
'string': 'Message content', 'string': 'Message Content',
} }
}) })
for node in doc.xpath("//field[1]"): for node in doc.xpath("//field[1]"):
# Add message_content in search view # Add message_content in search view
elem = etree.Element('field', { elem = etree.Element(
'field',
{
'name': 'message_content', 'name': 'message_content',
}) })
setup_modifiers(elem) setup_modifiers(elem)
node.addnext(elem) node.addnext(elem)
res['arch'] = etree.tostring(doc) res['arch'] = etree.tostring(doc)
return res return res
models.BaseModel.fields_view_get = _custom_fields_view_get

View File

@ -1,13 +0,0 @@
# -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>)
# 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']

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_base_search_mail_content

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class TestBaseSearchMailContent(TransactionCase):
def setUp(self):
super(TestBaseSearchMailContent, self).setUp()
self.channel_obj = self.env["mail.channel"]
def test_base_search_mail_content_1(self):
res = self.channel_obj.search(
[('message_content', 'ilike', 'xxxyyyzzz')])
self.assertFalse(res, "You have a channel with xxxyyyzzz :O")
def test_base_search_mail_content_2(self):
res = self.channel_obj.load_views(
[[False, 'search']], {'load_fields': False,
'load_filters': True,
'toolbar': True})
self.assertIn(
'message_content', res['fields_views']['search']['fields'],
"message_content field was not detected")

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <odoo>
<data>
<record model="ir.ui.view" id="trgm_index_view_form"> <record model="ir.ui.view" id="trgm_index_view_form">
<field name="name">trgm.index.view.form</field> <field name="name">trgm.index.view.form</field>
@ -25,5 +24,4 @@
</field> </field>
</record> </record>
</data> </odoo>
</openerp>