Skip to content

Instantly share code, notes, and snippets.

@3mrdev
Last active February 23, 2021 13:46
Show Gist options
  • Save 3mrdev/f32561047031a5b9ead153c5f747be90 to your computer and use it in GitHub Desktop.
Save 3mrdev/f32561047031a5b9ead153c5f747be90 to your computer and use it in GitHub Desktop.
Odoo Custom Report With Wizards
<odoo>
<report id="example_report"
model="example.report.wizard"
string="Example (PDF)"
report_type="qweb-pdf"
name="your_module.example_report_view"
menu="False"/>
<template id="example_report_view">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<br/>
<h2 class="text-center" style="border: 1px solid lightgray; padding: 10px 10px;">
<span>Example Title</span>
</h2>
<br/>
<table class="table table-bordered table-sm text-center">
<thead class="thead-light">
<tr>
<th scope="col">First Column</th>
</tr>
</thead>
<tbody class="sale_tbody">
<t t-foreach="docs" t-as="doc">
<tr>
<th scope="col">First Data in Column</th>
</tr>
</t>
</tbody>
</table>
</div>
</t>
</t>
</template>
</odoo>
from datetime import datetime, timedelta
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class ExampleReportWizard(models.TransientModel):
_name = 'example.report.wizard'
start_date = fields.Date(required=True,default=fields.Date.today())
end_date = fields.Date()
def get_report(self):
"""Call when button 'Get Report' clicked.
"""
sort = "id"
domain = [
('partner_id', '!=', False),
('date','>=', str(self.start_date))
]
lines = self.env['account.move.line'].search(domain,order=sort)
docs = []
for line in lines:
docs.append({
'partner': line.partner_id.name or False,
})
data = {
'doc_ids': self.ids,
'doc_model': self._name,
'docs': docs,
}
# use `module_name.report_id` as reference.
# `report_action()` will call `get_report_values()` and pass `data` automatically.
return self.env.ref('your_module.example_report').report_action(self, data=data)
class ReportExampleWizard(models.AbstractModel):
"""Abstract Model for report template.
for `_name` model, please use `report.` as prefix then add `module_name.report_name`.
"""
_name = 'report.your_module.example_report_view'
@api.model
def _get_report_values(self, docids, data=None):
return data
<odoo>
<data>
<record model="ir.ui.view" id="partner_report_wizard">
<field name="name">Partner Report</field>
<field name="model">partner.report.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Partner Report">
<group>
<group>
<field name="start_date"/>
<field name="end_date"/>
</group>
</group>
<footer>
<button name="get_report" string="Print Report" type="object" class="oe_highlight"/>
<button string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
<act_window id="action_example_report_wizard"
name="Example Report"
res_model="example.report.wizard"
view_mode="form"
target="new"/>
<menuitem id="example_wizard_menu" name="Example (PDF)" sequence="3" parent="your_parent_menu" action="action_example_report_wizard"/>
</data>
</odoo>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment