Odoo Help


Year only needed - how to implement?

on 5/31/13, 8:52 AM 2,602 views


I need to represent year only in module views (for example year of book publishing), what are the options? fields.date to store date, and then... ?


Andreas Brueckl

--Andreas Brueckl--

| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 5/31/13, 11:34 AM

You can use 2 columns, one date field for storing the data and one function field to extract the year :

def _get_year(self, cr, uid, ids, name, arg, context=None):

    values = self.read(cr, uid, ids, ['date'], context)
    res = dict(map(lambda x: (x['id'], x['date'] and x['date'][0:4] or False), values))

    return res

_columns = {
    'year': fields.function(_get_year, type='char', readonly=True, string='Year'),
    'date': fields.date('Date'),

Thank you very much!

on 6/3/13, 8:05 AM
On 9/10/14, 5:01 PM

Hello Andreas,

And how I could convert a date field in a Quarter field (YYYYQ1, Q2, Q3, Q4) in the same way with a function field?

Thanks in advance

Juan Sallent

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/31/13, 8:52 AM
Seen: 2602 times
Last updated: 3/16/15, 8:10 AM