Skip to content

Commit

Permalink
[16.0] add dependancies to use today() and datetime in domain (filter)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelTorrecillas committed Sep 5, 2024
1 parent dd7b35b commit f06b859
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions automation_oca/models/automation_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.safe_eval import safe_eval
from odoo.tools.safe_eval import (
datetime as safe_datetime,
)
from odoo.tools.safe_eval import (
dateutil as safe_dateutil,
)
from odoo.tools.safe_eval import (
safe_eval,
)
from odoo.tools.safe_eval import (
time as safe_time,
)


class AutomationConfiguration(models.Model):
Expand Down Expand Up @@ -184,14 +195,28 @@ def cron_automation(self):
for record in self.search([("state", "=", "periodic")]):
record.run_automation()

def _get_eval_context(self):
"""Prepare the context used when evaluating python code
:returns: dict -- evaluation context given to safe_eval
"""
return {
"ref": self.env.ref,
"user": self.env.user,
"time": safe_time,
"datetime": safe_datetime,
"dateutil": safe_dateutil,
}

def _get_automation_records_to_create(self):
"""
We will find all the records that fulfill the domain but don't have a record created.
Also, we need to check by autencity field if defined.
In order to do this, we will add some extra joins on the query of the domain
"""
domain = safe_eval(self.domain)
eval_context = self._get_eval_context()

domain = safe_eval(self.domain,eval_context)
Record = self.env[self.model_id.model]
if self.company_id and "company_id" in Record._fields:
# In case of company defined, we add only if the records have company field
Expand Down

0 comments on commit f06b859

Please sign in to comment.