Search code examples
odooopenerp-7openerp-8rml

RML report openerp 7


How to get the field which is present in sale.order in invoice report. So invoice report use the model account.invoice, if i add a function in report.py it allow only self.cr,self.uid because we are not using osv.memory. So how to get the value of cust_ref_value from sale.order to invoice report.


Solution

  • We can track from the Source Document

    In report.py we need to make a function and pass origin in it.

    def __init__(self, cr, uid, name, context):
        super(your_report_calss_name, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'time': time, 
            'get_cust_ref_val': self._get_cust_ref_val,
        })
    

    This method will check like origin is SO or PO or OUT/###:SO### or IN/###:PO### so following case be here

    def _get_cust_ref_val(self, origin)
        if 'SO' in origin:
            if 'OUT/' in origin:
                so_name = str(origin).split(':')[1]
                sale_id = self.pool.get('sale.order').search(self.cr, self.uid, [('name', '=', so_name)]
                if sale_id:
                    sale = self.pool.get('sale.order').browse(self.cr, self.uid, sale_id)
                    return sale.cust_ref_value
            else:
                sale_id = self.pool.get('sale.order').search(self.cr, self.uid, [('name', '=', origin)]
                if sale_id:
                    sale = self.pool.get('sale.order').browse(self.cr, self.uid, sale_id)
                    return sale.cust_ref_value
        else:
            return ''
    

    and from the rml side

    [[ get_cust_ref_val(inv.origin) ]]