Ir al contenido
Menú
Se marcó esta pregunta
5 Respuestas
17625 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 19
3527
3
dic 22
4411
4
sept 19
4788
0
mar 15
4230
1
ago 23
3702