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.

0

[8] Odoo Custom Report Page

By
mrpingu
on 7/27/15, 6:01 AM 472 views

I have my own custom module, named master.py

from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp import tools
import datetime
import itertools

class mmr_brand(osv.osv):
_name = "mmr.brand"
_description = "Brand Module for PT.MMR, for easier input and prevent duplication."

_columns = {
'name': fields.char("Brand", required=True),
'notes' : fields.char("Notes"),
}

mmr_brand()

class mmr_unit(osv.osv):
_name = "mmr.unit"
_description = "Unit Module for PT.MMR, for easier input and prevent duplication."

_columns = {
'name': fields.char("Unit", required=True),
'notes' : fields.char("Notes"),
}

mmr_unit()


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()

With view named master,

<openerp>
<data>
<record id="mmr_product_list" model="ir.ui.view">
<field name="name">mmr.product.list</field>
<field name="model">mmr.product</field>
<field name="arch" type="xml">
<tree string="Product" version="7.0">
<field name="brand" />
<field name="name" />
<field name="unit" />
<field name="minimumSellPrice" />
</tree>
</field>
</record>

<record id="mmr_product_form" model="ir.ui.view">
<field name="name">mmr.product.form</field>
<field name="model">mmr.product</field>
<field name="arch" type="xml">
<form string="Product" version="7.0" >
<header>
<button name="%(report_example)d" string="Print" type="action"/>
</header>
<group>
<field name="brand" />
<field name="name" />
<field name="unit" />
<field name="minimumSellPrice" />
</group>
</form>
</field>
</record>

<record id="mmr_brand_list" model="ir.ui.view">
<field name="name">mmr.brand.list</field>
<field name="model">mmr.brand</field>
<field name="arch" type="xml">
<tree string="Brand" version="7.0">
<field name="name" />
<field name="notes" />
</tree>
</field>
</record>

<record id="mmr_brand_form" model="ir.ui.view">
<field name="name">mmr.brand.form</field>
<field name="model">mmr.brand</field>
<field name="arch" type="xml">
<form string="Brand" version="7.0" >
<group>
<field name="name" />
<field name="notes" />
</group>
</form>
</field>
</record>

</data>
</openerp>

And Menu named menu_master,

<openerp>
<data>
<record id="multi_action_master_mmr_product" model="ir.actions.act_window">
<field name="name">Product</field>
<field name="res_model">mmr.product</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

<menuitem id="mmr_menu" name="MMR" sequence="111" groups="base.group_user"/>

<menuitem id="mmr_menu_product" name="Product" parent="mmr_menu" sequence="1" />
<menuitem id="multi_menu_master_product" action="multi_action_master_mmr_product" name="Product" parent="mmr_menu_product" sequence="1" />

</data>
</openerp>

I also have created xml containing report template, i named the file reportExample.xml and placed it in view folder

<?xml version="1.0" encoding="utf-8"?>
<!--Custom report.-->
<openerp>
<data>

<template id="report_example">
<t t-call="report.external_layout">
<div class="page">
<div class="row">
<h3>Title</h3>
</div>
</div>
</t>
</template>

</data>
</openerp>

Then I also create xml named MMR_report.xml, containing

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="custom_report_example"
model="mmr.product"
string="Example"
report_type="qweb-pdf"
name="mmr.report_example"
attachment_use="False"
file="mmr.report_example"
/>
</data>
</openerp>

Also, I already noticed __openerp__ file about my new report

 'update_xml': [  
'view/reportExample.xml',
'view/master.xml',
'menu/menu_master.xml',
],

As you can see, I already insert button which I expect to show my custom report page when i pressed it. Unfortunately it doesn't work. Can someone explain what wrong with it?

1

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 7/27/15, 8:03 AM

Dear Mrpingu,

Your code is good but you do one mistake in button so please replace your code with my code.

Your code

<button name="%(report_example)d" string="Print" type="action"/>  

My code

<button name="%(custom_report_example)d" string="Print" type="action"/>


Hope this help full for you

Thanks & Regards

Ankit H Gandhi.

0
mrpingu
On 7/28/15, 5:46 AM

Thx Ankit Gandhi for the answer!


So I will write what I learn from this:

1.    To make report you need to write the template and fill the ID. You can just fill the template with <h2>Test<\h2> for testing purpose

2.    Then you will need to register your report using <report> tag. You can fill the ID, model(what class you want this report about), name and file (Your module folder name.Your template ID) 

3. Voila! Your class should have print button beside more dropdown button

4. Hope it helps!


0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 7/27/15, 7:31 AM

You define security rights in ir.model.access.csv for your custom module.

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: 7/27/15, 6:01 AM
Seen: 472 times
Last updated: 7/28/15, 5:46 AM