Tryton - Issues

 

Issue8444

Title Extend format_date function to allow a format other then the default
Priority feature Status resolved
Superseder Nosy List ced, edbo, reviewbot, roundup-bot
Type feature request Components trytond
Assigned To edbo Keywords review
Reviews 279611002
View: 279611002

Created on 2019-06-20.14:42:49 by edbo, last changed by roundup-bot.

Messages
New changeset 07e1d03acf76 by C├ędric Krier in branch 'default':
Add format argument to Report.format_date
https://hg.tryton.org/tryton-env/rev/07e1d03acf76
New changeset d3b479ec1e5a by EdbO in branch 'default':
Add format argument to Report.format_date
https://hg.tryton.org/trytond/rev/d3b479ec1e5a
review279611002 updated at https://codereview.tryton.org/279611002/#ps257751002
review279611002 updated at https://codereview.tryton.org/279611002/#ps275691002
review279611002 updated at https://codereview.tryton.org/279611002/#ps287701002
review279611002 updated at https://codereview.tryton.org/279611002/#ps257671002
New review279611002 at https://codereview.tryton.org/279611002/#ps283581002
msg50356 (view) Author: [hidden] (edbo) Date: 2019-06-21.13:01:26
I created https://codereview.tryton.org/279611002
msg50333 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2019-06-20.16:19:32
See https://discuss.tryton.org/t/guide-to-get-a-basic-development-environment/1444/16?u=ced
msg50332 (view) Author: [hidden] (edbo) Date: 2019-06-20.15:50:32
I follewed http://www.tryton.org/develop to get the sources. Then I made the changes and want to submit them. But I get:

upload.py: error: --oauth2_port option requires an argument

Also the wiki https://github.com/rietveld-codereview/rietveld/wiki/upload.py-Usage is not very helpful. I also joined the discussion on https://discuss.tryton.org/t/guide-to-get-a-basic-development-environment/1444/12
msg50331 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2019-06-20.14:53:21
Why not. Please follow http://www.tryton.org/develop
msg50330 (view) Author: [hidden] (edbo) Date: 2019-06-20.14:42:49
Sometimes when you create a report you have dates on it. To get the date right for the language you use format_date to get the date. 
However if you want to have a portion of the date or want a different format then the default one, you can't.

Digging a bit deeper in the report.py I saw that format_date calls strftime in ir.lang. And that part actually accepts a format which is default None.

I propose to also extend the format_date function with the format=None so nothing breaks, but allows the user to add their own format.

So format_date (in report.py) WAS:
@classmethod
def format_date(cls, value, lang=None):
    pool = Pool()
    Lang = pool.get('ir.lang')
    if lang is None:
        lang = Lang.get()
    return lang.strftime(value)

and BECOMES:
@classmethod
def format_date(cls, value, lang=None, format=None):
    pool = Pool()
    Lang = pool.get('ir.lang')
    if lang is None:
        lang = Lang.get()
    return lang.strftime(value, format=format)
History
Date User Action Args
2019-07-17 01:03:06roundup-botsetmessages: + msg50682
2019-07-17 00:58:08roundup-botsetstatus: testing -> resolved
nosy: + roundup-bot
messages: + msg50680
2019-07-12 14:42:44reviewbotsetmessages: + msg50631
2019-07-08 23:10:18reviewbotsetmessages: + msg50577
2019-07-08 18:14:44reviewbotsetmessages: + msg50554
2019-06-28 22:16:50cedsetstatus: chatting -> testing
assignedto: edbo
2019-06-28 15:53:21reviewbotsetmessages: + msg50449
2019-06-21 15:37:53reviewbotsetnosy: + reviewbot
messages: + msg50358
2019-06-21 15:37:52reviewbotsetreviews: 279611002
keyword: + review
2019-06-21 13:01:26edbosetmessages: + msg50356

Showing 10 items. Show all history (warning: this could be VERY long)