Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
4 Ответы
8678 Представления

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???

Автор Лучший ответ

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'))]")
Аватар
Отменить
Лучший ответ

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

Related Posts Ответы Просмотры Активность
1
мар. 24
1407
2
авг. 25
220
1
авг. 25
316
1
авг. 25
262
0
авг. 25
259