I need to count the no of records in one2many which i am able to do by using the method:
def update_cust(self,cr,uid,ids,context=None):
current_obj = self.browse(cr,uid,ids[0])
one2many_ids=self.pool.get('customer.test').search(cr,uid,[], count=True)
if one2many_ids==0:
one2many_ids=1
count=one2many_ids
elif one2many_ids<11:
one2many_ids=one2many_ids+1
count=one2many_ids
elif one2many_ids==11:
return True
elif not one2many_ids:
count=one2many_ids=11
else:
one2many_ids=12
count=one2many_ids
self.pool.get('customer.test').create(cr,uid,{
'cust_id':current_obj.id,
'customer':current_obj.customer.id,
'street':current_obj.street,
'phone':current_obj.phone,
'cust_address':current_obj.cust_address.id,
'code':count-1
})
return True
Although what i need to do is, incase one unlinks a record and add a new record the next record must continue from 11... &the total number of records in one2many must be 10 at most one2many definition & class definition:
class customer_test(osv.osv):
_name="customer.test"
_columns={
'customer':fields.many2one('res.partner','Customers',ondelete="cascade"),
'cust_id':fields.many2one('customer.test','CustId'),
'street':fields.char('Street',size=40),
'phone':fields.integer('Phone'),
'cust_address':fields.many2one('res.partner.address','Address'),
'cust_address2':fields.many2one('res.partner.address','Secondary Address'),
'cust_one2many':fields.one2many('customer.test','cust_id',''),
'code' : fields.integer('Code'),
}
def update_cust(self,cr,uid,ids,context=None):
current_obj = self.pool.get('customer.test').browse(cr,uid,ids[0])
code=current_obj.code+1
count=one2many_ids=self.pool.get('customer.test').search(cr,uid,[('cust_id','=',current_obj.id)], count=True)
vals=self.pool.get('customer.test').search(cr,uid,[('id','=',current_obj.id)])
sequence_obj = self.pool.get('customer.test')
seq_id = sequence_obj.search(cr, uid, [('id', '=', current_obj.id)])
if count==0:
sequence_obj.write(cr, uid, seq_id, {'code': 1})
while current_obj.id in vals and count < 10:
sequence=self.pool.get('customer.test').browse(cr,uid,ids[0]).code
self.pool.get('customer.test').create(cr,uid,{
'cust_id':current_obj.id,
'customer':current_obj.customer.id,
'street':current_obj.street,
'phone':current_obj.phone,
'cust_address':current_obj.cust_address.id,
'code':sequence})
sequence_obj.write(cr, uid, seq_id, {'code': sequence+1})
return True
return True
Thats the solution for my question