ASD
ASD

Reputation: 47

Inherit/extend the class in odoo

I have a class that extends the other class by providing the _inherit=[helpdesk.team] in odoo. It did not have _name attribute in this class. This class has a method that adds stuff to the parent helpdesk.team. Now, I want to add some more stuff but I don't want to change in existing class and want to add a new class that extends both the above class. is it possible? How can I do it?

Thanks.

Upvotes: 0

Views: 655

Answers (2)

ipin
ipin

Reputation: 93

You can have both _name and _inherit on your new class (third class). Your new model will have the entire properties of the model you inherit, including the second class that you extend from the first one, without altering the properties of the first model. On your third class, I think you need to depend to those two modules defining the first and second class. Here an example:

class A(models.Model):
    _name = 'model.a'
    property_a = fields.Any()
    def do_stuff(self):
        pass

class B(models.Model):
   _inherit = 'model.a'
  
   more_property = fields.Any()

   def do_stuff(self):
       # do any other stuff
       super(B, self).do_stuff()


  class C(models.B)
      _name = 'model.c'
      _inherit = ['model.a', 'any.other.model.you.want']

      property_c = fields.Any()
      def do_stuff(self):
         super(C, self).do_stuff() # this will call the method defined in class A and class B
         # do more stuff
    
      def do_something_only_in_c(self):
          pass

Upvotes: 0

Sidharth Panda
Sidharth Panda

Reputation: 716

from the question what i understood is you want to add some stuff to a existing model in odoo

if I am right then you can do it using _inherit like for eg.

class HelpdeskTeam(models.Model):
    _inherit = 'helpdesk.team'

    def your_method(self):
        your_code = write your method here
        return your_code

it will reflect in helpdesk.team

Upvotes: 0

Related Questions