OCA / automation

automation
GNU Affero General Public License v3.0
9 stars 14 forks source link

[16.0] automation_oca : can't use context_today() or datetime in filter #5

Open gaelTorrecillas opened 4 months ago

gaelTorrecillas commented 4 months ago

Module

automation_oca

Describe the bug

I create a new automation with a filter on write date <= today + XX days. For today I used :

ex : [("stage_id", "in", [10]),('write_date','<=', context_today()-datetime.timedelta(days=14 )),('id','=',409)]

In the form view of automation.filter I have the validation of this formula (at the bottom of this field)

But when I validate automation and "generate new records" I have an error type :

File "Libs/OCA-automation/automation_oca/models/automation_configuration.py", line 194, in _get_automation_records_to_create domain = safe_eval(self.domain) ^^^^^^^^^^^^^^^^^^^^^^ File "odoo/tools/safe_eval.py", line 405, in safe_eval raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)) ValueError: <class 'NameError'>: "name 'context_today' is not defined" while evaluating '[("stage_id", "in", [10]),(\'write_date\',\'<=\', context_today()-datetime.timedelta(days=14 )),(\'id\',\'=\',409)]'

To Reproduce

odoo : OCA/OCB automation_oca : 16.0.1.0.0

Steps to reproduce the behavior:

  1. create a new automation
  2. create a filter with a date condition
  3. validate and generate new records

Expected behavior A clear and concise description of what you expected to happen.

Additional context python version : Python 3.10.4

flotho commented 3 months ago

This seems to come from the call of https://github.com/OCA/automation/blob/16.0/automation_oca/models/automation_configuration.py#L194C9-L194C15 no options is passed to this method https://github.com/OCA/OCB/blob/16.0/odoo/tools/safe_eval.py#L341 so you can't reach internal parameters

flotho commented 3 months ago

If you add some options like for server actions you will be able to use those variables