Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar 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
  • Proyecto
  • 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

ValueError. How to customize a Qweb report properly by replacing "div[@class='page']"?

Suscribirse

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

Se marcó esta pregunta
qwebinheritreportodoo10
5 Respuestas
27689 Vistas
Avatar
Art

I'm trying to customize a report_invoice_document qweb report. Here is the source code:

<?xml version="1.0"?>
<t t-name="account.report_invoice_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})"/>
<div class="page">
    <div class="row">
        <div name="invoice_address" class="col-xs-5 col-xs-offset-7">
            <address t-field="o.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
            <span t-if="o.partner_id.vat">TIN: <span t-field="o.partner_id.vat"/></span>
        </div>
    </div>
<h2>
    <span t-if="o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')">Invoice</span>
    <span t-if="o.type == 'out_invoice' and o.state == 'proforma2'">PRO-FORMA</span>
    <span t-if="o.type == 'out_invoice' and o.state == 'draft'">Draft Invoice</span>
    <span t-if="o.type == 'out_invoice' and o.state == 'cancel'">Cancelled Invoice</span>
    <span t-if="o.type == 'out_refund'">Refund</span>
    <span t-if="o.type == 'in_refund'">Vendor Refund</span>
    <span t-if="o.type == 'in_invoice'">Vendor Bill</span>
    <span t-field="o.number"/>
</h2>
...

So I'm trying to replace "div[@class='page']" and build my own report with the following code and expect to see just the "Invoice_test_2" in my report when I print it out:

<odoo>	
    <data>
        <template id="practichem_report_invoice_layout" inherit_id="account.report_invoice_document">
            <xpath expr="//div[@class='page']" position="replace">
                <div class="page">
                    <h2>Invoice_test_2</h2>
                </div>
            </xpath>
        </template>
    </data>
</odoo>

But I'm getting the following error:

ValueError: Can't validate view:
Element '<xpath expr="//div[@name='invoice_address']">' cannot be located in parent view

What am I doing wrong?


1
Avatar
Descartar
Art
Autor

However, I can replace the <h2> tag with the following code and it works:

<template id="practichem_report_invoice_layout" inherit_id="account.report_invoice_document">

<xpath expr="//div[@class='page']//h2" position="replace">

<h2>Customer Invoice Report</h2>

</xpath>

</template>

Avatar
Marius Stedjan
Mejor respuesta

The reason for the error is that other templates ("report_invoice_document_inherit_sale", "account_invoice_report_duplicate", "report_invoice_document_inherit_sale" and "report_invoice_layouted") are already inheriting the account.report_invoice_document template.
When you inherit it yourself and remove the code that the inheriting templates are looking for, Odoo throws an error.. because it can't find the code.

The solution I found was to first make a new template inheriting "account.report_invoice" (this is the template calling the "account.report_invoice_document" on every document), and make this new template call my custom report_invoice_document template/report.

Something like this:

Inherit account.report_invoice to make it call my custom template/report:

<template id="report_invoice_inherit_mymodule" inherit_id="account.report_invoice">
<xpath expr="//t[@t-call='account.report_invoice_document']" position="replace">
            <t t-call="mymodule.report_invoice_document" t-lang="o.partner_id.lang"/>
</xpath>
</template>

Create new template for report_invoice_document

<template id="report_invoice_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})" />
<div class="page">
My Custom Report Here...
</div>
</t>
</template>
3
Avatar
Descartar
SonnyV

+1 for including a code-example of the suggested solution ;)

SHIV SHANKAR

Thanks for saving my day!! :)

Paolo M

Don't work on odoo 12, i have this error message:

Error to render compiling AST

AttributeError: 'dict' object has no attribute 'type'

Template: 1151

Path: /templates/t/t/t/t[1]

Node: <t t-set="lang" t-value="o.user_id.sudo().lang if o.type in ('in_invoice', 'in_refund')

Avatar
Art
Autor Mejor respuesta

So I added attribute primary=”True” inside the <template> tag and error was gone. But now no matter what I do with the report customization it doesn't affect anything and it prints out the original report.

So I still have a problem with the report inheritance.

1
Avatar
Descartar
SonnyV

primary="True" Means your report does not inherit from any other report. So Xpath expressions are of no use here since you just told Odoo this report is a new one.

This could be good, but then you will need to update the action (clicking the print invoice button for example) to call your new report and not the original invoice-layout.

Avatar
SonnyV
Mejor respuesta

Hello Art

The problem you are facing here is because you are replacing the entire page and another installed module inherits a part of this page you are replacing.

I checked the github odoo10 code and searched for <xpath expr="//div[@name='invoice_address']">
This made me notice the file addons/sale/report/invoice_report_templates.xml

In this file they inherit the report you are trying to inherit. When you update your module the invoice report gets reloaded and all it's 'children' as well. Since you remove everything from the report, Odoo is unable to validate the view in the sale addon above, since the xpath is looking for something inside the page and that is gone now, since the xml only consists of the page and the h2.

SO, you can test if I am right or not by adding a div with name invoice_address to your page, then install or update your module, this should solve your error, but you have an unwanted div in the report now.

What I would suggest is that you create a whole new report and an action, or find out how to make the existing action link to another xml file (your new xml file).

The problem with creating a whole new action would be that when you send the invoice by mail, the default layout would still be called and not your new one, so if you decide to go this road, bear in mind that there are references that should also be updated.


I hope I helped you or at least gave you a push in the right direction.

Sincerely

Sonny V.
ERP-consultant @ Cats and Dogs, BE


0
Avatar
Descartar
Marius Stedjan

Wow.. we replied at exactly the same time :-D

Check my answer for a solution to the "new action" problem.

¿Le interesa esta conversación? ¡Participe en ella!

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

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
[V.10] How to add Google Font in report odoo
qweb report odoo10
Avatar
Avatar
1
nov 17
6640
Change pdf file name in report definition Odoo 10 Resuelto
qweb report odoo10
Avatar
Avatar
Avatar
Avatar
4
oct 17
27258
Inherit Qweb Resuelto
v8 qweb inherit report
Avatar
Avatar
Avatar
Avatar
4
feb 24
49888
how to pass value of custom field to existing report and comput on it?
qweb inherit report v15
Avatar
0
may 22
4144
odoo10: How too call an attachment in an other qweb report ?
attachment qweb report odoo10
Avatar
Avatar
1
sept 19
4399
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información 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 totalmente integrado.

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