[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
This commit is contained in:
Nicolas Lempereur 2015-08-20 10:32:43 +02:00
parent 1f57c9a5a6
commit 3e82c94d69
2 changed files with 15 additions and 16 deletions

View File

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

View File

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