lims_report_html: Improve datetime filter converting to company timezone
This commit is contained in:
parent
53d2c27afc
commit
179d6d00f1
|
@ -503,13 +503,14 @@ class LimsReport(Report):
|
|||
@classmethod
|
||||
def get_lims_filters(cls):
|
||||
Lang = Pool().get('ir.lang')
|
||||
Company = Pool().get('company.company')
|
||||
|
||||
def module_path(name):
|
||||
module, path = name.split('/', 1)
|
||||
with file_open(os.path.join(module, path)) as f:
|
||||
return 'file://%s' % f.name
|
||||
|
||||
def render(value, digits=2, lang=None, filename=None, date_format=None):
|
||||
def render(value, digits=2, lang=None, company=None, filename=None, date_format=None):
|
||||
if value is None or value == '':
|
||||
return ''
|
||||
|
||||
|
@ -526,14 +527,14 @@ class LimsReport(Report):
|
|||
|
||||
if hasattr(value, 'rec_name'):
|
||||
return value.rec_name
|
||||
|
||||
|
||||
if isinstance(value, datetime):
|
||||
if company:
|
||||
value = company.convert_timezone_datetime(value)
|
||||
return lang.strftime(value, format=date_format)
|
||||
if isinstance(value, date):
|
||||
return lang.strftime(value, format=date_format)
|
||||
|
||||
if isinstance(value, datetime):
|
||||
return '%s %s' % (lang.strftime(value, format=date_format),
|
||||
value.strftime('%H:%M:%S'))
|
||||
|
||||
if isinstance(value, str):
|
||||
return value.replace('\n', '<br/>')
|
||||
|
||||
|
@ -562,10 +563,15 @@ class LimsReport(Report):
|
|||
|
||||
locale = Transaction().context.get('locale').split('_')[0]
|
||||
lang, = Lang.search([('code', '=', locale or 'en')])
|
||||
company_id = Transaction().context.get('company')
|
||||
company = None
|
||||
if company_id:
|
||||
company = Company(company_id)
|
||||
# now = company.convert_timezone_datetime(now)
|
||||
|
||||
return {
|
||||
'modulepath': module_path,
|
||||
'render': partial(render, lang=lang),
|
||||
'render': partial(render, lang=lang, company=company),
|
||||
'subrender': subrender,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue