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.

6

Is it possible for a report to use data from two unrelated tables?

By
Yakito
on 3/16/13, 1:20 AM 2,118 views

Hello,

I don't seem to finish understanding how reports work, or at least how to make them work in the way I need.

I developed a custom module with multiple tables, and what I need is a report which takes data from different queries to those tables and then produce a PDF. I understand how to do it for just 1 table.

In my ideal scenario I would create different queries to each table and then produce a report.

I don't seem to find a way to include in a report data from tables which have no relationship between them.

For example lets say I have a table for "Expenses" and another one for "Income". They don't have a common key between them. Is there any type of report I could use to produce a PDF with the query to both tables?

Thanks for any tip!

7

Davide Corio

--Davide Corio--
1822
| 4 3 7
Bricherasio, Italy
--Davide Corio--

Odoo Evangelist and Consultant

Davide Corio
On 3/16/13, 5:31 AM

By default in your reports, you can access all the object linked to the main object (o, the one you associated the report to, i.e. an invoice).

This means for instance, that you can access the partner object by doing o.partner_id, and a partner category object with o.partner_id.category_id.

Since there are fields related to accounting on the partner form, you can access this way more or less every object.

But, if you don't want to take this "dirty" way, you can use a parser.

Take the invoice report definition for instance (addons/account/report/account_print_invoice.py):

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
        })
report_sxw.report_sxw(
    'report.account.invoice',
    'account.invoice',
    'addons/account/report/account_print_invoice.rml',
    parser=account_invoice
)

the self.localcontext is always passed to the report, then you put a key (i.e. sale_orders) inside this dict, with value all the SOs i need.

Obviously, you'll have to populate this value with the list of object you need loop on. And you can do this by searching the sale orders with, for instance:

from openerp import pooler
pooler.get_pool(self.cr.dbname).get('sale.order').search(self.cr,self.uid,[])

Inside [] you can put your domain to filter the results.

This way you can print whatever you like in your report.

Thanks a lot Davide! I might have to ask more questions along the way, but just even knowing it is possible is a very good news. I will be doing test during the weekend.

Yakito
on 3/16/13, 9:14 AM

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

0 follower(s)

Stats

Asked: 3/16/13, 1:20 AM
Seen: 2118 times
Last updated: 3/16/15, 8:10 AM