openerp 报告中的函数调用
此 sum_taxes
方法如何获取其 lot
参数集?这是 openerp 中拍卖插件的代码示例。
import pooler
import time
from report import report_sxw
from osv import osv
class seller_form_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(seller_form_report, self).__init__(cr, uid, name, context=context)
lot=self.pool.get('auction.lots').browse(cr,uid,uid)
#address=lot.bord_vnd_id.address_get(self.cr,self.uid,[partner.id])
# partner=lot.bord_vnd_id.partner_id
# address=partner.address and partner.address[0] or ""
# street = address and address.street or ""
self.localcontext.update({
'time': time,
'sum_taxes': self.sum_taxes,
'sellerinfo' : self.seller_info,
'grand_total' : self.grand_seller_total,
# 'street':street,
# 'address':address,
})
def sum_taxes(self, lot):
taxes=[]
amount=0.0
if lot.bord_vnd_id.tax_id:
taxes.append(lot.bord_vnd_id.tax_id)
elif lot.auction_id and lot.auction_id.seller_costs:
taxes += lot.auction_id.seller_costs
tax=self.pool.get('account.tax').compute(self.cr,self.uid,taxes,lot.obj_price,1)
for t in tax:
amount+=t['amount']
return amount
def seller_info(self):
objects = [object for object in self.localcontext.get('objects')]
ret_dict = {}
ret_list = []
for object in objects:
partner = ret_dict.get(object.bord_vnd_id.partner_id.id,False)
if not partner:
ret_dict[object.bord_vnd_id.partner_id.id] = {'partner' : object.bord_vnd_id.partner_id or False,'lots':[object]}
else:
lots = partner.get('lots')
lots.append(object)
# buyer_ids=self.pool.get(auction.lots).read(cr,uid,lot)
return ret_dict.values()
def grand_seller_total(self,o):
grand_total = 0
for oo in o:
grand_total =grand_total + oo['obj_price']+ self.sum_taxes(oo)
return grand_total
report_sxw.report_sxw('report.seller_form_report', 'auction.lots', 'addons/auction/report/seller_form_report.rml', parser=seller_form_report)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
How is this sum_taxes
method getting its lot
parameter set? This is a code sample from the auction addon in openerp.
import pooler
import time
from report import report_sxw
from osv import osv
class seller_form_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(seller_form_report, self).__init__(cr, uid, name, context=context)
lot=self.pool.get('auction.lots').browse(cr,uid,uid)
#address=lot.bord_vnd_id.address_get(self.cr,self.uid,[partner.id])
# partner=lot.bord_vnd_id.partner_id
# address=partner.address and partner.address[0] or ""
# street = address and address.street or ""
self.localcontext.update({
'time': time,
'sum_taxes': self.sum_taxes,
'sellerinfo' : self.seller_info,
'grand_total' : self.grand_seller_total,
# 'street':street,
# 'address':address,
})
def sum_taxes(self, lot):
taxes=[]
amount=0.0
if lot.bord_vnd_id.tax_id:
taxes.append(lot.bord_vnd_id.tax_id)
elif lot.auction_id and lot.auction_id.seller_costs:
taxes += lot.auction_id.seller_costs
tax=self.pool.get('account.tax').compute(self.cr,self.uid,taxes,lot.obj_price,1)
for t in tax:
amount+=t['amount']
return amount
def seller_info(self):
objects = [object for object in self.localcontext.get('objects')]
ret_dict = {}
ret_list = []
for object in objects:
partner = ret_dict.get(object.bord_vnd_id.partner_id.id,False)
if not partner:
ret_dict[object.bord_vnd_id.partner_id.id] = {'partner' : object.bord_vnd_id.partner_id or False,'lots':[object]}
else:
lots = partner.get('lots')
lots.append(object)
# buyer_ids=self.pool.get(auction.lots).read(cr,uid,lot)
return ret_dict.values()
def grand_seller_total(self,o):
grand_total = 0
for oo in o:
grand_total =grand_total + oo['obj_price']+ self.sum_taxes(oo)
return grand_total
report_sxw.report_sxw('report.seller_form_report', 'auction.lots', 'addons/auction/report/seller_form_report.rml', parser=seller_form_report)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查以下文件auction/report/buyer_form_report.sxw
[[ RepeatIn(o['lots'],'oo') ]] [[ oo.obj_num ]]
这里定义了 'oo',其调用方式类似于[[ oo.obj_price + sum_taxes(oo) ]]
并且由于此报告是为模型注册的:
auction.lots
它将返回active_id
的BrowseRecord
代码> 当用户点击报告时!!!check following file auction/report/buyer_form_report.sxw
[[ repeatIn(o['lots'],'oo') ]] [[ oo.obj_num ]]
Here 'oo' is defined and its called like[[ oo.obj_price + sum_taxes(oo) ]]
and as this report is registered for the model:
auction.lots
it will return theBrowseRecord
for theactive_id
when user clicks on report !!!它实际上并没有调用该代码中的函数,该函数可能是从报告中调用的,并将批次参数传递到那里。在您发布的代码示例中,它只是将函数指针放入上下文中。
有关 OpenERP 报告的更多信息,请查看开发人员手册的报告部分。我还发现在 Eclipse 中运行 OpenERP 服务器并在调试模式下单步执行代码确实很有帮助。然后您可以看到
sum_taxes()
方法是从哪里调用的。It's not actually calling the function in that code, the function probably gets called from within the report and passes the lot parameter there. In the code example you posted, it's just putting a function pointer into the context.
For more info on OpenERP reports, check out the reports section of the developer book. I also find it really helpful to run the OpenERP server in Eclipse and step through the code in debug mode. Then you can see where the
sum_taxes()
method is being called from.