Odoo Help

Welcome!

This community 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.

2

Comparison with date on action domain filter

By
David Verove
on 9/15/15, 11:03 AM 1,158 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

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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>


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/15/15, 11:03 AM
Seen: 1158 times
Last updated: 3/14/16, 7:47 AM