Odoo Help


Can I able to inherit only one method? [Closed]

on 4/1/13, 6:34 AM 4,825 views

The Question has been closed

Sudhir Arya (ERP Harbor Consulting Services)
on 04/18/2013 05:18:49


As we inherit particular field from target model, like this, _inherits = {'resource.resource':"resource_id"}

can I able to inherits a method only from targeted model?

_inherits = {'target.model':"_get_amount_calc"}

Does it possible ?

Note that you do not "inherit particular field", the field you specified, resource_id, should be the relational field in your model that links to the target model. All target model fields will be accessible from the new model.

Mohammad Alhashash
on 4/1/13, 10:36 AM

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 4/1/13, 6:53 AM

It's called method overriding. You can override any method of inherited class.

For example I want to override def _amount_all() of sale.order in my module:

def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
    #Todo code
    return res

If I want to call super(actual method in sale.order) I can call it by super keyword.

def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
    #Todo code
    super(sale_order, self)._amount_all(cr, uid, ids, field_name, arg, context=None)
    return res

You can refer Method Overriding.

My Question is, Can we able to inherit method via _inherits = {'target.model':"_get_amount_calc_method"}

only one method from targeted model, as we inherits only one field.

on 4/1/13, 7:53 AM

No. you can not. There is no term like inherit method. But what you are saying is called method overriding which is possible.

Sudhir Arya (ERP Harbor Consulting Services)
on 4/1/13, 8:35 AM

Mohammad Alhashash

--Mohammad Alhashash--
| 5 5 8
Giza, Egypt
--Mohammad Alhashash--


Mohammad Alhashash
On 4/1/13, 7:58 AM

No. Inheritance using _inherits only adds the fields to the new model. Actually you cannot "inherit particular field", all target model fields will be accessible from the new model.

The example field you specified, resource_id, must be the relational field in your model that links (many2one) to the target model record. You have to explicitly declare it in _columns.

If you want to access a method from the inherited model, you need to call it through the relation field.

For example, if you need to call the method target.model._get_amount_calc() in your method source.model.action1(), you can do something like this:

class source_model(osv.Model):
    _inherits = {'target.model':'resource_id'}
    def action1(self, cr, uid, ids, context=None):
        context = context or {}
        for line in self.browse(cr, uid, ids, context=context):
            amount = line.resource_id._get_amount_calc()



| 5 4 7
Baarn, Netherlands
On 4/1/13, 6:56 AM

It is possible to inherit just a method from a specific model.

You start with the regular inherit command (_inherit = 'model.model')

Than you copy the method definition you want to inherit.


class res_partner(osv.osv):

_inherit = 'res.partner'

def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):

  Do your thing

  res = super(res.partner, self).name_search(cr, uid, name, args = args, operator = 'ilike', context = context)

  do more things

  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

0 follower(s)


Asked: 4/1/13, 6:34 AM
Seen: 4825 times
Last updated: 3/16/15, 8:10 AM