Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1516 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
2448
2
ก.ค. 25
7906
2
ก.ค. 25
4313
2
ก.ค. 25
4059
2
มิ.ย. 25
2661