Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Qweb add condition on view

Naroči se

Get notified when there's activity on this post

This question has been flagged
viewsqwebbuttonconditionalcondition
1 Odgovori
2373 Prikazi
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
Opusti
Avatar
Hans Rickhoff 🚀 https://obd.digital
Best Answer

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
Opusti
Dilaw bedj
Avtor

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
Avtor

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
Avtor

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

Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Conditionally extend template with Odoo QWeb
views qweb
Avatar
Avatar
Avatar
3
jul. 17
11413
Xpath problems...Help me write this xpath
views qweb xpath
Avatar
Avatar
1
avg. 24
3250
Qweb if-else condition? Solved
qweb conditional if
Avatar
Avatar
Avatar
Avatar
Avatar
6
maj 24
112893
how can i click on a specific record and open a form
views button odoo13CE
Avatar
0
nov. 23
2807
Where are the barcode app's views?
views qweb barcode
Avatar
0
dec. 22
3443
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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