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.

0

how to override base class field ?

By
Nishant Kashyap
on 6/28/13, 5:49 AM 3,226 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

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

1 follower(s)

Stats

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