openerp 报告中的函数调用

发布于 2024-10-07 20:26:43 字数 2423 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦行七里 2024-10-14 20:26:43

检查以下文件auction/report/buyer_form_report.sxw
[[ RepeatIn(o['lots'],'oo') ]] [[ oo.obj_num ]] 这里定义了 'oo',其调用方式类似于 [[ oo.obj_price + sum_taxes(oo) ]]

并且由于此报告是为模型注册的:auction.lots 它将返回 active_idBrowseRecord代码> 当用户点击报告时!!!

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 !!!

我不吻晚风 2024-10-14 20:26:43

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

有关 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文