根据这个论坛功能领域:
“在调用创建、写入或任何其他 orm 方法时调用功能字段”
我已经测试了这个想法,我创建了一个函数字段,并且每次我(1)在列表/树上添加新项目或(2)编辑列表/树上的现有项目时都会调用它
但我想知道是否有办法在用户从树中删除项目时调用/调用功能字段?
class payment(osv.osv):
def _get_total_check_info(self, cr, uid, ids, field, arg, context=None):
"""
_get_total_check_info() :
Function that automatically computes for the Total Check Info upon saving
"""
result={}
check_amount = 0
for record in self.browse(cr, uid, ids, context=context):
for n in record.check_info_ids:
res = self.pool.get('cashier.check.information').browse(cr, uid, n.id)
if res:
check_amount += res['check_amount']
print "check_amount", res['check_amount']
print "check_amount Total", check_amount
result[record.id] = check_amount
return result
_name = 'payment'
_description = __doc__
_columns = {
'check_info_ids': fields.one2many('check.information', 'pymt_id', 'Check Information'),
'total_check_amount': fields.function(_get_total_check_info, method=True, type='float', string='Total Check Amount', store=True),
}
payment()
class check_information(osv.osv):
def unlink(self, cr, uid, ids, context=None):
"""
unlink():
Function used to override the unlink method
"""
#Your code goes here.
print "here at unlink function"
return super(check_information, self).unlink(cr, uid, ids, context=context)
_name = 'check.information'
_description = __doc__
_columns = {
'pymt_id': fields.many2one('payment', 'Payment ID'),
'check_date': fields.date('Check Date'),
'check_number': fields.char('Check Number', size=50),
'check_amount': fields.float('Check Amount', digits=(16, 2)),
'payee': fields.char('Payee', size=100),
'bank': fields.char('Bank', size=20),
'bank_branch': fields.char('Bank Branch', size=20),
}
check_information()