Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Only month and year in a date

By
Uillino
on 8/13/15, 8:12 AM 2,038 views

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!

0

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 8/13/15, 10:15 AM

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

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

Tarek Mohamed Ibrahim
on 8/13/15, 12:00 PM
0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/13/15, 10:25 AM

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.

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.

Uillino
on 8/14/15, 4:08 AM
0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 8/13/15, 12:04 PM

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 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/13/15, 8:12 AM
Seen: 2038 times
Last updated: 8/16/15, 4:02 AM