Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
11 Trả lời
54512 Lượt xem

Hi,

All fields with date (Order date, Scheduled date etc) are in format datetime. Can I change it to just date?

Here is screenshot:

https://www.dropbox.com/s/x8ps66k3xymhdn0/Screenshot 2016-11-14 11.44.57.png

Thanks,

Damian

Ảnh đại diện
Huỷ bỏ

Thanks for reply.

Do I need to change it in the code or somewhere in settings?



datetime.datetime.strptime(self.expiry_date, '%Y-%m-%d').date()

Câu trả lời hay nhất

If you only need change format of  Datetime to Date in view. You can use this code.
 

1 . For forms or tree view use widget ''date"

 <field name="date_from" string="Date" widget="date"/>

2 . For reports or qweb use

for t-esc              ->  <span t-esc="o.date_from" t-options='{"widget": "date"}'/>

for t-fields -> <span t-field="o.date_from" t-field-options='{"format": "dd-MM-yyyy"}'/>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
Change
date_order = fields.Datetime('Date')
to
date_order = fields.Date('Date')
Ảnh đại diện
Huỷ bỏ

This is good solution, however, it requires changing the python code.

Câu trả lời hay nhất

With Developer Mode active:

1. Settings --> Translations --> Languages.

2. Click on English (or the language you use).

3. Set Time Format to a space (it can't be blank).

Refresh the browser page or log out and back in.  In the screens and reports I tried after making this change, it worked fine - no times showed up where Datetimes were previously shown.   I didn't test exhaustively.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Damian,

You redefine to Datefield from Datetimefield

# Before
date_field = fields.Datetime('Date')


# After
date_field = fields.Date('Date')


Ảnh đại diện
Huỷ bỏ

Shameem, by doing this what will happen to past data?

Sorry I don't know the past data is converted or ignored

When changing a field type, existing data will be cleared

Câu trả lời hay nhất
This worked well. Thank you @Abhay !

<span t-esc="o.date_from" t-options='{"widget": "date"}'/>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

If you only need change format of Date or Datetime in view. You can use this code.

for report
<span t-field="o.date" widget="date" t-field-options="{'format': 'dd/MM/yyyy'}"/>
OR for view
<field name="o.date" widget="date" options="{'format': 'dd/MM/yyyy'}"/>
    

format: 'dd/MM/yyyy' will help you.

Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

https://apps.odoo.com/apps/modules/13.0/user_wise_datetime_format/

Ảnh đại diện
Huỷ bỏ