This question has been flagged
10 Replies
6585 Views

Hi,

I made some research in odoo 10 documentation but i didn't find anything talking about Parser Report.

Could anyone help with this ?

Regards,

Avatar
Discard
Author

Hi anil it's wrriting with odoo 9 i'm looking for odoo 10

The given link is not for v10.

Author

Thanks Anil this what Niyas Posted in his answer but here with an exemple,thanks

Best Answer

Hi,

By checking this link you will get good idea about creating report is In Odoo V10.

https://www.odoo.com/documentation/10.0/reference/reports.html

Also I will show a sample of creating a report from the wizard.


XML for the wizard view,

<record id="id_for_the_wizard" model="ir.ui.view">
<field name="name">Test Name</field>
<field name="model">sample.wizard</field>
<field name="arch" type="xml">
<form string="Test">
<group>
<field name="sample_field"/>
</group>
<footer>
<button name="print_report" string="Print" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>


Python file for the wizard,

class PartnerWizard(models.TransientModel):
_name = 'sample.wizard'

sample_field = fields.Many2one('res.partner', string='Partner', required=True)

def print_report(self, data):
data = {}
data['form'] = self.read(['course_id', 'batch_id'])[0]
return self.env['report'].get_action(self, 'module_name.report_name_report', data=data)


Then for printing the report,

from odoo import models, api


class TestClass(models.AbstractModel):
_name = 'report.module_name.report_name_report'

@api.model
def render_html(self, docids, data=None):
#you will receive the data entered in the wizard here
#.........
#here you can write the code and pass the required data to template
#......
#here just passing the same data to template
docargs = {
'doc_ids': self.ids,
'doc_model': self.model,
'data': data,
}
return self.env['report'].render('module_name.report_name_report', docargs)

The above defined render_html function act as the parser for the v10. You can do the all operation here and can return the necessary things to the template by adding it to the docargs dictionary.

If you want to call custom functions you can call it from inside of this function and can define the custom function in the same model.

Now we have to define the template for the report, ie report_name_report

Report Template


<template id="report_name_report">
<t t-call="report.html_container">
<div class="font">
<div class="page">
<t t-call="report.external_layout">
<div class="text-center">
<h3>
<strong>Test Print</strong>
</h3>
</div>
<span>
Data:<t t-esc="data"/>
</span>
</t>
</div>
</div>
</t>
</template>

This is sample template, not much data is added in it.

Now to load the report to database we have to add the report tag.

<report
id="test_report"
model="sample.wizard"
string="Test Report"
report_type="qweb-pdf"
name="module_name.report_name_report"
file="module_name.report_name_report"
menu="False"
auto="False"
/>

This is how you can create a report in Odoo v10.

Thanks

Avatar
Discard
Author

Hi Niyas,

Here i'm talking about parser report and not normal report what i'm looking for is a converting of the code on answer below from 9 to 10

https://www.odoo.com/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244#answer_92245

Hello medmars,

You can see a function render_html in the above answer, that will be act as parser for v10

If you want to call any custom function you call it from the render_html function and that function can be defined in the same model. Then you can pass the value to template by appending it to docargs dictionary

Also as you have mentioned this is not normal report, hope you will understand its function

Author

Thanks will try

check the link i have mentioned in my answer,

You can see the Odoo documentation on the same, also the report generation in v10 is not same as in V9 or V8.

To make the report generation easier and faster this method is introduced.