[FIX] base_automation: fix check and execute time based

Before this commit, the ir.cron "Automation Rules: check and execute" crashed
because the "_check" method used get_eval_context where it shouldn't

This is due to b846d1ebe9, which makes _get_eval_context a record's
method, not a model one.

closes odoo/odoo#140153

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais
2023-10-27 23:44:52 +00:00
parent 431d40be34
commit d04ca8fa60
2 changed files with 19 additions and 1 deletions
@@ -892,10 +892,10 @@ class BaseAutomation(models.Model):
self = self.with_context(__action_done={})
# retrieve all the automation rules to run based on a timed condition
eval_context = self._get_eval_context()
for automation in self.with_context(active_test=True).search([('trigger', 'in', TIME_TRIGGERS)]):
_logger.info("Starting time-based automation rule `%s`.", automation.name)
last_run = fields.Datetime.from_string(automation.last_run) or datetime.datetime.utcfromtimestamp(0)
eval_context = automation._get_eval_context()
# retrieve all the records that satisfy the automation's condition
domain = []
@@ -855,6 +855,24 @@ if env.context.get('old_values', None): # on write
lead.unlink()
self.assertEqual(called_count, 1)
def test_004_check_method(self):
model = self.env["ir.model"]._get("base.automation.lead.test")
TIME_TRIGGERS = [
'on_time',
'on_time_created',
'on_time_updated',
]
self.env["base.automation"].search([('trigger', 'in', TIME_TRIGGERS)]).active = False
automation = self.env["base.automation"].create({
"name": "Cron BaseAuto",
"trigger": "on_time",
"model_id": model.id,
})
self.assertFalse(automation.last_run)
self.env["base.automation"]._check(False)
self.assertTrue(automation.last_run)
@common.tagged('post_install', '-at_install')
class TestCompute(common.TransactionCase):