Odoo Help


A suggestion to add a new standard field to the ORM

Tarek Mohamed Ibrahim
on 4/10/16, 4:09 AM 716 views

I have a suggestion to add a new standard field 'is_default', which would be used to set the default record in a table, for example, if I have a table of fiscal years, and need to set the current default year I would use this record, which will be changed by the end of the year to select another record.

How to do that

But you can ALWAYS calculate the current fiscal year by using the CURRENT DATE and finding the year it is inside. A new field needs to be updated when the year changes.

Ray Carnes
on 4/10/16, 3:35 PM

Fiscal year is just an example, I needed to create a generic solution for the case of setting a record in a table as a 'Default' record.

Tarek Mohamed Ibrahim
on 4/11/16, 3:24 AM

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
| 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.



Tarek Mohamed Ibrahim
On 4/10/16, 4:22 AM

    add a new field to the base model, call it 'is_defaul'

    _columns = {


       'is_default': fields.boolean('Default', ),




create a new method  'set_default_record'

    def set_default_record(self, cr, uid, ids, vals):

        if 'is_default' in vals:

            if vals.get('is_default'):

                query = 'update your_module set is_default=False where id<>%s'%(ids[0],)



call this method from the create and the write methods

    def create(self, cr, uid, vals, context=None):

        context = context or {}

        res_id = super(your_module, self).create(cr, uid, vals, context=context)

        self.set_default_record(cr, uid, [res_id], vals)

        return res_id


    def write(self, cr, uid, ids, vals, context=None):

        context = context or {}

        res = super(your_module, self).write(cr, uid, ids, vals, context=context)

        self.set_default_record(cr, uid, ids, vals)

        return res

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

1 follower(s)


Asked: 4/10/16, 4:09 AM
Seen: 716 times
Last updated: 4/10/16, 4:22 AM