[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:
parent
1f57c9a5a6
commit
3e82c94d69
|
@ -425,7 +425,7 @@ class pos_session(osv.osv):
|
||||||
bank_statement_ids.append(statement_id)
|
bank_statement_ids.append(statement_id)
|
||||||
|
|
||||||
values.update({
|
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)],
|
'statement_ids' : [(6, 0, bank_statement_ids)],
|
||||||
'config_id': config_id
|
'config_id': config_id
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import pytz
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
|
@ -218,21 +220,18 @@ class ir_sequence(openerp.osv.osv.osv):
|
||||||
return s % d
|
return s % d
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _interpolation_dict(self):
|
def _interpolation_dict_context(self, context=None):
|
||||||
t = time.localtime() # Actually, the server is always in UTC.
|
if context is None:
|
||||||
return {
|
context = {}
|
||||||
'year': time.strftime('%Y', t),
|
t = datetime.now(pytz.timezone(context.get('tz') or 'UTC'))
|
||||||
'month': time.strftime('%m', t),
|
sequences = {
|
||||||
'day': time.strftime('%d', t),
|
'year': '%Y', 'month': '%m', 'day': '%d', 'y': '%y', 'doy': '%j', 'woy': '%W',
|
||||||
'y': time.strftime('%y', t),
|
'weekday': '%w', 'h24': '%H', 'h12': '%I', 'min': '%M', 'sec': '%S'
|
||||||
'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),
|
|
||||||
}
|
}
|
||||||
|
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):
|
def _next(self, cr, uid, ids, context=None):
|
||||||
if not ids:
|
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("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'],))
|
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)
|
self.invalidate_cache(cr, uid, ['number_next'], [seq['id']], context=context)
|
||||||
d = self._interpolation_dict()
|
d = self._interpolation_dict_context(context=context)
|
||||||
try:
|
try:
|
||||||
interpolated_prefix = self._interpolate(seq['prefix'], d)
|
interpolated_prefix = self._interpolate(seq['prefix'], d)
|
||||||
interpolated_suffix = self._interpolate(seq['suffix'], d)
|
interpolated_suffix = self._interpolate(seq['suffix'], d)
|
||||||
|
|
Loading…
Reference in New Issue