Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
qwebdockeyerrorodoo17
1 Responder
3275 Vistas
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
Descartar
Avatar
Fayis
Mejor respuesta
  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
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
External Layout not showing in pdf
qweb odoo17
Avatar
Avatar
2
feb 25
3154
Custom background
qweb template odoo17
Avatar
0
dic 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. Resuelto
security keyerror odoo17
Avatar
Avatar
1
jun 25
1843
Change arabic font in qweb report
qweb font odoo17
Avatar
Avatar
Avatar
2
feb 25
2534
Odoo 17 generating blank QWeb.
xml qweb odoo17
Avatar
0
ago 24
2711
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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