Odoo Help


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.


Add Field type year

Ajeng Shilvie
on 12/17/14, 6:06 AM 636 views

i want to add field and value just year with code python and xml..

ok thank you

Ajeng Shilvie
on 12/17/14, 7:00 AM

Med Said BARA

--Med Said BARA--
| 5 5 7
--Med Said BARA--
Med Said BARA
On 12/17/14, 10:12 AM

Maybe you can use:  'year': fields.selection([(y, str(y)) for y in range(1970, (datetime.now().year + 30)+1 )], 'Year'),

Range from 1970 to 2044 (Adjust your range as you want)

and in the .xml file just add your field somewhere in your view:  <field name="year" />



| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 12/17/14, 6:14 AM

easiest way is to add : 
'year':fields.char('Year', size="4")

aternative can be fields.integer('"Year")

both would need with some validity check on write 
adding field of type date will add full date format, and on view it will be shown as calendat widget...

Ait-Mlouk Addi
On 12/17/14, 7:08 AM

in your python file it seems this :

class model_name(osv.osv)

      _name = "model.name"

     _description = "description for model"

    _columns = {

                  'year':fields.char('Year', size="4"),



in your xml form view description it seems this :

    <!-- form -->   
    <record model="ir.ui.view" id="id_model_form">
            <field name="name">model.name.form</field>
            <field name="model">model.name</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="descripti" version="7.0" > 
                                <field name="year" />


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

2 follower(s)


Asked: 12/17/14, 6:06 AM
Seen: 636 times
Last updated: 3/16/15, 8:10 AM