Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Create a custom report in Odoo12. Error "index out of range". How to solve it?

Subscribe

Get notified when there's activity on this post

This question has been flagged
reportsOdoo12.0
1 Reply
16296 Views
Avatar
Paulo Matos

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

2
Avatar
Discard
Sehrish

QWEB reporting tips:

1- https://goo.gl/tg2Zyp

2- https://goo.gl/KZEo8X

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,
Please update the code like this,

<template id="attendance_recap_report_view">
<t t-call="web.html_container">
<t t-call="web.internal_layout"
>
<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>
</t>
</t>
</template>


Thanks

10
Avatar
Discard
Paulo Matos
Author

Thank you very much @Cybrosys

David Sicard Sotaquira

Bro, pero entonces porqué razón toca obligatoriamente usar el html_container y el web.internal_layout? yo me acuerdo que en la community V8 no era necesario y uno podía mas facil customizar el header y el footer dentro del mismo reporte. Créeme que se me ha hecho muy dificil poder customizar un header y sobre todo el footer dentro de un reporte desde 0.

Dèèpak ahir

Thanks @Cybrosys !

Serge Mercado

This was posted a year ago, but this one actually helped me a lot. A duplicate t-call on web.external_layout cause the problem so I changed the outer one to web.html_container. Thank you!

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Code for page number in Body of Pdf report
reports
Avatar
Avatar
Avatar
2
अक्तू॰ 25
3395
How to increase the width of a column on odoo quotation PDF?
reports
Avatar
Avatar
1
अक्तू॰ 25
1210
Odoo Online (SaaS 18.4 Enterprise) – How to modify invoice report header without affecting other reports but keep default table content
reports
Avatar
Avatar
1
अग॰ 25
1871
Custom Dashboard using js
Odoo12.0
Avatar
Avatar
1
अप्रैल 25
4833
Odoo .SH V17 how do I migrate a report from staging to production?
reports
Avatar
Avatar
1
अप्रैल 25
2521
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now