Skip to content
Snippets Groups Projects
Commit 9d1909f2 authored by Jeremy Hennecart's avatar Jeremy Hennecart Committed by Thibault Delavallée
Browse files

[FIX] base: update lastcall with manual cron execution as with automated execution


Cron holds a lastcall field and context key allowing to compute an accessible
range of processable records based on last execution. This lastcall value is
updated when cron runs automatically. Manual call currently does not update.
It makes sense to do the same update in manual call than with automated calls.

Moreover lastcall context key is also updated. It is used notably in calendar.
Otherwise only mails linked to "today" are taken into account, leading to
reminder issues.

Task ID-2331999

closes odoo/odoo#60537

X-original-commit: 6c34d199
Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 037012bc
Branches
Tags
No related merge requests found
......@@ -81,6 +81,8 @@ class ir_cron(models.Model):
self.check_access_rights('write')
for cron in self:
cron.with_user(cron.user_id).ir_actions_server_id.run()
cron.with_user(cron.user_id).with_context(lastcall=cron.lastcall).ir_actions_server_id.run()
cron.lastcall = fields.Datetime.now()
return True
@api.model
......
......@@ -15,6 +15,7 @@ from . import test_http_case
from . import test_image
from . import test_ir_actions
from . import test_ir_attachment
from . import test_ir_cron
from . import test_ir_http
from . import test_ir_filters
from . import test_ir_model
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from unittest.mock import patch
from odoo import fields
from odoo.tests.common import TransactionCase
class TestIrCron(TransactionCase):
def setUp(self):
super(TestIrCron, self).setUp()
self.cron = self.env['ir.cron'].create({
'name': 'TestCron',
'model_id': self.env.ref('base.model_res_partner').id,
'state': 'code',
'code': 'model.search([("name", "=", "TestCronRecord")]).write({"name": "You have been CRONWNED"})',
'interval_number': 1,
'interval_type': 'days',
'numbercall': -1,
'doall': False,
})
self.test_partner = self.env['res.partner'].create({
'name': 'TestCronRecord'
})
self.test_partner2 = self.env['res.partner'].create({
'name': 'NotTestCronRecord'
})
def test_cron_direct_trigger(self):
self.assertFalse(self.cron.lastcall)
self.assertEqual(self.test_partner.name, 'TestCronRecord')
self.assertEqual(self.test_partner2.name, 'NotTestCronRecord')
def patched_now(*args, **kwargs):
return '2020-10-22 08:00:00'
with patch('odoo.fields.Datetime.now', patched_now):
self.cron.method_direct_trigger()
self.assertEqual(fields.Datetime.to_string(self.cron.lastcall), '2020-10-22 08:00:00')
self.assertEqual(self.test_partner.name, 'You have been CRONWNED')
self.assertEqual(self.test_partner2.name, 'NotTestCronRecord')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment