Creating custom reports in Odoo 8

Hi guys

In this tutorial you will learn how to create a new QWeb report from scratch.
During this tutorial I will create a second invoice report, but this time without prices. Some companies do not want to show prices per record for example, so I’ll take this as a sample.

1. Creating a new XML file

The first step to create your own new report is to make a new XML file. This file should be placed under yourModuleName/views and you can name it as you wish. In this tutorial I will create a new invoice that is made in the module account.
I’ve named the file report_without_prices.xml as you can see here:
View structure

In this file you will define the template id’s and names, which will later on be used by your Odoo to find the correct report.
The minimal code looks like this:

So, what is important about this? The name of the template id (from the first record) should be the same as the name for the t-raw that handles translations. In the t-raw you need to add the module name before this name with a dot. Here’s an image to make things more clear:
Code structure
The second template_id then needs to be identical to the name that you will set in the next file. So let us continue.

2.Add the report to the XML file responsible for reports

This brings us to part 2. Every module has a file that makes a reference to every single report in the module. This is done by a item, which can be found in the XML file.
This file always has the same name structure. It starts with the name of your module, an underscore and then report.xml. Its found in the first level of the directory of your module, as you can see here:
XML file for reports
The filename is always yourModuleName_report.xml. Now open up this file and you will see a tag for every report that exists in this module.
The next step for us is to add a new tag for our own report. The code looks like this:

Now that you’ve added this code you’re almost there! The last step is to notify Odoo of the new report.

3. Notify Odoo from the new report

So how do we tell Odoo there is a new report? In every module is a file named __openerp__.py. This file is used to import (include) all files in a module.
As all files are loaded in here we should also add our new XML file in this list. Without this Odoo will not find or use the XML file which will result in a not working report and errors.
Add a new line to the __openerp__.py file, right under ‘data’:[

4. Wrapping things up

Now that you’ve made a new report (a new XML file),added the template id to the moduleName_report.xml file and added your XML file to __openerp__.py you’re done!
The last thing you need to do is reload your module (by command or by a module update) and you’ll see the new report showing up.
If you then look under accounting > Customer Invoices and make a new invoice you will see your new print option:
Print option custom report

And, finally, if you print it out you’ll get your custom report!
Custom report lay-out

NOTE:If you want a more advanced code, which shows a full report without the prices just paste this code in reports_without_prices.xml

Looking for more information about reports?
Check out the official documentation




Odoo Experts

32 thoughts on “Creating custom reports in Odoo 8

  1. qubi says:

    Hi there. Thanks a lot for the great tutorial.

    I wanted to ask you how to insert an image to a pricelist qweb report. I’ve been fooling around with the code, but only to break it badly. Also, is there a manual or some sore of info aout there where we can find all variables that can be used in qweb reporting?

    Much appreciated your help. Cheers

  2. midfox says:

    Hi Yenthe666 & josef !

    First, thanks for you tutorial, unfortunetely it doesn’t work for me…
    As I have a doubt about how to reloading module, and so I decided to restart odoo service, but it still doesn’t work…

    I noticed a difference between you screenshot and mine on step 4 : there is no “Attachments” button after “Print” combo ; is it in relation with my problem ?

    • Yenthe666 says:

      Hi midfox,

      Restarting your Odoo service doesn’t do enough. This will not update your module and reload all the Python files. You should go to settings and click on ‘Update Modules List’. After this find the module from the apps list, open it and click on ‘Upgrade’. The new report should then show up!

      • midfox says:

        Hi,
        Thanks for the precisions, I had already made this before, without success 🙁 Unless I’m editing files in a wrong path, I don’t know where to search…
        I have a fresh install made by apt-get install (on Debian Jessie), and modules path in /usr/lib/python2.7/dist-packages/openerp/addons/account
        Thanks…

        • Yenthe666 says:

          You should have another Odoo path where everything is at. Something like /odoo/odoo-server/addons.

  3. Randy says:

    Hi, I tried to implement this on my own custom module.
    My file is master.py, inside there is a class

    class mmr_product(osv.osv):

    _name = “mmr.product”
    _description = “Product Module for PT.MMR, refer to Product doc.”

    _columns = {
    ‘brand’: fields.many2one(“mmr.brand”, “Brand”, required=True),
    ‘name’: fields.char(“Name”, required=True),
    ‘unit’: fields.many2one(“mmr.unit”, “Unit”, required=True),
    ‘minimumSellPrice’: fields.float(“Minimum sell price”),
    }

    mmr_product()

    So, how should i change these according to my module?

    id=”custom_report_without_prices”
    model=”account.invoice”
    string=”Invoice without prices”
    report_type=”qweb-pdf”
    name=”mmr.report_without_prices_document”
    attachment_use=”False”
    file=”mmr.report_without_prices_document”

    • Yenthe666 says:

      Hi Randy,

      The first thing that I notice is that you have another model name defined in your class and function than in your report. I’m not sure if that is the intention though. I’d have to see the full code for the module to be able to help you. Post it on help.odoo.com if this doesn’t solve it, I’ll see it passing by then 🙂

  4. Bosko says:

    Hi!

    I tried adding a new report for quotations in the sale module. I followed the steps in this tutorial (with necessary changes obviously) and after updating the sale module it worked like a charm until I restarted the server.

    Since then, my Odoo installation doesn’t work at all. The error I get is:

    insert or update on table “xxxxxx” violates foreign key constraint

    DETAIL: Key not present in table

    Now the key that is apparently not present in the table is in fact there and I’ve changed everything to it’s previous state but the problem persists.

    Also, I can’t update the modules at all.

    Could this be caused by changing something in the files mentioned in this tutorial or is it a database problem?

    Thank you!

    • Yenthe666 says:

      Hi Bosko,

      Looks like something has gone wrong o database level or you’ve tinkered around with models/fields without correct inheritance for example. Have you tried a -u through terminal to update the module? This shouldn’t give you any problems and fixes my problems 99% of the time.

  5. Yenthe666 says:

    Hi Afif,

    I’m sorry but I haven’t had this one before. Sounds to me like you’ve forget to fill something in for your report. NoneType means it is missing something for your report.

  6. Yenthe666 says:

    Hi Zsolt,

    I’m afraid there are some possibilities on why you’re getting this so I’d have to see the code. I’d suggest you to create a new help topic on help.odoo.com. Add the important code to it and/or a link to Github. Plenty of people there to help you and I’m also quite active there so I’ll see it pass by. 🙂

  7. Els Guns says:

    Hi Yenthe666,

    I have created a custom report and it works but it is not translated. I added the two templates ….

    What to check or should I do something else? (There is something else that is not like it should be maybe. In the reports list I now see two reports. The original report for quotations/orders has 4 qweb views (the 2 original and the two new) and the new report has 2 qweb views (the 2 new).

    thanks and greetings,
    Els

  8. Hey Yenthe,

    Can you tell me how can i import a tax table with tax amounts by group (for example : Tax 10% and Tax 5,5%) in the sale order document ? Or decompose the total tax amount in quotation.

    Odoo 9

  9. masoud says:

    It not working, make me tired.
    error:
    QWebTemplateNotFound: External ID not found in the system: sale.MyQWebReportNmae

    everything look find, i check milion times with other sources too, still not working, so annoying.
    anybody have idea about this!!???
    And one more question:
    Is it possible to use Pentaho report as attachment in email!? I set pentaho report in email attachment, but will make my template and partner_id fields crash and empty. have any solution for this?

    • Yenthe666 says:

      Hi Masoud,

      The issue is saying that one of those ID’s is not found, I do notice a type in sale.MyQWebReportNmae, shouldn’t this be MyQWebReportName?
      At this point I haven’t used Pentaho yet, so I can’t help you with this I’m afraid.. sorry.

      • masoud says:

        I solve the problem,
        sale.MyQWebReportNmae not working because refer to sale module. for custom modules must be like this:
        MyCustomModuleName.MyQWebReportNmae
        and will work fine.
        I didn’t find a right solution for Pentaho problem in attachment too, for now i just creating the same report in QWeb format to use in my attachment. If i find solution will share here too. Thanks for your useful site, most of your posts clear and grate for study.
        You can also add Custom header and footer too, I already figure it out how to create. easy and interesting.

  10. drobin says:

    Hi Yenthe666,

    First, thanks for you tutorial. Ur, I tried it but failed. The new report didn’t appear under the ‘Print’ dropdown. I restarted the service, updated the modules list and upgraded the ‘account’ module without success. But the new report was listed in the tech-info tab under ‘Upgrade’. Btw, my locale is Chinese, and the odoo’s version is 8.0. Do they have any affection?

    • Yenthe666 says:

      Hi Drobin,

      You’re welcome! I’m not sure why you’re updating the account module though. You don’t have to update this module, you need to install your custom module to add the custom code in your Odoo. Chinese shouldn’t have any effect.

  11. Hello Yenthe666 I do a report on a table that I have to do with a condition that the date of creation of a tuple must be in a range on what should give the dates from a view, and show first preview the report for then print to pdf, also I have to show all data in the table on the same page of the pdf, not a tuple per page …. how could I do this?

    • Yenthe666 says:

      Hi @dr1@n,

      You should handle the formatting and data in the Python side, show this in a view and then simply create a QWeb report that prints out your results generated by the Python.

  12. Rudy says:

    Hi Yenthe666,

    Does this tutorial work for Odoo 9 CE ?

    Please correct if me if I am wrong :
    Let say my module name is : addons/report_without_prices
    The file needed :
    a. addons/report_without_prices/__openerp__.py
    b. addons/report_without_prices/account_without_prices_report.xml
    c. addons/report_without_prices/views/account_without_prices.xml

    Is there any other file needed ?

    • Yenthe666 says:

      Hi Rudy,

      Yes this tutorial will also work for Odoo 9 (CE).
      What you’ve listed looks good to me too. This should work, provided that you’ve added the files in the __openerp__.py file too.

  13. whoah this blog is excellent i really like reading your articles.

    Keep up the good work! You understand, a lot of persons are hunting round for this info, you can aid them greatly.

    • Yenthe666 says:

      Hi Rosalie,

      Thank you for the kind feedback! That is why I made this blog, to inform as many people as I can. 🙂

    • Yenthe666 says:

      Hi Dorsaf,

      You will need to either inherit the default report header and footer or you’ll need to create a new header and footer that you will call in your own reports.

Leave a Reply

Your email address will not be published. Required fields are marked *