Help

2

Why is the date displayed like this? QWEB

Avatar
Benjamin Cherpas

Hi,


I want to display the activity date deadline but it takes a wrong format. I work on French odoo but the date is displayed in English, with the following format and time set to 00:00:00 but this is a date field not datetime...

Format : Wed Dec 18 2019 00:00:00 GMT+2

This is weird because even in my database, the date is displayed like 18/09/2019, so why is it displayed like that when I call the field in inherited qweb template?


Here is my qweb inheritance: 

<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="mail.KanbanActivityDropdown">
<t t-jquery=".fa-clock-o" t-operation="after">
<t t-if="log.date_deadline > new Date() and log.activity_type_id[1] != 3">
<span><t t-esc="log.date_deadline" /></span>
</t>
</t>
</t>
</templates>


Hope that anyone can help me. Thanks !


UPDATE: 

I already tried t-field, t-options, t-field-options with format or widget: no effect...


Bye.

1 Comment
Avatar
Discard
Avatar
faOtools
-

Try using the widget 'date', e.g.:

<span t-field="log.date_deadline" t-options='{"widget": "date"}'/>
2 Answers
1
Avatar
faOtools
Best Answer

Okay, it seems that is because of default: date is kept with time zone in the database (not UTC).

I guess the simplest way to replace timezone is to re-calculate date in Python (or alternative apply fields_utils in Javascript). Something like (not tested):

@api.multi
@api.depends("date_deadline")
def _compute_no_tz_date(self):
for record in self:
record.no_tz_date = fields.Date.to_string(record.date_deadline.date())
# perhaps also better to apply time zone transformation
# have a look at the method _compute_state_from_date in the same file
no_tz_date = fields.Date(compute=_compute_no_tz_date)

Then, this no_tz_date should be shown in XML just as a string without time or time zone



Avatar
Discard
0
Avatar
Benjamin Cherpas
Best Answer

It has no effect (see updated answer) I don't understand why...


UPDATE:

date_deadline field in MailActivity object (in mail_activity.py file):

date_deadline = fields.Date('Due Date', index=True, required=True, default=fields.Date.context_today)


Log declaration (I don't know if it is declared in some JS file or not):

<li t-if="!_.isEmpty(records)">
<ul class="nav o_activity_log">
<t t-foreach="_.keys(records)" t-as="key">
<t t-set="logs" t-value="records[key]" />
<li class="o_activity_label">
<strong t-attf-class="o_activity_color_#{key}">
<t t-esc="selection[key]" /> (<t t-esc="logs.length"/>)
</strong>
</li>
<li t-foreach="logs" t-as="log" t-att-data-activity-id="log.id" class="o_schedule_activity">
<div class="o_activity_title pull-left">
<span t-attf-class="fa #{log.icon} fa-fw" />
<strong>
<t t-esc="log.title_action or log.activity_type_id[1]" />
</strong>
<div>
<span class="fa fa-clock-o fa-fw" />
<span t-att-title="log.date_deadline"><t t-esc="log.label_delay" /></span>
<t t-if="log.user_id[0] != uid">
<span class="ml4 fa fa-user" />
<span><t t-esc="log.user_id[1]" /></span>
</t>
</div>
</div>
<div class="pull-right">
<span class="o_mark_as_done o_activity_link o_activity_link_kanban fa fa-check-circle fa-2x mt4" t-att-data-activity-id="log.id" title="Mark as done" />
</div>
</li>
</t>
</ul>
</li>

Thank you for help !

5 Comments
Avatar
Discard
Avatar
faOtools
-

Share then the field date_deadline Python declaration or Javascript code (depending on what is log - Odoo class or Javascript object).

Avatar
Benjamin Cherpas
-

Done. Thanks !

Avatar
Benjamin Cherpas
-

Thank you so much it works ! But I used from_string instead of to_string (sorry I can't reply your comment above, just mine). You have been helpful so I'm disappointed to not have enough karma to upvote your answer. Thaaaanks again !!!

Avatar
faOtools
-

You are welcome. As for karma: I upvoted your question - the situation is quite interesing. Besides, if you need karma in the Future, you can pass a few learning courses - https://www.odoo.com/slides/all

Avatar
Benjamin Cherpas
-

Oh nice! I'll think about that! Thanks a lot!

Regards.