1

Hi there i'm trying to print Qweb report but no luck i don't know why

it just generate empty report with no pages Here is all my code for this report

i need to generate a report from wizard

My report class :

from openerp.osv import osv,fields import time

class fci_attendance_analysis (osv.osv):

_name='fci.attendance.analysis'
_rec_name='student_id'

_columns={
    'standard_id':fields.many2one('fci.standard',string='Standard',required=True),
    'group_id':fields.many2one('fci.standard.groups',string='Group'),
    'date':fields.date('Date Of generation',readonly=True),
    '_date':fields.date('Date'),
    'student_id':fields.many2one('fci.student',string='Student'),
    'number_of_absence': fields.integer( 'Number Of Absence'),
    'terms_id': fields.many2one('fci.terms', string='Term',required=True),
    'subject_id':fields.many2one('fci.subject',string='Subject',required=True),
    'state': fields.selection([('s','by Subject'),('t','By Student')],string='Select Report Type',required=True),
}
_defaults = {
             'state': 't',
             'date': time.strftime("%Y-%m-%d")
             }
def gen_student_attendance_report(self,cr, uid, ids, context=None ):
    datas = {}
    if context is None:context = {}
    noobs_data=[]
    data = self.read(cr, uid, ids, ['state','subject_id','student_id'], context=context)
    stu= data[0]['student_id']
    sub=data[0]['subject_id']
    darsh=int(stu[0])
    sasa=int(sub[0])
    if data[0]['state'] == 't':
        cr.execute(
        "select DISTINCT ON (s.name) s.name as student_name,d.name as subject_name,attendance_date from fci_attendance_line ,fci_student s,fci_subject d where s.id=%d and d.id=%d and present=False "% (
            darsh,sasa))
        noobs = cr.dictfetchall()
        cr.execute(
        "select DISTINCT ON (s.name) s.name as student_name,d.name as subject_name,attendance_date from fci_attendance_line ,fci_student s,fci_subject d where s.id=%d and d.id=%d and present=False "% (
            darsh,sasa))
        noobs_details = cr.dictfetchall()
        for details_ids in noobs_details:
            for datae in noobs:
                details_ids[datae['student_name']] = str(datae['student_name'])+str(datae['subject_name']) + str(datae['attendance_date'])
            noobs_data.append(details_ids)
        #print("Values",noobs_data[0])
        #p=self.pool['report'].get_action(cr, uid,[], 'FCI_ERP.abcence_report_stu_document', data=noobs_data[0], context=context)
        #print("it return : ",p )
    #return self.pool['report'].get_action(cr, uid,[], 'FCI_ERP.abcence_report_stu_document', data=noobs_data[0], context=context)

    datas = {
         'ids': [],
         'model': 'fci.attendance.analysis',
         'form': data
             }
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'FCI_ERP.abcence_report_stu_document',
        'datas': datas
        }
fci_attendance_analysis()

here is my wizard code :

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="fci_attendance_analysis_form" model="ir.ui.view">
            <field name="name">fci.attendance.analysis.form</field>
            <field name="model">fci.attendance.analysis</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <form string="Time Table Report" version="7.0">
                    <header>
                        <span groups="base.group_user">
                            <button special="cancel" string="Close" type="object"
                                    icon="terp-dialog-close"/>
                            <button string="Generate Time Table Report" type="object"
                                    name="gen_student_attendance_report"/>
                        </span>
                    </header>
                    <sheet>
                        <separator string="Select Teacher/Student" colspan="4"/>
                        <div>
                            <group colspan="4" cols="4">
                                <field name="state"/>
                                <field name="standard_id"/>
                                <field name="date"/>
                                <field name="terms_id"/>
                                <field name="subject_id"/>
                            </group>
                            <group col="4" colspan="4">
                                <field name="group_id"
                                       attrs="{'required':[('state','=','t')],'invisible':[('state','!=','t')]}"/>
                                <field name="student_id"
                                       attrs="{'required':[('state','=','t')],'invisible':[('state','!=','t')]}"/>
                            </group>
                        </div>
                    </sheet>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="fci_attendance_analysis_reports_view">
            <field name="name">Generate Time Table Report</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">fci.attendance.analysis</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
            <field name="domain">[]</field>
            <field name="context">{}</field>
        </record>
        <record model="ir.actions.act_window.view" id="fci_attendance_analysis_reports_view_form">
            <field name="act_window_id" ref="fci_attendance_analysis_reports_view"/>
            <field name="sequence" eval="20"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="fci_attendance_analysis_form"/>
        </record>
    </data>
</openerp>

here is my report tag :

<report
           string="Student Report Absence"
           id="report_Absence_subject"
           model="fci.attendance.analysis"
           report_type="qweb-pdf"
           name="FCI_ERP.abcence_report_stu_document"
           file="FCI_ERP.abcence_report_stu_document"/>

and here is my report.xml :

 <?xml version="1.0" encoding="utf-8"?>
<openerp>

    <data>
        <template id="abcence_report_stu_document">
            <style type="text/css">
                table.gridtable {
                font-family: verdana,arial,sans-serif;
                font-size:14px;
                color:#333333;
                border-width: 1px;
                border-color: #666666;
                border-collapse: collapse;
                }
                table.gridtable th {
                border-width: 1px;
                padding: 9px;
                border-style: solid;
                border-color: #666666;
                background-color: #dedede;
                }
                table.gridtable td {
                border-width: 1px;
                padding: 9px;
                border-style: solid;
                border-color: #666666;
                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>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <div class="row text-center">
                                    <h2>
                                        <strong>
                                            كشف غياب الطالب
                                            <p>
                                              <span t-esc="o.student_id.name"/>
                                            </p>
                                            فى مادة
                                            <p>
                                               <span t-esc="o.subject_id.name"/>
                                            </p>
                                        </strong>
                                    </h2>
                                </div>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <table class="gridtable">
                                    <tbody>
                                        <tr>
                                            <th>Student Name</th>
                                            <th>Standard</th>
                                            <th>Group</th>
                                        </tr>
                                        <tr>
                                            <td>
                                                <span t-esc="o.student_id.name"/>
                                            </td>
                                            <td>
                                                <span t-esc="o.standard_id.name"/>
                                            </td>
                                            <td>
                                                <span t-esc="o.group_id.name"/>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <table class="gridtable">
                                    <tbody>
                                        <tr>
                                            <th>Subject Name</th>
                                            <th>Absence Day</th>
                                        </tr>
                                        <tr t-foreach="o.gen_student_attendance_report(o.id)" t-as="a">
                                            <td>
                                                <span t-esc="a.get('student_name')"/>
                                            </td>
                                            <td>
                                                <span t-esc="a.get('attendance_date') "/>
                                            </td>

                                        </tr>

                                    </tbody>
                                </table>
                                <para>
                                    <font color="white">......</font>
                                </para>
                                <para>
                                    <font color="white">......</font>
                                </para>
                            </div>
                        </div>
                    </t>
                </t>
            </t>
        </template>
    </data>
</openerp>

-----------------------------------------------------------------------------

Edit 1 :

I updated the code but it generate error in calling gen_student_attendance_report function in ther report

Hint : if i remove the table of gen_student_attendance_report function the report print successfully

Here is my error :

except_orm: (u'"gen_student_attendance_report() got multiple values for keyword argument \'context\'" while evaluating\n\'o.gen_student_attendance_report(o.id)\'', (<class 'openerp.addons.base.ir.ir_qweb.QWebException'>, QWebException(ValueError(u'"gen_student_attendance_report() got multiple values for keyword argument \'context\'" while evaluating\n\'o.gen_student_attendance_report(o.id)\'',),), <traceback object at 0x7f3478bd0a28>))
4

2 回答 2

0

在 xml 中更新此调用行,

<tr t-foreach="o.gen_student_attendance_report()" t-as="a">

你可以参考这个博客,

http://blog.emiprotechnologies.com/create-qweb-report-odoo/
于 2015-04-11T09:14:29.897 回答
0

对于 gen_student_attendance_report 函数,不要将其设置为向导对象。总体而言,关于 OpenERP/Odoo 的报告适用于特定的拱门:在您的模块中添加新的文件夹名称“报告”。在您的报告文件夹中添加两个 .py 文件:1- __init__.py 2- anyname.py ,对于您的情况,您可以调用它abcence_report.py

abcence_report.py添加任何可能从报告 QWeb 模板调用的函数。

您可以随时查看源代码,您的报告只需查看帐户模块上的合作伙伴分类帐报告,它对您的帮助比任何人都大。

注意:首先,请参考 OpenERP/Odoo 的源代码。

试着在你的 abcence_report.py 上写这个

# -*- coding: utf-8 -*-

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

class student_attend(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
    super(student_attend, self).__init__(cr, uid, name, context=context)
    self.localcontext.update( 
                              {
                               'time': time,
                               'gen_student_attendance_report':self.gen_student_attendance_report,
                              }
                            )
    self.context = context
def gen_student_attendance_report(self,cr, uid, ids, context={} ):
    noobs_data=[]
    data = self.read(cr, uid, ids, ['group_id', 'date','standard_id',\
                            'student_id','state','terms_id','subject_id'], context=context)

    stu= data[0]['student_id']
    sub=data[0]['subject_id']
    darsh=int(stu[0])
    sasa=int(sub[0])
    if data[0]['state'] == 't':
        cr.execute(
        "select DISTINCT ON (s.name) s.name as student_name,d.name as subject_name,attendance_date from fci_attendance_line ,fci_student s,fci_subject d where s.id=%d and d.id=%d and present=False "% (
            darsh,sasa))
        noobs = cr.dictfetchall()
        cr.execute(
        "select DISTINCT ON (s.name) s.name as student_name,d.name as subject_name,attendance_date from fci_attendance_line ,fci_student s,fci_subject d where s.id=%d and d.id=%d and present=False "% (
            darsh,sasa))
        noobs_details = cr.dictfetchall()
        for details_ids in noobs_details:
            for data in noobs:
                details_ids[data['student_name']] = str(data['student_name'])+str(data['subject_name']) + str(data['attendance_date'])
            noobs_data.append(details_ids)
        print("Values",noobs_data)
    #return self.pool['report'].get_action(cr, uid, [], 'FCI_ERP.abcence_report_stu_document', data=noobs_data[0], context=context)
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'FCI_ERP.abcence_report_stu_document',
        'datas': noobs_data[0],
        }

class student_attend_report(osv.AbstractModel):
_name = 'report.FCI_ERP.abcence_report_stu_document'
_inherit = 'report.abstract_report'
_template = 'FCI_ERP.abcence_report_stu_document'
_wrapped_report_class = student_attend

这就是我所说的,类似这样的东西

于 2015-04-09T09:21:56.883 回答