Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
8449 Vizualizări

Hi,

I have a model A with a related one2many field (pics_ids) to another one2many field in Model B

client_id = fields.Many2one('res.partner', string='Client Visité')

pic_ids = fields.One2many(string='PIC', related='client_id.child_ids')

 The problem is when im trying to edit the related one2many records in model B throght model A , When saving, new record are normaly created , but exititng ones are being duplicated and not updated. Trying to dump that relation before saveing we got:

'pic_ids': [[0, 1033, {'phone': False, 'name': 'Alpha', 'email': False}]],

instead of getting : (NOTE the Mode 0 instead of mode 1)

'pic_ids': [[1, 1033, {'phone': False, 'name': 'Alpha', 'email': False}]],
Imagine profil
Abandonează
Cel mai bun răspuns

To have a consistent two directions relation you should use:

class A:
    field1 = fields.Many2One("B")

class B:
    field2 = fields.One2Many("A", inverse_name="field1")

 https://www.odoo.com/documentation/11.0/reference/orm.html#relational-fields

 

Imagine profil
Abandonează
Cel mai bun răspuns

Did you find the solution? I have the same issue... Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
iul. 20
10378
1
ian. 22
18563
0
apr. 21
2615
3
iul. 19
5467
2
oct. 23
2302