[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.
This commit is contained in:
Samus CTO 2014-08-08 11:46:41 +02:00
parent 5f696ba86c
commit c16884364b
1 changed files with 5 additions and 4 deletions

View File

@ -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()