Merge lp:~openerp-dev/openobject-server/7.0-opw-603382-ado into lp:openobject-server/7.0

Proposed by Amit Dodiya (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-opw-603382-ado
Merge into: lp:openobject-server/7.0
Diff against target: 38 lines (+20/-1)
1 file modified
openerp/addons/base/ir/ir_ui_menu.py (+20/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-opw-603382-ado
Reviewer Review Type Date Requested Status
Amit Dodiya (OpenERP) (community) Needs Resubmitting
Olivier Dony (Odoo) Needs Fixing
Naresh(OpenERP) Pending
Review via email: mp+203296@code.launchpad.net

Description of the change

Hello,

[FIX] ir_ui_menu: while adding domain value using 'time.strftime("%Y-%m-%d")' in domain of window action it gives trace-back, NameError: name 'time' is not defined

Steps to reproduce:
1). Goto: Setting-> Technical-> Action-> Window Action
2). Now search for 'Quotation' you will find some result, now open the action which has tree view ref. added
3). add one condition on existing domain like 'date_order','=',time.strftime("%Y-%m-%d"), save it and click on Sales menu you will get trace-back.

Regards,
Amit

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

This is not a complete fix. If you want to support most of the custom action domains that are supported on the client-side, you need to provide the same evaluation context (look at the way contexts and domains are evaluated on the client-side). You will need datetime.datetime, relativedelta, timedelta, etc.
In any case it would be a good idea to put a try/except around this eval, and fallback to having an empty `dom` if the eval fails. At least this will avoid breaking the need_action system too easily.

Thanks!

review: Needs Fixing
Revision history for this message
Amit Dodiya (OpenERP) (ado-openerp) wrote :

Hello Olivier Dony,

I have changed the code as per your suggestion.

Regards,
Amit

review: Needs Resubmitting
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi,

Thanks for updating the merge proposal.

It looks better now, but:
 - you don't need backslashes within a literal dict declaration
 - the one-liner with the eval is difficult to read now, could you split it in multiple lines (but keep the lazy creation of the eval dict, i.e. only eval the domain if menu.action.domain is set
 - in case an exception occurs, it could be useful to log a warning, something like:
    _logger.warning("Action domain '%s' could not be processed to filter need-action data, ignoring it.", exc_info=True)

Thanks,

review: Needs Fixing
5214. By Martin Trigaux (OpenERP)

[MERGE] [FIX] expression: do not look at translation in parse when searching with empty string or false
This fixes traceback when applying filter 'is not set' on a translatable field

5215. By Amit Dodiya (OpenERP)

[FIX] ir_ui_menu: while adding domain value using python time in domain of window action it gives traceback

Revision history for this message
Amit Dodiya (OpenERP) (ado-openerp) wrote :

Hello,

I have changed the code as per the comment.

Thanks,
Amit

review: Needs Resubmitting

Unmerged revisions

5215. By Amit Dodiya (OpenERP)

[FIX] ir_ui_menu: while adding domain value using python time in domain of window action it gives traceback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_ui_menu.py'
2--- openerp/addons/base/ir/ir_ui_menu.py 2013-05-07 10:40:25 +0000
3+++ openerp/addons/base/ir/ir_ui_menu.py 2014-01-28 07:03:32 +0000
4@@ -20,6 +20,10 @@
5 #
6 ##############################################################################
7
8+import time
9+from datetime import datetime, timedelta
10+from dateutil.relativedelta import relativedelta
11+from openerp.tools.misc import DEFAULT_SERVER_DATE_FORMAT
12 import base64
13 import re
14 import threading
15@@ -333,7 +337,22 @@
16 obj = self.pool.get(menu.action.res_model)
17 if obj and obj._needaction:
18 if menu.action.type == 'ir.actions.act_window':
19- dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
20+ #if menu.action.domain is not there set dom blank
21+ dom = []
22+ #evaluate the action domain if menu.action.domain is there
23+ if menu.action.domain:
24+ try:
25+ dom = eval(menu.action.domain, {
26+ 'uid': uid,
27+ 'context_today': fields.date.context_today,
28+ 'datetime': datetime,
29+ 'time': time,
30+ 'relativedelta': relativedelta,
31+ 'current_date': time.strftime(DEFAULT_SERVER_DATE_FORMAT)
32+ })
33+ except Exception:
34+ _logger.warning("Action domain '%s' could not be processed to filter need-action data, ignoring it.", dom, exc_info=True)
35+ dom = []
36 else:
37 dom = eval(menu.action.params_store or '{}', {'uid': uid}).get('domain')
38 res[menu.id]['needaction_enabled'] = obj._needaction