Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

KeyError: 'doc' in Custom QWeb Report for Sale Order

Odebírat

Get notified when there's activity on this post

This question has been flagged
qwebdockeyerrorodoo17
1 Odpovědět
3267 Zobrazení
Avatar
Moses Mwaba

Hello,

I'm encountering an issue while trying to render a custom QWeb report for the sale.order model in Odoo. I created a custom report template and linked it to an action in my custom module. However, when I attempt to generate the report, I get the following error:

Error:
File "<1659>", line 1398, in template_1659

odoo.addons.base.models.ir_qweb.QWebException: Error while render the template

KeyError: 'doc'

Template: zra_smart_invoice.zra_custom_report_saleorder

Path: /t/t/t[2]

Node: <t t-set="forced_vat" t-value="doc.fiscal_position_id.foreign_vat"/>



What I Have Done:

  1. Custom Template: Below is a snippet from my template file:
    <template id="zra_custom_report_saleorder">
        <t t-call="web.external_layout">
            <t t-set="doc" t-value="doc.with_context(lang=lang)"/>
            <t t-set="forced_vat" t-value="doc.fiscal_position_id.foreign_vat"/>
            <!-- Other content here -->
        </t>
    </template>
  2. Report Action: I defined the report action as follows:
<record id="zra_action_print_custom_report" model="ir.actions.report">
    <field name="name">Sale Order Report</field>
    <field name="model">sale.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">zra_smart_invoice.zra_custom_report_saleorder</field>
    <field name="binding_model_id" ref="model_sale_order"/>
</record>

3. Issue: It seems like the doc variable is not being initialized or passed to the template properly, resulting in the KeyError when accessing doc.fiscal_position_id.foreign_vat.

My Questions:

  1. How can I ensure that the doc variable is properly initialized in the report template?
  2. Is there a specific way to pass the current record to the QWeb template for reports in Odoo?
  3. Are there any debugging tips or best practices for handling similar issues with custom QWeb templates?

Any help or guidance would be greatly appreciated! Thank you.

0
Avatar
Zrušit
Avatar
Fayis
Nejlepší odpověď
  1. Modify your report template to ensure proper context and variable passing:
xmlCopy<template id="zra_custom_report_saleorder">
    <t t-call="web.external_layout">
        <t t-foreach="docs" t-as="doc">
            <t t-set="lang" t-value="doc.partner_id.lang"/>
            <t t-set="forced_vat" t-value="doc.fiscal_position_id.foreign_vat or ''"/>
            
            <!-- Your report content here -->
            <div class="page">
                <h2>Sale Order: <t t-esc="doc.name"/></h2>
                
                <!-- Add more content as needed -->
            </div>
            
            <!-- Add page break for multiple documents -->
            <t t-if="not loop.last">
                <div style="page-break-after: always;"/>
            </t>
        </t>
    </t>
</template>

Key changes:

  • Use t-foreach="docs" instead of manually setting doc
  • Add fallback for forced_vat
  • Include page break for multiple documents
  1. Ensure your report action is correctly configured:
<record id="zra_action_print_custom_report" model="ir.actions.report">
    <field name="name">Sale Order Custom Report</field>
    <field name="model">sale.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">zra_smart_invoice.zra_custom_report_saleorder</field>
    <field name="report_file">zra_smart_invoice.zra_custom_report_saleorder</field>
    <field name="binding_model_id" ref="sale.model_sale_order"/>
    <field name="binding_type">report</field>
</record>
  1. Debugging Tips:
  • Use t-debug="1" in your template to enable Odoo's QWeb debug mode
  • Add logging in your Python code to track report generation
  • Check that all referenced fields exist on the model

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
External Layout not showing in pdf
qweb odoo17
Avatar
Avatar
2
úno 25
3147
Custom background
qweb template odoo17
Avatar
0
pro 24
2127
I'm trying to limit the users into to see only the kiosk mode menu in attendance but it is throwing an error. Vyřešeno
security keyerror odoo17
Avatar
Avatar
1
čvn 25
1835
Change arabic font in qweb report
qweb font odoo17
Avatar
Avatar
Avatar
2
úno 25
2532
Odoo 17 generating blank QWeb.
xml qweb odoo17
Avatar
0
srp 24
2709
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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