From c16884364b61cd5bf88790a0818aad52ac1715d1 Mon Sep 17 00:00:00 2001 From: Samus CTO Date: Fri, 8 Aug 2014 11:46:41 +0200 Subject: [PATCH] [FIX] Calculate date interval using super user time zone When you set the date of a cron the July 1st at midnight, if the user time zone has a positive offset, then the converted UTC date is the June 30th and adding 1 month will end up on July 30th translating to July 31th instead of September 1st. To solve this issue we use the super user time zone for the date calculation. --- openerp/addons/base/ir/ir_cron.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/ir/ir_cron.py b/openerp/addons/base/ir/ir_cron.py index 77c9835d9be..cfabd97fb16 100644 --- a/openerp/addons/base/ir/ir_cron.py +++ b/openerp/addons/base/ir/ir_cron.py @@ -24,9 +24,10 @@ import time import psycopg2 from datetime import datetime from dateutil.relativedelta import relativedelta +import pytz import openerp -from openerp import netsvc +from openerp import netsvc, SUPERUSER_ID from openerp.osv import fields, osv from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.tools.safe_eval import safe_eval as eval @@ -149,8 +150,8 @@ class ir_cron(osv.osv): must not be committed/rolled back! """ try: - now = datetime.now() - nextcall = datetime.strptime(job['nextcall'], DEFAULT_SERVER_DATETIME_FORMAT) + now = fields.datetime.context_timestamp(job_cr, SUPERUSER_ID, datetime.now()) + nextcall = fields.datetime.context_timestamp(job_cr, SUPERUSER_ID, datetime.strptime(job['nextcall'], DEFAULT_SERVER_DATETIME_FORMAT)) numbercall = job['numbercall'] ok = False @@ -166,7 +167,7 @@ class ir_cron(osv.osv): if not numbercall: addsql = ', active=False' cron_cr.execute("UPDATE ir_cron SET nextcall=%s, numbercall=%s"+addsql+" WHERE id=%s", - (nextcall.strftime(DEFAULT_SERVER_DATETIME_FORMAT), numbercall, job['id'])) + (nextcall.astimezone(pytz.UTC).strftime(DEFAULT_SERVER_DATETIME_FORMAT), numbercall, job['id'])) finally: job_cr.commit()