This question has been flagged
3 Replies
7347 Views

Hello,

I want to make relation one2one in the same model 'person' which inherit from 'res.partner' .
I know that one2one is not available any more so what's the solution?
The relation is "married_with". So i want when i change the field of the person A to B. B "married_with" field automatically changes

class person
       inherit = 'res.partner'
       married_with =.........


Is it possible to do it and how? 


Avatar
Discard
Best Answer

Dear Mohamed,

Try to use Related Field Related Field Link


Hoping to Solve the issue,


You can Use Onchange Function :

married is Many2one with same model:


@api.onchange('married')

def onchange_married(self):

    self.married.married= self.id


Try it


Avatar
Discard
Author Best Answer

Dear Boubaker and Aymen

I don't think that related field will solve my problem because what i am looking for is not how to get the field of the other record.

I want when i link the record A with record B, record B will be linked with A.
A.married_with(B)   ====>   B.married_with(A)
I hope that my problem is clear

Avatar
Discard

Pls Check the answer ...

Author

I try it but it doesn't resolve the problem

Author

Dear Aymen

I have an idea. But i don't know how to do it.

How about adding a one2many to my "married_with" many2one field, make relation and when the one2many is changed i will use the first line to update my many2one field is it possible?

Best Answer

Hi Mohamed Ali 

When you change for example   the customer, 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="Phone", related='partner_id .phone')

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

2- the other solution by Methode On_change 

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


Avatar
Discard