-
-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.0][MIG] base_search_mail_content #180
[10.0][MIG] base_search_mail_content #180
Conversation
20cb978
to
c8eb14c
Compare
c8eb14c
to
256d275
Compare
def _compute_message_content(self): | ||
""" We don't really need to show any content. This field is to be | ||
used only by searches""" | ||
return '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compute fields don't return, they just set self.field=something
. Just pass
please.
return res | ||
|
||
|
||
models.BaseModel.fields_view_get = _custom_fields_view_get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This monkey-patching should not get accepted now on v10. Override it as usual with _inherit = "base"
instead (it is a new v10 feature).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
class Partner(models.Model): | ||
|
||
_name = 'res.partner' | ||
_inherit = ['res.partner', 'mail.thread'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this file? res.partner
already inherits from mail.thread
by default... Isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already inherits or you wouldn't have chatter on partners, so this is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let's see if it works now without the file 👍
search='_search_message_content') | ||
|
||
|
||
class BaseModel(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet this shouldn't inherit from object
|
||
class BaseModel(object): | ||
|
||
_inherit = 'base' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be mail.thread
instead? So it should be merged with the class above... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more? You said before that we should override it with _inherit = "base"
. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know 😆
Sorry for confusing. I said that before because it's the new way to avoid monkey patches, but after seeing this now, I realized that you only need this code for addons that inherit from mail.thread
, so possibly adding the method there should be better.
res = super(BaseModel, self)._fields_view_get( | ||
view_id=view_id, view_type=view_type, toolbar=toolbar, | ||
submenu=submenu) | ||
if view_type == 'search' and self._fields.get('message_content'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the method in mail.thread
, then you don't need to check and self._fields.get('message_content')
, since it would always be true.
operators = {'!=': '=', 'not like': 'like', | ||
'not ilike': 'ilike', 'not in': 'in'} | ||
operator = operators[operator] | ||
domain = [('model', '=', self._name), '|', '|', '|', '|', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that it would be much cleaner and more efficient to do something like:
domain = [('model', '=', self._name)]
if operator not in expression.NEGATIVE_TERM_OPERATORS:
domain += ["|"] * 4
domain += [('record_name', operator, value),
('subject', operator, value),
('body', operator, value),
('email_from', operator, value),
('reply_to', operator, value)]
message_content = fields.Text( | ||
string='Message Content', | ||
help='Message content, to be used only in searches', | ||
compute="_compute_message_content", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can compute=lambda self: False
instead. Just a suggestion.
@@ -22,42 +22,34 @@ def _search_message_content(self, operator, value): | |||
operators = {'!=': '=', 'not like': 'like', | |||
'not ilike': 'ilike', 'not in': 'in'} | |||
operator = operators[operator] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete all above this in the method.
('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'))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete these 2 lines and return domain
"data": ["data/trgm_index_data.xml", | ||
"views/trgm_index_view.xml"], | ||
"depends": ["mail", | ||
"base_search_fuzzy"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
mail
is because the inheritedmail.thread
classbase_search_fuzzy
, a module in server-tools repository, is because the inheritedtrgm_index_view.xml
view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but UI fails.
for node in doc.xpath("//field[1]"): | ||
# Add message_content in search view | ||
elem = etree.Element('field', { | ||
'name': 'message_content', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be working, maybe yes it was required to inherit from base
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... return again to:
class BaseModel(object):
_inherit = 'base'
🤔?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems... Remember that reviewers can be wrong, you should test what you do and let it as it was if new patch does not work 😉
|
||
def _search_message_content(self, operator, value): | ||
|
||
domain = [('model', '=', self._name)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to break the UI:
Odoo Server Error
Traceback (most recent call last):
File "/.repo_requirements/odoo/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/.repo_requirements/odoo/odoo/http.py", line 677, in dispatch
result = self._call_function(**self.params)
File "/.repo_requirements/odoo/odoo/http.py", line 333, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/.repo_requirements/odoo/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/.repo_requirements/odoo/odoo/http.py", line 326, in checked_call
result = self.endpoint(*a, **kw)
File "/.repo_requirements/odoo/odoo/http.py", line 935, in __call__
return self.method(*args, **kw)
File "/.repo_requirements/odoo/odoo/http.py", line 506, in response_wrap
response = f(*args, **kw)
File "/home/odoo/odoo-10.0/addons/web/controllers/main.py", line 827, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "/home/odoo/odoo-10.0/addons/web/controllers/main.py", line 849, in do_search_read
offset=offset or 0, limit=limit or False, order=sort or False)
File "/.repo_requirements/odoo/odoo/models.py", line 4678, in search_read
records = self.search(domain or [], offset=offset, limit=limit, order=order)
File "/.repo_requirements/odoo/odoo/models.py", line 1518, in search
res = self._search(args, offset=offset, limit=limit, order=order, count=count)
File "/.repo_requirements/odoo/odoo/addons/base/res/res_partner.py", line 633, in _search
count=count, access_rights_uid=access_rights_uid)
File "/.repo_requirements/odoo/odoo/models.py", line 4220, in _search
query = self._where_calc(args)
File "/.repo_requirements/odoo/odoo/models.py", line 4019, in _where_calc
e = expression.expression(domain, self)
File "/.repo_requirements/odoo/odoo/osv/expression.py", line 643, in __init__
self.parse()
File "/.repo_requirements/odoo/odoo/osv/expression.py", line 821, in parse
raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'model' in leaf "<osv.ExtendedLeaf: ('model', '=', 'res.partner') on res_partner (ctx: )>"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what do you propose? 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly changing this to domain=[]
fixes it.
@yajo , could you please update your review? |
I feel current code will not work, have you tested it? |
I have just tested, but it has some issues that should be fixed |
Please @mreficent ping me when module is ready for a functional test! thanks |
Introduce search of html fields Create indexes Update Readme
bfbcaf7
to
0d144d4
Compare
Hi @mreficent thank you!!! you should improve test as it has 42.85% of diff hit (target 98.81%) I will wait until @yajo finish his review ;-) for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking suggestions
base_search_mail_content/README.rst
Outdated
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/10.0/base_search_fuzzy/README.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better:
`install instructions <https://github.com/OCA/server-tools/blob/10.0/base_search_fuzzy/README.rst>`_.
base_search_mail_content/README.rst
Outdated
* Lois Rilo Antelo <lois.rilo@eficent.com> | ||
* Aaron Henriquez <ahenriquez@eficent.com> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove line
search='_search_message_content') | ||
|
||
|
||
class BaseModel(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to do quick search of message contents. Most likely this should inherit from models.AbstractModel
instead, although I think you already fixed this before... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgresql decides when is best to use trigram indexes. You will need to install this module into a DB with a rather large number of emails.
To check if the trigram indexes are being used, you must:
- start odoo with --log-level=debug_sql
- Do the search that you want to analyze - e.g. search for emails from the leads.
- Copy the query and run in command line
EXPLAIN ANALYZE (my_query)
:
EXPLAIN ANALYZE (SELECT "mail_message".id FROM "mail_message" WHERE (("mail_message"."model" = 'res.partner') AND ((((("mail_message"."record_name"::text ilike 'dear') OR ("mail_message"."subject"::text ilike 'dear')) OR ("mail_message"."body"::text ilike 'dear')) OR ("mail_message"."email_from"::text ilike 'dear')) OR ("mail_message"."reply_to"::text ilike 'dear'))) ORDER BY "mail_message"."id" DESC);
This will tell you if trigram indexes are being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0d144d4
to
11b5ee8
Compare
the field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excelent!
Please do the final squash
d4c8e64
to
f7eeb11
Compare
Squash done |
@rafaelbn can you review? |
Is there the possibility of improving test coverage? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested functionaly 👍 but codecov/patch — 38.46% of diff hit (target 98.81%) must be increased please! This is a great funcionality
ping @mreficent @jbeficent
self.thread_obj = self.env["mail.thread"] | ||
|
||
def test_base_search_mail_content(self): | ||
res = self.thread_obj._search_message_content('not ilike', 'xxxyyyzzz') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the test should be self.thread_obj.search([("message_content", ...
|
||
def test_base_search_mail_content(self): | ||
res = self.thread_obj._search_message_content('not ilike', 'xxxyyyzzz') | ||
self.assertEqual(res[0][2], [], "You have a message with xxxyyyzzz :O") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then here assertFalse
3070674
to
110b28d
Compare
There is not codecov/patch now 😂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested functionaly 👍
@mreficent please could answer @yajo 's comments ? I wish tomorrow we can merge this one! Great work! |
Which comments? All @yajo's comments have been attended I think. |
Cool! could you squash the migration commits to merge please? 😊 |
110b28d
to
b36457e
Compare
Done! codecov/patch at 100% |
Standard migration.