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.

1

Year only needed - how to implement?

By
Antanas
on 5/31/13, 8:52 AM 1,872 views

Hi,

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... ?

4

Andreas Brueckl

--Andreas Brueckl--
5056
| 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!

Antanas
on 6/3/13, 8:05 AM
-1
jsallent
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

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

0 follower(s)

Stats

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