Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
qwebdockeyerrorodoo17
1 Odpowiedz
3278 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Fayis
Najlepsza odpowiedź
  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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
External Layout not showing in pdf
qweb odoo17
Awatar
Awatar
2
lut 25
3156
Custom background
qweb template odoo17
Awatar
0
gru 24
2128
I'm trying to limit the users into to see only the kiosk mode menu in attendance but it is throwing an error. Rozwiązane
security keyerror odoo17
Awatar
Awatar
1
cze 25
1848
Change arabic font in qweb report
qweb font odoo17
Awatar
Awatar
Awatar
2
lut 25
2534
Odoo 17 generating blank QWeb.
xml qweb odoo17
Awatar
0
sie 24
2712
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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