Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Guest House
    • Drankenhandelaar
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Solar Energy Systems
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC Services
    Others
    • Nonprofit Organization
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

[V14] Conditionally change attribute

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
conditionalattributev14
1 Beantwoorden
11952 Weergaven
Avatar
Tristan Fullmer

I am trying to do some styling on a project kanban tile based on a selection field I added to the task. Here is a snippet of my attempt.


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

          <!-- Color border -->

          <xpath expr="//templates/t/div" position="attributes">

            <t t-if="record.order_type.raw_value == 'store'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: steelblue;</attribute>

            </t>

            <t t-else-if="record.order_type.raw_value == 'curb'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: firebrick;</attribute>

            </t>

            <t t-else-if="record.order_type.raw_value == 'delivery'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: mediumseagreen;</attribute>

            </t>

          </xpath>

This results in only the last attribute getting used regardless of the value of order_type. I think this is because the <t> elements are just getting ignored. I have also tried to use the <t t-esc> to embed the color text in the value, but that resulted in outputting an empty string. I also tried attaching t-if attributes on the <attribute> tag itself. None of these things have worked.


Any suggestions on how to apply a style based on the value of the task?

0
Avatar
Annuleer
Avatar
Ray Carnes (ray)
Beste antwoord

EDIT:

I took a closer look at what you are wanting to do.

For your specific example, I was able to get this:



I created a custom selection field that stored the HTML codes of the colors as the Value:



Then used this syntax for changing the style attribute:

<attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: {{record.x_order_type.raw_value or 'white'}};</attribute> 

Note that you don't actually need the t-attf- prefix when you are not using substitution to compute attributes on-the-fly - see https://www.odoo.com/documentation/14.0/developer/reference/qweb.html#attributes



Original Answer:


The supported t- directives for IF/THEN/ELSE are:

t-if
t-elif
t-else

t-else-if is not supported.


See a code example at https://github.com/odoo/odoo/blob/14.0/addons/product/report/product_packaging.xml#L31

<img alt="Barcode" t-if="len(packaging.barcode) == 13"
<img alt="Barcode" t-elif="len(packaging.barcode) == 8"
<img alt="Barcode" t-else=""
4
Avatar
Annuleer
Tristan Fullmer
Auteur

Thanks for the correction on my syntax, but this unfortunately didn't solve my problem. The third attribute element is always applied, regardless of the value of the order_type variable. Here is my updated xml: (Yes I know there are redundant t-if's here)

<t t-if="record.order_type.raw_value == 'store'">

<attribute t-if="record.order_type.raw_value == 'store'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: steelblue;</attribute>

</t>

<t t-elif="record.order_type.raw_value == 'curb'">

<attribute t-if="record.order_type.raw_value == 'curb'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: firebrick;</attribute>

</t>

<t t-elif="record.order_type.raw_value == 'delivery'">

<attribute t-if="record.order_type.raw_value == 'delivery'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: mediumseagreen;</attribute>

</t>

Ray Carnes (ray)

See the EDIT to my answer.

Tristan Fullmer
Auteur

Thanks for your answer Ray!

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
14: How to set conditional domain on res_partner based on move_type in account.move.form?
views conditional Domain v14
Avatar
Avatar
Avatar
2
okt. 21
5175
How can I mask Tax ID for most Users, but allow access to certain Users? Opgelost
field conditional v14 mask
Avatar
Avatar
1
sep. 21
3072
ver 14: hide a page conditionally under notebook, but showing error (please...)
hide page conditional v14
Avatar
Avatar
Avatar
2
jun. 21
5155
Odoo14 alternative for Automated Translations through Gengo API module
v14
Avatar
Avatar
Avatar
Avatar
3
sep. 25
3479
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Avatar
0
aug. 25
960
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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