Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
16004 มุมมอง

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")

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
มี.ค. 24
3531
1
ต.ค. 23
5468
1
มิ.ย. 22
6720
2
ส.ค. 17
12748
0
เม.ย. 16
3356