from openerp import models, fields, api, _
class Student(models.Model):
_name = 'student.student'
"""
contain all student data
"""
name = fields.Char('Name', required=True)
age = fields.Integer('Age', required=True)
phone = fields.Integer('Phone', required=True)
email = fields.Char('Email', required=True)
so first we gonna create wizard by name student_report_wiz.py and we gonna add two integers fields to make the user define the range of age , after that we will take the two values which entered by the user and go to the student model and get the id of any student whose age is less than the max value and larger than the min value which are defined by the user , and push all ids in dictionary which passed to the template , as below
from openerp import models, api
class student_report_wiz(models.TransientModel):
"""
get students by age range
"""
_name = 'student.report.wiz'
max_age = fields.Integer('Max Age', required=True)
min_age = fields.Integer('Min Age', required=True)
@api.multi
def get_students(self):
student_ids = self.env['student.student'].search([])
student_list = []
for rec in student_ids :
if rec.age > self.min_age and rec.age < self.max_age"
student_list.append(rec.id)
student_dic = {stud_list: student_list}
return student_dic
return self.pool['report'].get_action(cr, uid, [], 'module_name.students_age_report_temp', data=student_dic, context=context)
Now we get all student we want in student_dic , then we will create the report py file by name students_age_report.py as below
class students_age_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
self.context = context
super(students_age_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'line':self._getdata,
})
def _getdata(self,data):
"""
method that return student's in age range
"""
lines = {}
lines = data['form']
return lines
class students_age_report_details(osv.AbstractModel):
_name = 'report.module_name.students_age_report_temp'
_inherit = 'report.abstract_report'
_template = 'module_name.students_age_report_temp'
_wrapped_report_class = students_age_report
then we will create template by id students_age_report_temp as below
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data >
<!-- ...Define Template... -->
<template id="students_age_report_temp">
<t t-call="report.html_container">
<div class="page">
<header>
<center>
<div style="float:left; width:80%;">
<div style="float:right; width:75%;">
<b style="font-family:Georgia, serif;font-size:16px;">
student by age range
</b>
<br></br><br></br>
</div>
<div>
<table>
<th>
<td>
<b style="size:16px;">
name
</b>
</td>
<td>
<b style="size:16px;">
age
</b>
</td>
<td>
<b style="size:16px;">
phone
</b>
</td>
<td>
<b style="size:16px;">
email
</b>
</td>
</th>
<t t-foreach="line(data)" t-as="line" >
<tr>
<td>
<b style="size:16px;">
<span t-esc="line(data).name"/>
</b>
</td>
<td>
<b style="size:16px;">
<span t-esc="line(data).age"/>
</b>
</td>
<td>
<b style="size:16px;">
<span t-esc="line(data).phone"/>
</b>
</td>
<td>
<b style="size:16px;">
<span t-esc="line(data).email"/>
</b>
</td>
</tr>
</table
</div>
</div>
</p>
</div>
</t>
</template>
<!-- """create report """ -->
<report
id="students_age_report_id"
string="Students By Age Report"
model="student.student"
report_type="qweb-pdf"
name="maodule_name.students_age_report_temp"
menu="False"
/>
<record id="report.paperformat_euro" model="report.paperformat">
<field name="margin_top">15</field>
<field name="margin_bottom">15</field>
<field name="margin_left">15</field>
<field name="margin_right">15</field>
<field name="header_spacing">15</field>
</record>
</data>
</openerp>
>>>DONE