跳至內容
選單
此問題已被標幟
5 回覆
17794 瀏覽次數

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...........

頭像
捨棄
最佳答案

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.
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 19
3623
3
12月 22
4512
4
9月 19
4886
0
3月 15
4340
1
8月 23
3880