Xavier (Open ERP) has proposed merging
lp:~openerp-dev/openobject-server/trunk-read_group-dates-formatting-xmo into
lp:openobject-server.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-read_group-dates-formatting-xmo/+merge/81909
Locale-aware date formatting in read_group
When grouping on a date or datetime field, read_group groups by (year, month),
and formats that pair to have a displayable result (as a group title).
This is currently done with strftime and the pattern `%B %Y` (complete word
month, long year), which is problematic as — at best — it uses the server's
locale for its formatting. This means if the server works in an english locale
e.g. russian users are going to see the month name in english, instead of their
own language.
This proposal makes use of `babel.dates.format_date`, which is locale-aware
(and to which a locale can be provided directly) and the locale present in the
request context to format the month, year pair according to the user's language.
--
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-read_group-dates-formatting-xmo/+merge/81909
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-server/trunk-read_group-dates-formatting-xmo.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2011-11-10 13:51:06 +0000
+++ openerp/osv/orm.py 2011-11-10 21:41:23 +0000
@@ -54,6 +54,8 @@
import traceback
import types
import warnings
+
+import babel.dates
from lxml import etree
import fields
@@ -2471,7 +2473,9 @@
dt = datetime.datetime.strptime(alldata[d['id']][groupby][:7], '%Y-%m')
days = calendar.monthrange(dt.year, dt.month)[1]
- d[groupby] = datetime.datetime.strptime(d[groupby][:10], '%Y-%m-%d').strftime('%B %Y')
+ date_value = datetime.datetime.strptime(d[groupby][:10], '%Y-%m-%d')
+ d[groupby] = babel.dates.format_date(
+ date_value, format='MMMM yyyy', locale=context.get('lang', 'en_US'))
d['__domain'] = [(groupby, '>=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-01', '%Y-%m-%d').strftime('%Y-%m-%d') or False),\
(groupby, '<=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-' + str(days), '%Y-%m-%d').strftime('%Y-%m-%d') or False)] + domain
del alldata[d['id']][groupby]
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp