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

Qweb add condition on view

Suscribirse

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

Se marcó esta pregunta
viewsqwebbuttonconditionalcondition
1 Responder
2380 Vistas
Avatar
Dilaw bedj

i defined a button on my qweb template and i want to put a condition based on view_id so it appears only on the view with the id that i gave

1
Avatar
Descartar
Avatar
Hans Rickhoff 🚀 https://obd.digital
Mejor respuesta

First off, you'll need to ensure you have access to the view_id in your QWeb context. This might require a bit of backend preparation, depending on how and where you're planning to use this template.

Once you have view_id at your disposal, you can use an t-if directive in your QWeb template to show or hide your button based on the condition. Assuming view_id is the magical number you want to check against, your button code would look something like this



1
Avatar
Descartar
Dilaw bedj
Autor

The template is used to add a button that allow to show archives , it's like an activation button near to "new" button on the tree view , can you help me please how pass context from the backend to the template ?? here is my code
@api.model
def default_get(self, fields):
model_name = "bp.cdc"
view_name = 'cdc.tree'
view_id = self.env['ir.actions.act_window'].search([('model', '=', model_name)and('name','=',view_name)], limit=1).id
context = dict(self._context)
context.update({'default_view_id': view_id})
self = self.with_context(context)
return super(BpCdc, self).default_get(fields)

template : <templates xml:space="preserve">
<t t-name="cdcArchivesCdc.Buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_list_buttons')]" position="inside">
<button class="btn btn-secondary" type="button" t-on-click="display_archives"
t-if="view_id == 'view_cdc_tree'" id="display_archives_button">
Archives
</button>
</xpath>
</t>

js :
/** @odoo-module **/

import { ListController } from '@web/views/list/list_controller';
import { patch } from '@web/core/utils/patch';
import { useService } from '@web/core/utils/hooks';

let isChecked = false;

patch(ListController.prototype,{
setup() {
super.setup(...arguments);
this._action = useService("action");
this.isChecked = isChecked;
},

display_archives() {
isChecked = !isChecked;
this.isChecked = isChecked;

if (this.isChecked == true){
this._action.doAction({
type: "ir.actions.act_window",
name: "Cahiers des charges archivés",
domain: [["jours_restants", "=", 0]],
views: [[1927, "list"], [false, "form"]],
res_model: "bp.cdc",
target: 'self',
view_mode: "list,form"
});
}else if(this.isChecked == false){
this._action.doAction({
type: "ir.actions.act_window",
name: "Cahiers des charges en cours",
domain: [["jours_restants", "!=", 0]],
views: [[1927, "list"], [false, "form"]],
res_model: "bp.cdc",
target: 'self',
view_mode: "list,form"
});
}
}

});
btw i wanted to change the style of the button to btn-primary when its clicked and i didnt know how

Dilaw bedj
Autor

any help to get acces to the view_id in the qweb contaxt , i didnt know how to prepare it in the backend !!!

Dilaw bedj
Autor

any help to get acces to the view_id in the qweb contaxt , i didnt know how to prepare it in the backend !!!

¿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
Conditionally extend template with Odoo QWeb
views qweb
Avatar
Avatar
Avatar
3
jul 17
11418
Xpath problems...Help me write this xpath
views qweb xpath
Avatar
Avatar
1
ago 24
3257
Qweb if-else condition? Resuelto
qweb conditional if
Avatar
Avatar
Avatar
Avatar
Avatar
6
may 24
112919
how can i click on a specific record and open a form
views button odoo13CE
Avatar
0
nov 23
2821
Where are the barcode app's views?
views qweb barcode
Avatar
0
dic 22
3444
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.

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