跳至内容
菜单
此问题已终结
3 回复
8705 查看

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? 


形象
丢弃
最佳答案

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


形象
丢弃
编写者 最佳答案

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

形象
丢弃

Pls Check the answer ...

编写者

I try it but it doesn't resolve the problem

编写者

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?

最佳答案

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


形象
丢弃
相关帖文 回复 查看 活动
0
9月 19
98
0
11月 18
5858
0
10月 18
3781
1
7月 17
4189
4
8月 16
8404