콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
16046 화면

How to inherit a fields from one model to another model in odoo12

아바타
취소

For me this issue is not resolved as @mitul answer is right but when i try it ,it is still inheriting whole module .

베스트 답변

Hi, 

if you want to use other model's field in python side then use

class DemoClass(models.Model):

_inherit = 'fields.model'


# Here you can define method or any code to use field.

def demo_method(self):

print('field---->', self.field_name)


or you want to use in xml file then you have to inherit that view:

https://www.odoo.com/documentation/12.0/reference/views.html#inheritance

hope it will useful for you. 

Thanks..

아바타
취소
베스트 답변


Try Like this ...

class MyModelFoo1(models.Model):
_name = 'my.model.foo'

my_field1 = fields.Char()
my_field2 = fields.Char()
my_field3 = fields.Char()

class MyModelBar(models.Model):
_name = 'my.model.bar'

my_field4 = fields.Char()
my_field5 = fields.Char()
my_field6 = fields.Char()

class MyModelFoo2(models.Model):
_name = 'my.model.foo'
_inherit = ['my.model.foo', 'my.model.bar']

Here fileds of 'my.model.bar' will come under 'my.model.foo'.

Thanks !!!  

iWesabe

아바타
취소

How to create new view for these two inherited field model.

베스트 답변

hello 

for inherit only one field you can achieve this using  _inherits.

_inherits = {}              # inherited models {'parent_model': 'm2o_field'}

for eg. you can do like below code (in odoo there is already example in res.users object):

class Users(models.Model):
    _name = "res.users"
    _inherits = {'res.partner': 'partner_id'}
아바타
취소
베스트 답변

class ResUsers(models.Model):

_inherit = "res.users"

    age = fields.Float(string="Age")

아바타
취소
관련 게시물 답글 화면 활동
4
3월 24
3599
1
10월 23
5517
1
6월 22
6796
2
8월 17
12773
0
4월 16
3390