Dear all,
Once again I need your help and this time with Qweb Reports in Odoo12.
I have tried to read the Odoo documentation about custom qweb reports but it is not very clear.
Also, downloaded some modules with integrated reports to try to understand they're structure (accounting_pdf_reports), but this also some difficult for me to understand at this level.
I have found a simple report for Odoo v11, and I am trying to change it to v12 and since it is a simple report, perhaps following the example will help me creating my first custom report.
The problem is that at a specific stage (when I print the report) I am getting an "IndexError: list index out of range" error.
The report files code:
1. PY:
class AttendanceRecapReportWizard(models.TransientModel):
_name = 'attendance.recap.report.wizard'
date_start = fields.Date(string="Start Date", required=True, default=fields.Date.today)
date_end = fields.Date(string="End Date", required=True, default=fields.Date.today)
@api.multi def get_report(self):
data = { 'ids': self.ids,
'model': self._name,
'form': {'date_start': self.date_start,'date_end': self.date_end,
},
}
return self.env.ref('report_demo.recap_report').report_action(self, data=data)
class ReportAttendanceRecap(models.AbstractModel):
_name = 'report_demo.attendance_recap_report_view'
@api.model
def get_report_values(self, docids, data=None):
date_start = data['form']['date_start']
date_end = data['form']['date_end']
date_start_obj = datetime.strptime(date_start, DATE_FORMAT)
date_end_obj = datetime.strptime(date_end, DATE_FORMAT)
date_diff = (date_end_obj - date_start_obj).days + 1
docs = []
employees = self.env['hr.employee'].search([], order='name asc')
for employee in employees:
presence_count = self.env['hr.attendance'].search_count([
('employee_id', '=', employee.id),
('check_in', '>=', date_start_obj.strftime(DATETIME_FORMAT)),
('check_out', '<=', date_end_obj.strftime(DATETIME_FORMAT)),
])
absence_count = date_diff - presence_count
docs.append({
'employee': employee.name,
'presence': presence_count,
'absence': absence_count,
})
return {
'doc_ids': data['ids'],
'doc_model': data['model'],
'date_start': date_start,
'date_end': date_end,
'docs': docs,
}
2. The view, action and menu item:
<record model="ir.ui.view" id="attendance_recap_report_wizard">
<field name="name">HR Attendance Custom Recap Report</field>
<field name="model">attendance.recap.report.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Attendance Recap Report">
<group>
<group>
<field name="date_start"/>
</group>
<group>
<field name="date_end"/>
</group>
</group>
<footer>
<button name="get_report" string="Get Report" type="object" class="oe_highlight"/>
<button string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
<act_window id="action_attendance_recap_report_wizard"
name="Attendance Recap Report"
res_model="attendance.recap.report.wizard"
view_mode="form"
target="new"/>
<menuitem action="action_attendance_recap_report_wizard"
id="menu_attendance_report_wizard"
parent="hr_attendance.menu_hr_attendance_report"/>
3. The report id and template:
<report id="recap_report"
model="attendance.recap.report.wizard"
string="Attendance Recap Report"
report_type="qweb-pdf"
name="report_demo.attendance_recap_report_view"
paperformat="paperformat_attendance_recap_report"
menu="False"/>
<template id="attendance_recap_report_view">
<div class="header" style="border-bottom: 2px solid black">
<h3 class="text-center">Attendance Recap Report</h3>
<h4 class="text-center">
<strong>From</strong>:
<t t-esc="date_start"/>
<strong>To</strong>:
<t t-esc="date_end"/>
</h4>
</div>
</template>
The full error I get is:
Odoo Server Error
Traceback (most recent call last):
File "c:\odoo12\addons\web\controllers\main.py", line 1674, in report_download
response = self.report_routes(reportname, converter=converter, **dict(data))
File "C:\odoo12\odoo\http.py", line 517, in response_wrap
response = f(*args, **kw)
File "c:\odoo12\addons\web\controllers\main.py", line 1611, in report_routes
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
File "c:\odoo12\odoo\addons\base\models\ir_actions_report.py", line 694, in render_qweb_pdf
bodies, html_ids, header, footer, specific_paperformat_args = self.with_context(context)._prepare_html(html)
File "c:\odoo12\odoo\addons\base\models\ir_actions_report.py", line 316, in _prepare_html
body_parent = root.xpath('//main')[0]
IndexError: list index out of range
Can anyone help me solve this error?
Is there some tutorial that helps me develop custom reports for Odoo v12?
Thank you all once again
Best regards
QWEB reporting tips:
1- https://goo.gl/tg2Zyp
2- https://goo.gl/KZEo8X