From 3e82c94d695327d5fa85cf6c9eca5039d7bc1bb6 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 20 Aug 2015 10:32:43 +0200 Subject: [PATCH] [FIX] point_of_sale,base: use context timezone for sequence Previously when replacing time related sequence in a prefix or suffix of a sequence, the timezone used for the time values would always be the server's timezone. With this fix, the context timezone is used if available (UTC is used otherwise). closes #8159 opw-646487 --- addons/point_of_sale/point_of_sale.py | 2 +- openerp/addons/base/ir/ir_sequence.py | 29 +++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index cc51b8823ea..5ba591b39a7 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -425,7 +425,7 @@ class pos_session(osv.osv): bank_statement_ids.append(statement_id) values.update({ - 'name': self.pool['ir.sequence'].get(cr, uid, 'pos.session'), + 'name': self.pool['ir.sequence'].get(cr, uid, 'pos.session', context=context), 'statement_ids' : [(6, 0, bank_statement_ids)], 'config_id': config_id }) diff --git a/openerp/addons/base/ir/ir_sequence.py b/openerp/addons/base/ir/ir_sequence.py index 999f12a9d18..f93d7ba7eee 100644 --- a/openerp/addons/base/ir/ir_sequence.py +++ b/openerp/addons/base/ir/ir_sequence.py @@ -19,7 +19,9 @@ # ############################################################################## +from datetime import datetime import logging +import pytz import time import openerp @@ -218,21 +220,18 @@ class ir_sequence(openerp.osv.osv.osv): return s % d return '' - def _interpolation_dict(self): - t = time.localtime() # Actually, the server is always in UTC. - return { - 'year': time.strftime('%Y', t), - 'month': time.strftime('%m', t), - 'day': time.strftime('%d', t), - 'y': time.strftime('%y', t), - 'doy': time.strftime('%j', t), - 'woy': time.strftime('%W', t), - 'weekday': time.strftime('%w', t), - 'h24': time.strftime('%H', t), - 'h12': time.strftime('%I', t), - 'min': time.strftime('%M', t), - 'sec': time.strftime('%S', t), + def _interpolation_dict_context(self, context=None): + if context is None: + context = {} + t = datetime.now(pytz.timezone(context.get('tz') or 'UTC')) + sequences = { + 'year': '%Y', 'month': '%m', 'day': '%d', 'y': '%y', 'doy': '%j', 'woy': '%W', + 'weekday': '%w', 'h24': '%H', 'h12': '%I', 'min': '%M', 'sec': '%S' } + return {key: t.strftime(sequence) for key, sequence in sequences.iteritems()} + + def _interpolation_dict(self): + return self._interpolation_dict_context() def _next(self, cr, uid, ids, context=None): if not ids: @@ -252,7 +251,7 @@ class ir_sequence(openerp.osv.osv.osv): cr.execute("SELECT number_next FROM ir_sequence WHERE id=%s FOR UPDATE NOWAIT", (seq['id'],)) cr.execute("UPDATE ir_sequence SET number_next=number_next+number_increment WHERE id=%s ", (seq['id'],)) self.invalidate_cache(cr, uid, ['number_next'], [seq['id']], context=context) - d = self._interpolation_dict() + d = self._interpolation_dict_context(context=context) try: interpolated_prefix = self._interpolate(seq['prefix'], d) interpolated_suffix = self._interpolate(seq['suffix'], d)