Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4698 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
říj 22
3072
2
kvě 23
5239
1
říj 22
4122
1
úno 17
3236
2
led 17
7072