2

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:
4

2 回答 2

1

检查以下文件auction/report/buyer_form_report.sxw
[[ repeatIn(o['lots'],'oo') ]] [[ oo.obj_num ]]这里'oo'被定义并且它被称为[[ oo.obj_price + sum_taxes(oo) ]]

并且由于此报告已为模型注册:当用户单击报告时,auction.lots它将返回!!!BrowseRecordactive_id

于 2010-12-14T12:42:34.400 回答
1

它实际上并没有在该代码中调用该函数,该函数可能从报告中被调用并在那里传递 lot 参数。在您发布的代码示例中,它只是将一个函数指针放入上下文中。

有关 OpenERP 报告的更多信息,请查看开发人员手册的报告部分。我还发现在 Eclipse 中运行 OpenERP 服务器并在调试模式下逐步执行代码非常有帮助。然后您可以看到从哪里sum_taxes()调用该方法。

于 2010-12-14T20:02:41.853 回答