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

Is it possibile to input only month and year in a date field?

Using tag 'date' I'm able to remove time. What about the day?

Thanks!

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

Friend follow this example:

import time

import datetime

from datetime import date

from datetime import datetime, date, time

ref_id = False

y = False

m = False

state = False

d = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

print d

d_ref = datetime.strptime("2011-01-11","%Y-%m-%d")

print d_ref

d_to = datetime.strptime("2012-01-31","%Y-%m-%d")

print d_to

if d_ref < d_to :

d_ref = d_to

y = d_to.year

m = d_to.month

day = d_to.day

print y

print m

print day

print d

print (str(y),str(m)))

Its really helpful to understand how it is functionning!!

Regards.

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

As Tarek said, this solve the print case, but don't the input one. I need to format on column of my db with year and month, without day.

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

Dear Uillino,

Yes its possible. Try below code

Step 1: Import this library.

from datetime import datetime

Updated Answer with input case:

Step 2: Define the field in python file.

'dob': fields.date('Date Of Birth'),

Step 3: Write the onchange method

def dob_changed(self,cr,uid,ids,dob,context=None):

    if context is None:

    context = {}

    if dob: # datestring = "2015-08-10" 

        date = datetime.strptime(dob, '%Y-%m-%d')

        year = date.year

        month = date.month

        print 'year and month', year, month

Step 4: Define the field in XML file.

<field name="dob" on_change="dob_changed(dob)"/>

Hope this may help you :) 

Thanks & Regards

Ankit H Gandhi

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

you resolved the 'print' case, what about the 'input' case in the question?

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

check this link, it does not contain an answer to your question, but it may guide you.

Also https://www.odoo.com/apps/modules/6.0/web_mask_widget/, I didn't try it, but I think it would be helpful

Another related link is this one 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 15
5277
3
thg 6 25
1296
3
thg 5 25
2017
1
thg 4 25
1509
1
thg 1 25
18081