Steps to follow when creating a report from wizard:
Rewrite the print_report method as follows:
code:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class CustomerFeedbackReportWizard(models.TransientModel):
_name = 'customer.feedback.report.wizard'
_description = 'Customer Feedback Report Wizard'
customer_id = fields.Many2one('res.partner', string='Customer')
@api.multi
def print_report(self):
context = dict(self._context)
if context is None:
context = {}
data = self.read()[0] or {}
datas = {
'ids': self._ids,
'data': data,
'model': 'customer.feedback.report.wizard'
}
print('datas: ', datas)
return self.env.ref('customer_feedback.action_customer_feedback_wizard_report').report_action(self, data=datas)
code:
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class CustomerFeedbackWizardReport(models.AbstractModel):
_name = 'report.customer_feedback.wizard_report_template'
@api.model
def _get_report_values(self, docids, data=None):
docs = self.env['customer.feedback'].search([('customer_id', '=', data['data']['customer_id'][0])])
return {
'doc_model': 'customer.feedback',
'docs': docs,
}
import wizard.py in init file
Code:
<odoo>
<data>
<template id="wizard_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>
Now lets define this template in report_action.xml file we already created.
Modified file will look like
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"
/>
<report
id="action_customer_feedback_wizard_report"
model="customer.feedback.report.wizard"
string="customer.feedback.report.wizard"
report_type="qweb-pdf"
name="customer_feedback.wizard_report_template"
file="customer_feedback.wizard_report_template"
attachment_use="False"
/>
</data>
</odoo>
Final manifest file will look like:
# -*- 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',
'wizard/customer_feedback_wizard.xml',
'report/report_action.xml',
'report/customer_feedback_report.xml',
'report/wizard_report.xml',
],
'application': True,
}
- Create a wizard
- Create a parser for the report template
- Create a template for report
Rewrite the print_report method as follows:
code:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class CustomerFeedbackReportWizard(models.TransientModel):
_name = 'customer.feedback.report.wizard'
_description = 'Customer Feedback Report Wizard'
customer_id = fields.Many2one('res.partner', string='Customer')
@api.multi
def print_report(self):
context = dict(self._context)
if context is None:
context = {}
data = self.read()[0] or {}
datas = {
'ids': self._ids,
'data': data,
'model': 'customer.feedback.report.wizard'
}
print('datas: ', datas)
return self.env.ref('customer_feedback.action_customer_feedback_wizard_report').report_action(self, data=datas)
- here data=self.read()[0] or {} will pass all values we selected in the wizard to report parser(which we'll create).
- action_customer_feedback_wizard_report is the id of the report action in which we'll define the report template.
code:
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class CustomerFeedbackWizardReport(models.AbstractModel):
_name = 'report.customer_feedback.wizard_report_template'
@api.model
def _get_report_values(self, docids, data=None):
docs = self.env['customer.feedback'].search([('customer_id', '=', data['data']['customer_id'][0])])
return {
'doc_model': 'customer.feedback',
'docs': docs,
}
import wizard.py in init file
- here naming of class should be like report.module_name.template_name
Code:
<odoo>
<data>
<template id="wizard_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>
Now lets define this template in report_action.xml file we already created.
Modified file will look like
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"
/>
<report
id="action_customer_feedback_wizard_report"
model="customer.feedback.report.wizard"
string="customer.feedback.report.wizard"
report_type="qweb-pdf"
name="customer_feedback.wizard_report_template"
file="customer_feedback.wizard_report_template"
attachment_use="False"
/>
</data>
</odoo>
Final manifest file will look like:
# -*- 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',
'wizard/customer_feedback_wizard.xml',
'report/report_action.xml',
'report/customer_feedback_report.xml',
'report/wizard_report.xml',
],
'application': True,
}
No comments:
Post a Comment