0

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.

ASD
  • 25
  • 6

2 Answers2

0

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

Sidharth Panda
  • 404
  • 3
  • 17
  • Hi, I have already created that. Now, I wanted to add more stuff but I don't want to add to this class (as I was told not to change this). But create new class and then add more stuff which inherit/extend 'helpdesk.team and HelpdeskTeam. How can I do that? – ASD Mar 17 '23 at 10:11
  • simply create a new class name as `CustomHelpDesk` and inherit `helpdesk.team`, although this will add functionality to `helpdesk.team` model only. is this what you want to ask? – Sidharth Panda Mar 17 '23 at 10:51
  • No, I want the functionality of both helpdesk.team and HelpdeskTeam(models.Model). is this possible? – ASD Mar 17 '23 at 10:59
  • Also, I have created a new custome class which inherits/extend only helpdesk.team and added all the code of HelpdeskTeam(models. Model) and also added code for the new functionality but in this, I am not getting the self-object inside this method. So ,I am not able to run the loop like for team in self: – ASD Mar 17 '23 at 11:11
  • @ASD yes it will be done as i explained above – Sidharth Panda Mar 18 '23 at 11:05
  • @ASD if you create inherit `helpdesk.team` and you will loop in `self` the self object will be the values of the `helpdesk.team`. – Sidharth Panda Mar 18 '23 at 11:09
0

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
ipin
  • 61
  • 2