跳至內容
選單
此問題已被標幟
2 回覆
1531 瀏覽次數

I have a M2O relation to account.move on a custom model:

invoice_id = fields.Many2one('account.move', string="Related invoices", ondelete='cascade', store=True)


and a O2M relation from account.move to my custom model:

rel_invoices = fields.One2many('inv.relations', 'id', string='Related Invoices', store=True)


But when I try to add related invoices, they are not saved.


How can I fix this?


Thank you


頭像
捨棄
最佳答案

Hi,

Can you try change field definition like below and check

rel_invoices = fields.One2many('inv.relations', 'invoice_id', string='Related Invoices', store=True)

Hope it helps

頭像
捨棄
作者

Thank you, but I get a KeyError "invoice_id"

作者

I don't have the KeyError anymore, but the wrong invoice is saved. When I add INV...0012 to INV...003, INV...003 is saved.

最佳答案

One2many fields aren't actually stored on the database table

頭像
捨棄
作者

Thank you, can u suggest a workaround?

you should set inverse_name as your many2one field in your custom module, don't add store ..
rel_invoices = fields.One2many(string='Related Invoices', comodel_name='inv.relations', inverse_name='invoice_id')

作者

The wrong invoice is saved now, when I add INV...0012 to INV...003, INV...003 is saved.

相關帖文 回覆 瀏覽次數 活動
1
7月 25
2500
2
7月 25
7940
2
7月 25
4379
2
7月 25
4091
2
6月 25
2688