Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
5632 Widoki

 have a form which I pass some invoice ids through context by an act_window. Invoices are set as default in an many2many field (I tried both using a default function and overriding the default_get function), but when I add a record on another one2many field in the same form, the many2many field just get cleared (I suppose it refresh itself) It does not happen with other fields which also had defaults but just with the many2many.

Any ideas?


edit: seems that the many2many field disapearing is not related with being a default or not. It happens everytime a record in the other one2many field is inserted. But at the end of the day, when I save the whole record, the m2m records are not deleted on DB: when I open again the form, here there are again!

Awatar
Odrzuć
Autor

Pawan, I tried your solution in many ways but problems are: 1-in which part of the code I should save, as you proposed (tried onchange but it could be never triggered) 2-in which part of the code I should unlink the record if the user then decide to cancel the action? (I transformed the cancel button into a normal button in order to write the unlink code in its method, but what about the "X" button in the top-right of the form? plus, if there are required unset fields, it doesn't let me press "Cancel" at all because of validation)

as per what i got till now is that you want to populate a many2many field with some default values on opening of a form you are newly going to create(by clicking on create button)... isn't it?? if it is so, then for many2many field odoo creates a new table with the id of current record and the ids of many2many fields records. so for your problems: 1 - it will not be saved in that(new) table until n unless you save your current record, then everything will happen automatically. 2 - as its not saved till now u don't even need to unlink it also. for writing data to many2many field you have to use notations like : [(6,0, ids)], etc, you must be aware about.

Autor Najlepsza odpowiedź

Given the edit I did, I suppose this is just some kind of bug.

Awatar
Odrzuć
Najlepsza odpowiedź

Try saving the record, it(many2many field)will populate with the data you populated, as it needs an id of the parents record to save with in the new table(created as default odoo functionality for many2many field).

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sty 21
6000
1
lip 19
6593
1
lut 24
2121
2
gru 24
2174
2
kwi 23
9258