This question has been flagged
1 Reply
10727 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 ?

Avatar
Discard
Author Best Answer

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)
Avatar
Discard

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

Author

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

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

Author

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

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?

Author

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