Odoo Help

0

how to override base class field ?

By
Nishant Kashyap
on 6/28/13, 5:49 AM 4,158 views

Lets suppose I have a field in base module:

class base_module(osv.osv):
    _name="base.module"
    _columns={
                   'state':fields.selection([('open', 'No Recruitment'), ('recruit', 'Recruitement in Progress')], 'Status')                   
                   }

Now I want to override this same field by inheriting the above "base.module"

class inherit_module(osv.osv):
    _inherit="base.module"
    _columns={
                  'state':fields.selection([ ('open', 'No Recruitment'),\
                                         ('submitted','Submitted'),\
                                         ('hod_depart','HOD Approval'),\
                                         ('hr_approval','HR Approval'),\
                                         ('recruit','Recruitement in Progress'),\
                                         ],'Stages',)
                   }

I did this and when I check the table , I did not get the required result Am I doing right, or there is another way to achieve this , or is it not possible ?

1
Nishant Kashyap
On 6/28/13, 8:48 AM

Well, I got the solution, it is :

class inherit_module(osv.osv):
          _inherit="base.module"
          def __init__(self,pool,cr):
                del super(hr_kanak_job_positions, self)._columns['state'].selection[:]
                new_selection=[('open', 'No Recruitment'),\
                                         ('submitted','Submitted'),\
                                         ('hod_depart','HOD Approval'),\
                                         ('hr_approval','HR Approval'),\
                                         ('recruit','Recruitement in Progress'),]

               super(inherit_module, self)._columns['state'].selection.extend(new_selection)

Dear Nishanth,

Thanks for the solution. Can I change the type of the field also? If the field on base class is of type "char" , can I change it to "function" ?

GuruDev
on 8/12/13, 8:05 AM

You can hide that default field in your inherited view and then you can make a new functional field labeling same as the hidden field, And I hope you can achieve what you asked...

Nishant Kashyap
on 8/12/13, 8:09 AM

Dear Nishanth,

I have to do this for "product.product"

Based on the selection of a boolean type field...the "Product Name" field's behaviour should be changed.

If the boolean field is True, then "Product Name" field should be of type "fields.function"

If False, then its type should be of that of "Parent class's" ie of product.product.

This is my intention

GuruDev
on 8/12/13, 8:24 AM

This you can achieve by making two field and then showing them according to the boolean field selection using domain.For example: 'field1':fields.char('Field1',size=20) 'field2':fields.function('Field2' ..............) 'field3':fields.boolean('Field3') Now in the xml file: <field name="field3"/> <field name="field1" attrs="{'invisible': [('field3', '=', True)]}/> <field name="field2" attrs="{'invisible': [('field3', '=', False)]}/> In this way you can achieve what you are looking for ..

Nishant Kashyap
on 8/12/13, 8:34 AM

Dear Nishanth,

You are absolutely right. I could manage the visibility by "attrs" tag.

In my particular case, the -- The ""Product Name"" should be changed based on the selection. That means... CREATE and EDIT(write),...these functions should also be Overrided based on the Boolean Selection ?, Am I right?

GuruDev
on 8/12/13, 8:54 AM

I think you should post your question so that the requirement is better understandable .

Nishant Kashyap
on 8/12/13, 9:01 AM
GuruDev
on 8/12/13, 9:14 AM

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.

Register

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)

Stats

Asked: 6/28/13, 5:49 AM
Seen: 4158 times
Last updated: 3/16/15, 8:10 AM