Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
3 Respostas
3841 Visualizações

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?

Avatar
Cancelar
Melhor resposta

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.

Avatar
Cancelar
Autor Melhor resposta

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!


Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
dez. 17
3516
1
set. 17
5000
2
fev. 17
7047
1
ago. 16
16437
0
jan. 16
3260