Merge lp:~openerp-dev/openobject-server/trunk-date-format-aja into lp:openobject-server

Proposed by ajay javiya (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/trunk-date-format-aja
Merge into: lp:openobject-server
Diff against target: 59 lines (+34/-1)
1 file modified
openerp/osv/fields.py (+34/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-date-format-aja
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+179651@code.launchpad.net

Description of the change

Hello ,
Fix : date format should be, as per user preference language in breadcrumb.
Thank You.

To post a comment you must log in.
4924. By ajay javiya (OpenERP)

[IMP]: code

4925. By ajay javiya (OpenERP)

[MERGE]: with trunk

4926. By ajay javiya (OpenERP)

[MERGE]: with trunk

4927. By ajay javiya (OpenERP)

[IMP] code: date format

4928. By ajay javiya (OpenERP)

[MERGE]: with trunk

Unmerged revisions

4928. By ajay javiya (OpenERP)

[MERGE]: with trunk

4927. By ajay javiya (OpenERP)

[IMP] code: date format

4926. By ajay javiya (OpenERP)

[MERGE]: with trunk

4925. By ajay javiya (OpenERP)

[MERGE]: with trunk

4924. By ajay javiya (OpenERP)

[IMP]: code

4923. By ajay javiya (OpenERP)

[IMP]: code and remove unwanted import

4922. By ajay javiya (OpenERP)

[MERGE] : with trunk

4921. By ajay javiya (OpenERP)

[IMP]: dateformate as per user prefrence language in breadcrum

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/fields.py'
2--- openerp/osv/fields.py 2013-10-30 10:23:13 +0000
3+++ openerp/osv/fields.py 2013-11-01 06:33:18 +0000
4@@ -142,7 +142,7 @@
5 """
6 # delegated to class method, so a column type A can delegate
7 # to a column type B.
8- return self._as_display_name(self, cr, uid, obj, value, context=None)
9+ return self._as_display_name(self, cr, uid, obj, value, context)
10
11 @classmethod
12 def _as_display_name(cls, field, cr, uid, obj, value, context=None):
13@@ -333,6 +333,19 @@
14 exc_info=True)
15 return (context_today or today).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
16
17+ @classmethod
18+ def _as_display_name(cls, field, cr, uid, obj, value, context=None):
19+ if context is None:
20+ context = {}
21+ registry = openerp.modules.registry.RegistryManager.get(cr.dbname)
22+ lang_code = context.get('lang', 'en_US')
23+ date_format = tools.DEFAULT_SERVER_DATE_FORMAT
24+ lang = registry['res.lang'].search_read(cr, uid, [('code','=', lang_code)],['date_format'], context=context)
25+ if lang and len(lang) > 0:
26+ date_format = lang[0]['date_format']
27+ value = DT.datetime.strptime(value, tools.DEFAULT_SERVER_DATE_FORMAT).strftime(date_format)
28+ return tools.ustr(value)
29+
30 class datetime(_column):
31 _type = 'datetime'
32
33@@ -397,6 +410,26 @@
34 exc_info=True)
35 return timestamp
36
37+ @classmethod
38+ def _as_display_name(cls, field, cr, uid, obj, value, context=None):
39+ if context is None:
40+ context = {}
41+ registry = openerp.modules.registry.RegistryManager.get(cr.dbname)
42+ lang_code = context.get('lang', 'en_US')
43+ date_format = tools.DEFAULT_SERVER_DATETIME_FORMAT
44+ lang = registry['res.lang'].search_read(cr, uid, [('code','=', lang_code)],['date_format','time_format'], context=context)
45+ value = value.split('.')[0]
46+ if lang and len(lang) > 0:
47+ date_format = ('%s %s') % (lang[0]['date_format'] , lang[0]['time_format'])
48+ if isinstance(value, basestring):
49+ date = DT.datetime.strptime(value[:len((DT.datetime.now()).strftime(date_format))], tools.DEFAULT_SERVER_DATETIME_FORMAT)
50+ elif isinstance(value, time.struct_time):
51+ date = DT.datetime(*value[:6])
52+ else:
53+ date = DT.datetime(*value.timetuple()[:6])
54+ value = DT.datetime.strptime(str(cls.context_timestamp(cr, uid,timestamp=date,context=context).replace(tzinfo = pytz.utc)), ('%s%s') % (tools.DEFAULT_SERVER_DATETIME_FORMAT,'+00:00')).strftime(date_format)
55+ return tools.ustr(value)
56+
57 class binary(_column):
58 _type = 'binary'
59 _symbol_c = '%s'