mirror of https://github.com/OCA/social.git
[IMP] advanced search for negative expression
parent
6eafc8fa13
commit
763dde0d54
|
@ -6,7 +6,7 @@
|
||||||
Base Search Mail Content
|
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.
|
helpdesk ticket) based on the conversation threads associated to them.
|
||||||
|
|
||||||
This will be useful in models that make intense use of messages,
|
This will be useful in models that make intense use of messages,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# 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).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Base Mail Search Content",
|
"name": "Base Search Mail Content",
|
||||||
"version": "9.0.1.0.0",
|
"version": "9.0.1.0.0",
|
||||||
"author": "Eficent,"
|
"author": "Eficent,"
|
||||||
"SerpentCS,"
|
"SerpentCS,"
|
||||||
|
|
|
@ -15,16 +15,20 @@ class MailThread(models.AbstractModel):
|
||||||
_inherit = 'mail.thread'
|
_inherit = 'mail.thread'
|
||||||
|
|
||||||
def _search_message_content(self, operator, value):
|
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), '|', '|', '|', '|',
|
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)]
|
||||||
|
|
||||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
|
||||||
domain = domain[2:]
|
|
||||||
recs = self.env['mail.message'].search(domain)
|
recs = self.env['mail.message'].search(domain)
|
||||||
return [('id', 'in', recs.mapped('res_id'))]
|
return [('id', main_operator, recs.mapped('res_id'))]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_message_content(self):
|
def _compute_message_content(self):
|
||||||
|
@ -33,7 +37,7 @@ class MailThread(models.AbstractModel):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
message_content = fields.Text(
|
message_content = fields.Text(
|
||||||
string='Messages',
|
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="_compute_message_content",
|
||||||
search='_search_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]"):
|
for node in doc.xpath("//field[1]"):
|
||||||
# Add message_ids in search view
|
# Add message_content in search view
|
||||||
elem = etree.Element('field', {
|
elem = etree.Element('field', {
|
||||||
'name': 'message_content',
|
'name': 'message_content',
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,18 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="field_id" position="attributes">
|
<field name="field_id" position="attributes">
|
||||||
<attribute name="domain">[('ttype', 'in', ['char', 'text', 'html'])]</attribute>
|
<attribute name="domain">[('ttype', 'in', ['char', 'text', 'html'])]</attribute>
|
||||||
|
<attribute name="help">"You can either select a field of type 'text', 'char' or 'html'."</attribute>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="trgm_index_view_tree">
|
||||||
|
<field name="name">trgm.index.view.tree</field>
|
||||||
|
<field name="model">trgm.index</field>
|
||||||
|
<field name="inherit_id" ref="base_search_fuzzy.trgm_index_view_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="field_id" position="attributes">
|
||||||
|
<attribute name="help">"You can either select a field of type 'text', 'char' or 'html'."</attribute>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
Loading…
Reference in New Issue