Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
5099 Visualizzazioni

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.


Avatar
Abbandona
Autore Risposta migliore

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!

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ott 22
3340
2
mag 23
5621
1
ott 22
4358
1
feb 17
3411
2
gen 17
7342