我需要计算 one2many 中的记录数,我可以使用以下方法来做到这一点:
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
尽管我需要做的是,如果取消链接记录并添加新记录,则下一条记录必须从 11 开始... & one2many 中的记录总数最多必须为 10 one2many 定义和类定义:
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'),
}