[FIX] models.py, account, calendar, product: lang in context can be None
Different method use self._context.get('lang', 'en_US') to get the lang
value but, the lang in the context can be set to None (eg: copy method).
When the context is used with a lang=None, the method can have a
unexpected behavior or crashed (eg: if you try to format a datetime with a
locale=None)
This commit is contained in:
@@ -56,7 +56,7 @@ class account_journal(models.Model):
|
||||
last_bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids),('date', '<=', last_month.strftime(DF))], order="date desc, id desc", limit=1)
|
||||
start_balance = last_bank_stmt and last_bank_stmt[0].balance_end or 0
|
||||
|
||||
locale = self._context.get('lang', 'en_US')
|
||||
locale = self._context.get('lang') or 'en_US'
|
||||
show_date = last_month
|
||||
#get date in locale format
|
||||
name = format_date(show_date, 'd LLLL Y', locale=locale)
|
||||
@@ -94,7 +94,7 @@ class account_journal(models.Model):
|
||||
data = []
|
||||
today = datetime.strptime(fields.Date.context_today(self), DF)
|
||||
data.append({'label': _('Past'), 'value':0.0, 'type': 'past'})
|
||||
day_of_week = int(format_datetime(today, 'e', locale=self._context.get('lang', 'en_US')))
|
||||
day_of_week = int(format_datetime(today, 'e', locale=self._context.get('lang') or 'en_US'))
|
||||
first_day_of_week = today + timedelta(days=-day_of_week+1)
|
||||
for i in range(-1,4):
|
||||
if i==0:
|
||||
@@ -105,9 +105,9 @@ class account_journal(models.Model):
|
||||
start_week = first_day_of_week + timedelta(days=i*7)
|
||||
end_week = start_week + timedelta(days=6)
|
||||
if start_week.month == end_week.month:
|
||||
label = str(start_week.day) + '-' +str(end_week.day)+ ' ' + format_date(end_week, 'MMM', locale=self._context.get('lang', 'en_US'))
|
||||
label = str(start_week.day) + '-' +str(end_week.day)+ ' ' + format_date(end_week, 'MMM', locale=self._context.get('lang') or 'en_US')
|
||||
else:
|
||||
label = format_date(start_week, 'd MMM', locale=self._context.get('lang', 'en_US'))+'-'+format_date(end_week, 'd MMM', locale=self._context.get('lang', 'en_US'))
|
||||
label = format_date(start_week, 'd MMM', locale=self._context.get('lang') or 'en_US')+'-'+format_date(end_week, 'd MMM', locale=self._context.get('lang') or 'en_US')
|
||||
data.append({'label':label,'value':0.0, 'type': 'past' if i<0 else 'future'})
|
||||
|
||||
# Build SQL query to find amount aggregated by week
|
||||
|
||||
@@ -1199,11 +1199,11 @@ class Meeting(models.Model):
|
||||
|
||||
elif interval == 'month':
|
||||
# Localized month name and year
|
||||
result = babel.dates.format_date(date=date, format='MMMM y', locale=self._context.get('lang', 'en_US'))
|
||||
result = babel.dates.format_date(date=date, format='MMMM y', locale=self._context.get('lang') or 'en_US')
|
||||
|
||||
elif interval == 'dayname':
|
||||
# Localized day name
|
||||
result = babel.dates.format_date(date=date, format='EEEE', locale=self._context.get('lang', 'en_US'))
|
||||
result = babel.dates.format_date(date=date, format='EEEE', locale=self._context.get('lang') or 'en_US')
|
||||
|
||||
elif interval == 'time':
|
||||
# Localized time
|
||||
|
||||
@@ -44,7 +44,7 @@ class Pricelist(models.Model):
|
||||
if name and operator == '=' and not args:
|
||||
# search on the name of the pricelist and its currency, opposite of name_get(),
|
||||
# Used by the magic context filter in the product search view.
|
||||
query_args = {'name': name, 'limit': limit, 'lang': self._context.get('lang', 'en_US')}
|
||||
query_args = {'name': name, 'limit': limit, 'lang': self._context.get('lang') or 'en_US'}
|
||||
query = """SELECT p.id
|
||||
FROM ((
|
||||
SELECT pr.id, pr.name
|
||||
|
||||
+1
-1
@@ -1846,7 +1846,7 @@ class BaseModel(object):
|
||||
if ftype == 'many2one':
|
||||
value = value[0]
|
||||
elif ftype in ('date', 'datetime'):
|
||||
locale = self._context.get('lang', 'en_US')
|
||||
locale = self._context.get('lang') or 'en_US'
|
||||
fmt = DEFAULT_SERVER_DATETIME_FORMAT if ftype == 'datetime' else DEFAULT_SERVER_DATE_FORMAT
|
||||
tzinfo = None
|
||||
range_start = value
|
||||
|
||||
Reference in New Issue
Block a user