Help

0

multiple models inherited in a class

Avatar
Marychan

What should I do? Do i need to use inherits? 


If I will use inherits, how can I inherit the function and also the needed fields from each model from  the specific class, like this:


_name = 'newClassName'

_inherits = ['stock.picking', #1st model

'account.invoice'] #2nd model

min_date = fields.Datetime() #stock.picking field

date_invoice = fields.Date()#account.invoice  field


@api.multi

def _write(self,vals): #function from account.invoice

#codes...........

Avatar
Discard
2 Answers
0
Best Answer

Hi Marychan,

Try following code


class TestClass1(models.Model):
_name = 'test.class1'

name1 = fields.Char()

@api.multi
def my_new_fun(self):
print(self.name1)
# Your Main Class Method


class TestClass2(models.Model):
_name = 'test.class2'

name2 = fields.Char()


class TestClass3(models.Model):
_inherit = ['test.class1', 'test.class2']

@api.multi
def my_new_fun(self):
# You can Add your Functionality and also you can access name1 and name2 Variables here
print(self.name1, self.name2)
return super(TestClass3, self).my_new_fun()
Thanks.
Avatar
Discard
0
Avatar
Achuthan
Best Answer


class Test(models.Model):

_name = 'hr.employee'

_inherit = ['hr.employee','hr.employee.category']


3 Comments
Avatar
Discard