This question has been flagged
3 Replies
4701 Views

Dears,

I created a filter to filter tasks with no work in the last day, and it's working fine while applying it in filters.

While the filter is linked with automated action I get this error when i try to create or modify a task I get an error with :

openerp/addons/base_action_rule/base_action_rule.py", line 101, in _filter
    domain = [('id', 'in', record_ids)] + eval(action_filter.domain)
  File "<string>", line 1, in <module>
 NameError: name 'context_today' is not defined

If there's no automated action linked with the filter - I can modify tasks normally without errors.

The domain in the filter is:

['&', ['write_date', '<', ((context_today() - relativedelta(days=1)).strftime('%Y-%m-%d'))], ['progress', '<', 100]]

Can anyone tell me what's the problem ?

Avatar
Discard

I have the same issue. Filter is working in the search. But when I use it with automated action I get the same error. Anyone an idea what to use if you want to work with this filter in an Automated action?

Best Answer

To resolve this issue, you can modify the domain expression in your filter's automated action to include the context_today() function outside of the eval() statement. Here's an updated example:

[('&', ['write_date', 'datetime.datetime.now() - relativedelta(days=1)).strftime('%Y-%m-%d')]), ['progress', '

In this updated expression, we use the datetime module to calculate the current date and subtract one day (relativedelta(days=1)) to get the desired date. We then format it using strftime('%Y-%m-%d') to match the expected date format in the domain expression.

By making this change, you can avoid the NameError related to the context_today() function within the eval() statement.

Avatar
Discard
Best Answer

short: use datetime

like: ('start_date', '>', datetime\.datetime\.now\(\)\.strftime\("%Y\-%m\-%d\ 23:59:59"\) \ in\ odoo9

in\ odoo13\ maybe\ you\ can\ use\ \+\ operator\ and\ interval,\ but\ i\ does\ not\ test\ it,\ but\ it\ is\ appear\ in\ python\ source\ code\ and\ works\.\ \(from\ other\ post\)

\[\('last_connection_datetime',\ '>',\ datetime.datetime.now() MINUS OR PLUS datetime.timedelta(days=CHANGE THE NUMBER HERE))]


LONG: i figured out what's wrong. context_today validates on backend, but:

Domains uses safe_eval and it uses context for evaluting domains. 
In automatic actions there arentas many things as in backend, and context contains less objects.

e.g. if your domain is evaluted triggered by base action rule, then in the context are:

'dateutil': , 
'user': res.users(1,), 
'time': , 
'uid': 1,
'datetime':

}

Avatar
Discard
Best Answer

If someone could help us out here with some kind of directions what to do, would be much appreciated :)

Avatar
Discard