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

When I do research on a datetime field, I can not get the date , I want to do a search on a datetime field without taking into account the hours and minutes and without making the type date of field.

example : i have

    'date_visite' : fields.datetime(u'Date visite client'),

but in search view : i must type the compelete date with h:m:s to get the result for my search

i want not type h:m:s

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

Hi, At least you can answer if the answer is good or not, and in the first case, close the question by checking the grey "V" under the number of vote on the left of an answer. I verify all your questions and it seems you do not do it, You answer just to questions which are blocking the answer you stand, and after that, no comment, no thanks, nothink. I think you do not understand how works this forum, other contributors will appreciate this as they want ....

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

Hi,

use :

'date_visite' : fields.date('Date visite client'),

bye

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
You can use this if you want to filter Datetime field just by date:



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

To avoid change the type of the field, but keep the search excluding time part, I set into the search view 

<field name="date" widget="date"/>


and redefined into model

    def search_read(self, cr, uid, domain=None, fields=None, offset=0, limit=None, order=None, context=None):

        for d in domain:

            if d[0] == 'date' and d[1] == '=' and len(d[2]) == 10:

                d[1] = '>='

                domain += [['date','<=',datetime.combine(datetime.strptime(d[2],  "%Y-%m-%d").date(), time(23,59,59))).strftime("%Y-%m-%d %H:%M:%S")]]

                break

        return models.Model.search_read(self, cr, uid, domain=domain, fields=fields, offset=offset, limit=limit, order=order, context=context)


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 23
13890
1
thg 7 15
7222
2
thg 1 24
2673
2
thg 6 22
4609
2
thg 6 18
6143