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

hello,

i use current date time in python (time.strftime) without problem but i can't in XML file when i try to insert colors into tree view !

<tree string="Mission" colors="blue:datetime_field > time.strftime('%d-%m-%Y %H:%M:%S')">

i test datetime.datetime.now() and DateTime.today() but no result !

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

Hi

1.First create a compute field: 

current_time = fields.Datetime(string='Current time', compute='_get_current_time')


def _get_current_time(self):
for li in self:
li.current_time = fields.datetime.now()

2. Then use this in your xml:


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

Use the variable current_date instead of using other date calls. you will get the result

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

the current_date as a string of the form yyyy-MM-dd but i work with date time format like this ('%d-%m-%Y %H:%M:%S') and when i work with current_date there is a difference of 1 day because this function dont use time detail

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

In that case, you must create a customization for /web/static/src/js/view_tree.js Line 37.

Tác giả

Thank you for this post but in this file the creation of current_date is : current_date: new Date().toString('yyyy-MM-dd') you have an idea for creation of current_datetime with this format ('%d-%m-%Y %H:%M:%S') ?

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

Mehdi,

Use Date() for Kanban.

For tree comparison, use current_date. In any domain,can use datetime.datetime.now().strftime('%Y-%m-%d').

See for the Tasks as an example:

<tree fonts="bold:message_unread==True" colors="red:date_deadline and (date_deadline&lt;current_date)" string="Tasks">

Thanks.

Ảnh đại diện
Huỷ bỏ
Tác giả

the current_date as a string of the form yyyy-MM-dd but i work with date time format like this ('%d-%m-%Y %H:%M:%S') and when i work with current_date there is a difference of 1 day because this function dont use time detail

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 23
26603
1
thg 12 20
2776
1
thg 4 18
7897
3
thg 9 15
9737
2
thg 8 15
5562