Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

webkit report. get data from another model. odoo 8

By
Keywoker
on 12/31/14, 6:26 AM 1,048 views

hi everyone.

I have been using webkit report and, as far as I know, I can only get data from current model, pointed in the xml of reports description. ANd i know that I can get data using the link between models, but I don't know how to get data from the model which isn't linked with the current model.

I should underline - Webkit Reports!

Thank you so much.

P.S. I know that it's deprecated :) 

0
Timo Talvitie
On 1/2/15, 7:14 AM

Hi, you can do this by overriding the default report parser, and adding the desired data to the localcontext variable in its init method. Here's a python snippet that will hopefully help.

# -*- coding: utf-8 -*-
from openerp.report import report_sxw
from osv import osv

class sale_order_report_parser(report_sxw.rml_parse):
    
    def __init__(self, cr, uid, name, context):
               
       super(sale_order_report_parser, self).__init__(cr, uid, name, context=context)

       # Add a new key/value pair to localcontext. Instead of a simple string you can use self.pool.get here to access other models and pull data from there
       test = "Just testing"

       self.localcontext.update({'new_variable': test })

# Tell your report to use the new parser
report_sxw.report_sxw('your.report.name',
                       'sale.order', 
                       'path/to/your/makofile.mako',
                       parser=sale_order_report_parser)

 

After this, you can access new_variable in your mako file.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/31/14, 6:26 AM
Seen: 1048 times
Last updated: 4/6/15, 6:09 AM