Skip to Content
Menu
This question has been flagged
5 Replies
15725 Views

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
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
Related Posts Replies Views Activity
1
Nov 19
2613
3
Dec 22
3497
4
Sep 19
3767
0
Mar 15
3569
1
Aug 23
1916