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

Hello,

I have a model res.partner and i want to make relation in the same model. The relation is married_with.

So i created many2one field and i want when i change the field of an object it will change the field of the other object.

How to do that?

อวตาร
ละทิ้ง

Hello,

You want to add one more filed Many2one with the same reference(res.partner)

ผู้เขียน คำตอบที่ดีที่สุด

Sorry , but what I am looking for is how to make relation in the same model.

I have a model called Person inheriting from res.partner like that. I know that the relation ono2one is not available anymore.

So i choose to make a many2one field.And i want when i change the married_with field for the person x, , it will change for person y

class Person(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
    married_with = fields.Many2one('res.partner', ondelete='set null', string='Conjoint', index=True)
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You

When you change for example   the client, you want to change it with another field

1- You can link it to Related

for example 

    partner_id = fields.Many2one('res.parner', string="Partner")

    phone = fields.Char( string="Identification", related='partner_id .phone')

  phone This field is present in the model 'res.parner' 

2- the other solution by fuction On_change 



@api.onchange('partner_id')
def on_change_field(self):
    self.phone = self.partner_id.phone





อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

This should give you a clue:

field_of_other_obj = fields.Many2one('referencing.object')

@api.onchange('field_of_object')
def get_changes(self):
    if self.field_of_object:
        self.field_of_other_obj = self.field_of_object.pointed_field_obj

Make sure the "field_of_other_obj" model is the same with the pointed_field_obj.

If you need more clarity, feel free to ask with what you have done (code).

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ก.ค. 20
10733
0
พ.ย. 18
5538
0
ส.ค. 17
4223
2
ก.พ. 25
5196
1
ธ.ค. 24
1009