gpt4 book ai didi

odoo - OpenERP : How to invoke a function every time the user deletes an item from a tree

转载 作者:行者123 更新时间:2023-12-02 15:55:58 24 4
gpt4 key购买 nike

根据本论坛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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com