I have created on2many field in class A and other field nombre (integer):
'Inventaire' : fields.one2many('class.b','id_classb'),
'nombre' : fields.integer('Nombre'),
In class b :
'id_classb' : fields.many2one('class.a', 'ID_classA'),
'ql' : fields.integer('QL'),
I want to create a function in class a that create records for object b according to the value of nombre field. for example if nombre =3 I should create 3 object of class b
here is my function:
def save_b(self, cr, uid, ids, field_name, arg, context):
a= self.browse(cr, uid, id)
nbr=a.nombre
num=22
for i in range(nbr):
num+=1
self.create(cr, uid, [(0, 0,{'ql':num})])
I get these errors :
TypeError:range()integer expected ,got NoneType
ValueError: dictionary update sequence element #0 has length 3; 2 is required
can someone help me to improve my function?
You have following errors:
Your create call values should be a dictionary with field names as keys, not a list with tuples. The notation you are using is for writing/updating one2many fields.
You are not creating ‘class b’ records, but creating ‘class a’ records instead (using self instead of a self.pool.get call)
So you should write
Or as an alternative:
Remark: In class b your link to class a is in column named ‘id_classb’? The openerp-etiquette expects you to name them ‘classa_id’ or something similar.
Also, creating column names with capitals is frowned upon.