PDF reports are written similar to normal views in Odoo.
Today we'll create a pdf report for model customer.feedback in module customer_feedback we created from 1st chapter of this tutorial.
Report Action
All reports in Odoo must be declared with a report action. A report action will inculde the following attributes:
Create an xml file named report_action.xml. This is where we'll define report actions for our module.
Open your report_action.xml, add these lines.
Code:
<odoo>
<data>
<report
id="action_customer_feedback_report"
model="customer.feedback"
string="Customer Feedback"
report_type="qweb-pdf"
name="customer_feedback.customer_feedback_report_template"
file="customer_feedback.customer_feedback_report_template"
attachment_use="False"
/>
</data>
</odoo>
Now lets create a template for customer feedback. Create a new file named customer_feedback_report.xml in directory report
code:
<odoo>
<data>
<template id="customer_feedback_report_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div class="page">
<h2>Customer Feedback</h2>
<p>Customer Name <span t-field="o.customer_id.name"/></p>
<table width="100%">
<tr>
<th>
Feedback Type
</th>
<th>
Rating
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
<span t-field="o.feedback_type.name"/>
</td>
<td>
<span t-field="o.rating"/>
</td>
<td>
<span t-field="o.customer_description"/>
</td>
</tr>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</odoo>
Finally add the report_action.xml and customer_feedback_report.xml to your __manifest__.py file
# -*- coding: utf-8 -*-
{
'name': "Customer Feedback",
'version': '1.0',
'summary': """Record Your Customer feedback""",
'description': """
Customer Feedback Module
-create feedback to customers
""",
'author': "My Company",
'category': 'Test',
# any module necessary for this one to work correctly
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/customer_feedback_view.xml',
'report/report_action.xml',
'report/customer_feedback_report.xml',
],
'application': True,
}
Now when you open your customer feedback record you can see print option for your model there.
Next Chapter: Creating a wizard
Today we'll create a pdf report for model customer.feedback in module customer_feedback we created from 1st chapter of this tutorial.
Report Action
All reports in Odoo must be declared with a report action. A report action will inculde the following attributes:
- id: id for the generated report
- name[required]: Name of the report.
- model[required]: Name of model whose report is to be printed
- report-type[required]: Values can be qweb-pdf or qweb-html
- attachment_use: Values can be True or False. If set to True, then report will be saved in Odoo when printing for the first time. Used only if you have to generate the report for once.
- paperformat: If you want to set a paperformat different from company's default paperformat
Create an xml file named report_action.xml. This is where we'll define report actions for our module.
Open your report_action.xml, add these lines.
Code:
<odoo>
<data>
<report
id="action_customer_feedback_report"
model="customer.feedback"
string="Customer Feedback"
report_type="qweb-pdf"
name="customer_feedback.customer_feedback_report_template"
file="customer_feedback.customer_feedback_report_template"
attachment_use="False"
/>
</data>
</odoo>
Now lets create a template for customer feedback. Create a new file named customer_feedback_report.xml in directory report
code:
<odoo>
<data>
<template id="customer_feedback_report_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div class="page">
<h2>Customer Feedback</h2>
<p>Customer Name <span t-field="o.customer_id.name"/></p>
<table width="100%">
<tr>
<th>
Feedback Type
</th>
<th>
Rating
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
<span t-field="o.feedback_type.name"/>
</td>
<td>
<span t-field="o.rating"/>
</td>
<td>
<span t-field="o.customer_description"/>
</td>
</tr>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</odoo>
Finally add the report_action.xml and customer_feedback_report.xml to your __manifest__.py file
# -*- coding: utf-8 -*-
{
'name': "Customer Feedback",
'version': '1.0',
'summary': """Record Your Customer feedback""",
'description': """
Customer Feedback Module
-create feedback to customers
""",
'author': "My Company",
'category': 'Test',
# any module necessary for this one to work correctly
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/customer_feedback_view.xml',
'report/report_action.xml',
'report/customer_feedback_report.xml',
],
'application': True,
}
Now when you open your customer feedback record you can see print option for your model there.
Next Chapter: Creating a wizard
No comments:
Post a Comment