Thursday, 14 July 2016

How to show Datetime Field in Website / Front end Odoo


https://dedyyuristiawan.blogspot.co.id


Hello world. Today i've got problem with show field datetime in website. The problem is when you show datetime in website, date will show -7 hour,  +7 hour, etc. This problem is not bugs from Odoo,  cause in database Odoo data will save with GMT+0. Its not bugs, its a rule for the make our set datetime in anywhere easy. How can? yes when you show in backend is normal, datetime will show like your input, but when you want show in website is different, time will - 7 or something like that.

Ok lets make it clear. In this post i just want to show when i got problem with diatomite. Usually when we want to show datetime in website we use code like this. 

<tr t-foreach="split" t-as="line"> # looping model for get field
 <t t-set="no" t-value="no + 1"/>
 <td class="text-center"><span t-esc="no"/></td>
 <td class="text-center"><span t-esc="line.start_date"/></td>
 <td class="text-center"><span t-esc="line.end_date"/></td>
 <td class="text-center"><span t-esc="line.qty"/></td>
</tr>

line.end_date and line.start_date is my field. For the example in the backend i've input with 009-01-05 22:14:39, and when look into database time will save 009-01-05 22:07:39 its less 7 hour. Cause datetime will save with GMT+0. But why when in the backend will show 009-01-05 22:14:39 similar with i'd input in backend, Odoo will automatically convert time when you show in backend with this syntax <field/>. 

<field name="my_datetime"> #my_datetime is my datetime field in Odoo

so, its different when you show in website with syntax on the top or this syntax <span t-esc/>.

<span t-esc="line.end_date"/> #end_date is my datetime field in Odoo

datetime will show similar with database without automatically convert Odoo. In this case you don't need to change with javascript or make function python, you don't need this. Because Odoo have perfect syntax. This is it <span t-field="line.end_date"/> t-field

<span t-field="line.end_date"/> #end_date is my datetime field in Odoo. 

Perfect right, you don't need to make difficult to create function js or python you just need to use <t-field /> and datetime will show like your input (like what's you want). 

So the conclusion is when you want show Datetime field in backend you can use <field name="name_field"/> and different when you want show in website / front end you just use <t-field=name_field/> don't use the other. See yaa
Share:
Lokasi: Semarang, Semarang City, Central Java, Indonesia

2 comments:

  1. nice information please do the needful about reporting in odoo.

    ReplyDelete
  2. Great article! Thanks for sharing this informative article. Looking for the best MR App Development Company in Australia? Reach IDYA Technology.

    ReplyDelete


<br>


Advice for contacting me at dedyy54@gmail.com