Skip to Content
Menu
This question has been flagged

Hi guys,

I've created a One2Many from the model res.partner to sel.patient.ziekenfonds.geschiedenis but when I want to save the record I will get the following error:

Integrity Error

The operation cannot be completed, probably due to the following:

- deletion: you may be trying to delete a record while other records still reference it

- creation/update: a mandatory field is not correctly set

The One2many on the model res.partner:

_inherit = 'res.partner'

lidnummer_ziekenfonds = fields.One2many('sel.patient.ziekenfonds.geschiedenis', 'ziekenfonds_id', 'Ziekenfonds')

The model sel.patient.ziekenfonds.geschiedenis with a Many2one to the model sel.ziekenfonds:

class sel_patient_ziekenfonds_geschiedenis(models.Model): _name = 'sel.patient.ziekenfonds.geschiedenis' ziekenfonds_id = fields.Many2one('sel.ziekenfonds',required=True,string='Ziekenfonds') lidnummer = fields.Char('Lidnummer') begindatum = fields.Date('Begindatum') einddatum = fields.Date('Einddatum')

The model sel.ziekenfonds:

from openerp import models, fields, api #Everything regarding ziekenfondsen class sel_ziekenfonds(models.Model): _name = 'sel.ziekenfonds' name = fields.Char('Naam',required=True)

So what exactly am I doing wrong or missing? I know I am missing something trivial but I just don't see it.

Yenthe

Avatar
Discard

Remove both required=True and test again.

Best Answer

Hi Yenthe

You have 2 errors or your code need some tweaks, let's view it separately

1- When you define the one2many field:

lidnummer_ziekenfonds = fields.One2many('sel.patient.ziekenfonds.geschiedenis', 'ziekenfonds_id', 'Ziekenfonds')

The inverse_name argument need to be a field that point back to the model that holds the one2many field, in this case res.partner so the field ziekenfonds_id need to be a many2one to res.partner or just add another many2one field that point to the res.partner model  and declared on the 'sel.patient.ziekenfonds.geschiedenis' and use it as inverse name of the one2many field lidnummer_ziekenfonds .
2- The field lidnummer_ziekenfonds is a one2many to the model sel.patient.ziekenfonds.geschiedenis but the defined model have the _name = 'sel.patient.fonds.geschiedenis', and don't match each other, in the field relationship should be changed to match correctly the model name
That's all what I see 


Avatar
Discard
Author

I was indeed missing the inverse field that should link to 'res.partner'. I've added a second Many2one from sel.patient.ziekenfonds.geschiedenis to res.partner and added this as an inverse field on the One2many! Thanks a lot Axel. Accepted & upvoted.

Related Posts Replies Views Activity
1
Mar 23
2163
0
Dec 22
2810
0
Jun 21
2812
1
Jul 20
21418
0
Jun 20
5297