跳至内容
菜单
此问题已终结
2 回复
4736 查看

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.


形象
丢弃
编写者 最佳答案

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!

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
10月 22
3104
2
5月 23
5312
1
10月 22
4146
1
2月 17
3251
2
1月 17
7097