Reputation: 1009
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:
Upvotes: 2
Views: 3810
Reputation: 56660
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.
Upvotes: 1
Reputation: 14335
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 the BrowseRecord
for the active_id
when user clicks on report !!!
Upvotes: 1