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

Hi, I am using Odoo 14 I am trying to update a many 2 many field from Server Action, but it seems Odoo is protecting itself because it gets back in a second to the original values. I am trying to link an invoice to as sale order, so I am using:

record.write({'invoice_ids': [(3, 456)]}) #456 is the record of the invoice
raise Warning(record.invoice_ids)

The warning shows that the new Id has been appended to the current values, but if I check again in the next second, the values get back to the original. Any clue on how to make them persistent?

Thx.


Awatar
Odrzuć
Autor Najlepsza odpowiedź

Hi Jainesh Shah,

Thank you for your response. I tried what you suggest, but I receive the following User Errror: "You cannot delete an entry which has been posted once."

So I think that what this code tries to do is delete the records, maybe there is my error. I don't want to delete nor create records. I just want to create a relationship between the current record with another record throught its many2many field.

Explicitly, what I want to do is add two existing invoices to an existing sale order because my user mistakenlty created the invoice by duplicating the previous one. Any clue?

Best Regards!

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Oscar del Rio,

(3,id) will remove record from field but not permanently so if you want to remove this record permanently you can use (2,id) and (4,id) to add existing record in many2many field


Please refer below link for better understanding.
https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html?highlight=many2many#odoo.fields.Many2many

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 22
3072
2
maj 23
5239
1
paź 22
4122
1
lut 17
3236
2
sty 17
7072