Odoo Help

6

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

By
Yakito
on 3/16/13, 1:20 AM 2,403 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--
1852
| 5 4 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

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

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