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

StackOverflow https://stackoverflow.com/questions/23634646

  •  21-07-2023
  •  | 
  •  

Question

I created three classes like , ali_khan with an id ( 'ali_ids':fields.one2many('ali.khan', 'chbc_id', 'Ali khan'),, test_chbc and test_destitute. i referred that id in the rest two classes . i can add and delete records to tes_chbc but each time i try to add a record to test_destitute i get an integrity error..

my code:

class test_chbc(osv.osv):
    _name="test.chbc"
    _columns={
              'ali_ids':fields.one2many('ali.khan', 'chbc_id', 'Ali khan'),
              'first_name':fields.char('First Name',size=64),
              'family_name':fields.char('Family Name',size=64),
              'no_id':fields.boolean('No ID'),
              'id_num':fields.char('ID Number',size=64), #with a lable of ID Number yes/no
              'sex':fields.selection(gender_lov,'Sex',size=64),
              'date_o_birth':fields.date('Date of birth',size=64),
}    
test_chbc()

class test_destitute(osv.osv):
    _name="test.destitute"
    _columns={
              'ali_ids':fields.one2many('ali.khan', 'destitute_ids', 'Khan'),
              'first_name':fields.char('First Name',size=64),
              'family_name':fields.char('Family Name',size=64),
              'id_num':fields.char('ID Number',size=64), #with a lable of ID Number yes/no
              'sex':fields.selection(gender_lov,'Sex',size=64),
              'date_o_birth':fields.date('Date of birth',size=64),
              'formal_edu':fields.char('Formul Education',size=64),


    }
 test_destitute()

class ali_khan(osv.osv):
    _name="ali.khan"
    _description="Does any member of the household have regular paid employment"
    _columns={
              'destitute_ids':fields.many2one('test.destitute',reuired=True),
              'chbc_id':fields.many2one('test.chbc', required=True),    
              'person_name':fields.char('Name of Person'),
              'work_type':fields.char('Type of work'),
              'income_monthly':fields.char('Monthly Income'),
              'com_confirm':fields.char('Communal Confirmation'),
    }
 ali_khan()

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. [object with reference: chbc_id-chbc.id]

Note:

How i can set default values for many2fields , like chbc_id and destitute_ids

Was it helpful?

Solution

class ali_khan(osv.osv):
    _name="ali.khan"
    _description="Does any member of the household have regular paid employment"
    _columns={
              'destitute_ids':fields.many2one('test.destitute',required=True),
              'chbc_id':fields.many2one('test.chbc', required=True),    
              'person_name':fields.char('Name of Person'),
              'work_type':fields.char('Type of work'),
              'income_monthly':fields.char('Monthly Income'),
              'com_confirm':fields.char('Communal Confirmation'),
    }

I think you have miss spelled "required" in chbc_id field

OTHER TIPS

this error occurs when you didn't specify a value to required field

judt try to upgrade your module and then make sure that you enter a valid and existing value in the field chbc_id.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top