Saturday, 28 February 2015

Odoo Qweb Reports problems



I want to generate time table report but I'm very confused of how can i use Qweb I'm new to Odoo and i can't handle it and the documentation is very poor


here it what i try:


fci_time_table_report.py



import time
from openerp import osv
from openerp.report import report_sxw

class timetable_info(report_sxw.rml2sxw):
def __init__(self, cr, uid, name, context=None):
super(timetable_info, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'get_timetable':self._get_timetable,
})

def _get_timetable(self, timetable_id):
timetable_detail=[]

self.cr.execute(" select t.start_time,t.end_time,s.name,week_day,r.name as"
" teacher from fci_time_table_line t, fci_subject_subject s, resource_resource r, "
"hr_employee hr where t.subject_id= s.id and t.teacher_id= hr.id and "
"hr.resource_id = r.id and table_id = %d group by start_time,end_time,s.name,week_day,r.name"
" order by start_time"%(timetable_id.id))
res = self.cr.dictfetchall()
self.cr.execute("select start_time,end_time from fci_time_table_line where table_id=%d group by start_time,end_time order by start_time"%(timetable_id.id))
time_data = self.cr.dictfetchall()
for time_detail in time_data:
for data in res:
if time_detail['start_time']==data['start_time'] and time_detail['end_time']==data['end_time']:
if (data['name']=='Recess'):
time_detail[data['week_day']] = data['name']
else:
time_detail[data['week_day']] = data['name']+ '\n(' +data['teacher']+')'
timetable_detail.append(time_detail)
return timetable_detail
class report_time_table(osv.AbstractModel):
_name = 'FCI_ERP.timetable_report_document'
_inherit = 'report.abstract_report'
_template = 'FCI_ERP.timetable_report_document'
_wrapped_report_class = timetable_info


and here it is my report view in XML



<openerp>
<data>
<template id="timetable_report_document">
<style>
.font{
font-size:18px;
font-family:"Helvetica"
}
@page{
size: A4;
}

table.center {
width:80%;
margin-left:10%;
}

td.spacer1{
padding-right:320px;
}
.table.gridtable {
font-size:11px;
border-width: 1px;
border-color: #cccccc;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 10px;
border-style: solid;
border-color: #cccccc;
<!-- background-color: #dedede; -->
}
table.gridtable td {
border-width: 1px;
padding: 10px;
border-style: solid;
border-color: #cccccc;
<!-- background-color: #ffffff; -->
}

</style>

<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="font">
<div class="page">
<div class="row text-center">
<h2>
<b>
<span t-field='res_company.name'/>
</b>
</h2>
</div>
<div class="row text-center">
<h2>
<strong>Time Table</strong>
</h2>
</div>
<para>
<font color="white">......</font>
</para>
<para>
<font color="white">......</font>
</para>
<table class="center">
<tbody>
<tr>
<td>Standard</td>
<td>Term</td>
</tr>
</tbody>
</table>
<table class="center">
<tbody>
<tr>
<td>
<span t-esc="a.get('standard_id')"/>
</td>
<td>
<span t-esc="a.get('division_id')"/>
</td>
</tr>
</tbody>
</table>
<para>
<font color="white">......</font>
</para>
<para>
<font color="white">......</font>
</para>
<table class="center">
<tbody>
<tr>
<td>Time</td>
<td>Saturday</td>
<td>Sunday</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
</tbody>
</table>
<table class="gridtable center">
<tr t-foreach="get_timetable(data)" t-as="a">

<td>
<span t-esc=" a.get('start_time') - a.get('end_time')"/>
</td>
<td>
<span t-esc="a.get('saturday') "/>
</td>
<td>
<span t-esc="a.get('sunday')"/>
</td>
<td>
<span t-esc="a.get('monday')"/>
</td>
<td>
<span t-esc="a.get('tuesday')"/>
</td>
<td>
<span t-esc="a.get('wednesday')"/>
</td>
<td>
<span t-esc="a.get('thursday')"/>
</td>
<td>
<span t-esc="a.get('friday')"/>
</td>

</tr>
</table>
</div>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>

No comments:

Post a Comment