作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据本论坛Functional Fields :
"functional fields are called while when a create,write or any other orm method called"
我已经测试了这个想法,我创建了一个函数字段,并且每次我都会调用它(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()
最佳答案
通过对象,您可以通过创建对象来调用功能字段的方法
def unlink(self, cr, uid, ids, context=None):
"""
unlink():
Function used to override the unlink method
"""
#Your code goes here.
lst_ids = []
for brw_rec in self.browse(cr, uid, ids, context=context):
print "here at unlink function"
lst_ids.append(brw_rec.pymt_id.id)
self.pool.get('payment')._get_total_check_info(cr, uid, lst_ids, 'total_check_amount', None, context=context)
return super(check_information, self).unlink(cr, uid, ids, context=context)
关于odoo - OpenERP : How to invoke a function every time the user deletes an item from a tree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14133216/
我是一名优秀的程序员,十分优秀!