如何在报告上显示其他模型的数据(但没有ID相关) - OpenERP

时间:2014-04-02 05:04:47

标签: report openerp rml

我在account.invoice模块上创建报告 我尝试以sale.order形式显示一些数据 但在account.invoice表中没有order_id(与id相关) 如果我想在sale.order报告上显示account.invoice的某些数据,该怎么办? 但没有与sale.order相关的ID?

所以,如果account.invoiceorder_id(id相关),我可以使用

[[o.order_id._____]]

有人可以给我一些建议吗?

这是我的代码

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(order,self).__init__(cr, uid, name, context=context)
        so_origin = self.pool.get('account.invoice').browse(cr, uid, uid)
        so_obj = self.pool.get('sale.order').browse(cr, uid, so_origin.id)
        self.localcontext.update({
                'order_id': so_obj.id
        })

并在rml文件中

[[repeatIn(objects,'o')]]
[[o.order_id._______]]

1 个答案:

答案 0 :(得分:2)

只需编写一个设置销售订单browse_record的方法,就可以正常使用它。

class invoice_parser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(invoice_parser,self).__init__(cr, uid, name, context=context)
        self.order = False

        def setOrder(invoice_id):
            self.order = False
            so_obj = self.pool.get('sale.order')
            so_list = so_obj.search(cr, uid, [('invoice_ids.id','=',invoice_id)], context=context)
            # big question: what should be done with more than one sale order found
            # easiest solution: return True only when one was found
            if len(so_list) == 1:
                self.order = so_obj.browse(cr, uid, so_list[0], context)
                return True
            else:
                return False

        def getOrder():
            return self.order

        self.localcontext.update({
                'setOrder': setOrder,
                'getOrder': getOrder,
        })

现在您可以使用:

[[ setOrder(o.id) and getOrder().name or ' ']]

或者你想做什么。