Odoo Help

3

Comparison with date on action domain filter

By
David Verove
on 9/15/15, 11:03 AM 1,856 views

Hello,

In V8, I have an action on which I'd like to use a comparison with current date : 

        <record id="action_rez_by_date" model="ir.actions.act_window"> 
<field name="name">Réservations en cours (j/j+1/j+2/j+3)</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="domain">[('occupation_date_in','&gt;',time.strftime('%Y-%m-%d'))]</field>

occupation_date_in is declared as following

_columns = {
'occupation_date_in': fields.date('Rental date in', readonly=True, states={'draft': [('readonly', False)],'sent': [('readonly', False)],'progress': [('readonly', False)],'manual': [('readonly', False)]}),
}

After restarting Odoo and refreshing the view, I get the following message : 

Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 869, in load_needaction
return request.session.model('ir.ui.menu').get_needaction_data(menu_ids, request.context)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 900, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_ui_menu.py", line 341, in get_needaction_data
dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
File "/usr/lib/python2.7/dist-packages/openerp/tools/safe_eval.py", line 314, in safe_eval
return eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
ValueError: "name 'time' is not defined" while evaluating
u"[('occupation_date_in','>',time.strftime('%Y-%m-%d'))]"

This kind of comparison is used in many places in odoo modules, what's wrong? 

Thanks,

David

have you putted "import time" at beginning of the file???

Jusab Sida (jsi)
on 3/14/16, 8:51 AM
1
David Verove
On 9/18/15, 9:17 AM

Thanks, but I have anothe error : 

Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 869, in load_needaction
return request.session.model('ir.ui.menu').get_needaction_data(menu_ids, request.context)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 900, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_ui_menu.py", line 341, in get_needaction_data
dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
File "/usr/lib/python2.7/dist-packages/openerp/tools/safe_eval.py", line 312, in safe_eval
c = test_expr(expr, _SAFE_OPCODES, mode=mode)
File "/usr/lib/python2.7/dist-packages/openerp/tools/safe_eval.py", line 174, in test_expr
assert_valid_codeobj(allowed_codes, code_obj, expr)
File "/usr/lib/python2.7/dist-packages/openerp/tools/safe_eval.py", line 146, in assert_valid_codeobj
assert_no_dunder_name(code_obj, expr)
File "/usr/lib/python2.7/dist-packages/openerp/tools/safe_eval.py", line 126, in assert_no_dunder_name
raise NameError('Access to forbidden name %r (%r)' % (name, expr))
NameError: Access to forbidden name '__import__' (u"[('occupation_date_in','>',__import__('time').strftime('%Y-%m-%d'))]")
1
Axel Mendoza
On 9/18/15, 2:27 AM

You could fix this by using this syntax:

<field name="domain">[('occupation_date_in','&amp;gt;',__import__('time').strftime('%Y-%m-%d'))]</field>


0
Anton Chepurov
On 2/9/17, 7:20 PM

How have you solved it eventually?

EDIT: Sure, here's how I solved it:

https://gist.github.com/a0c/81ef97177d32cc421c5a2fde9199b6a4


I haven't found any solution, I finally gave up this functionnality.

But I'm still interested on it, if someone has an idea..

David Verove
on 2/10/17, 4:35 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/15/15, 11:03 AM
Seen: 1856 times
Last updated: 2/9/17, 7:20 PM