Skip to Content
Odoo Меню
  • Увійти
  • Спробуйте це безкоштовно
  • Додатки
    Фінанси
    • Бухоблік
    • Виставлення рахунку
    • Витрати
    • Електронні таблиці (BI)
    • Документи
    • Підпис
    Продажі
    • CRM
    • Продажі
    • POS Магазин
    • POS Ресторан
    • Підписки
    • Оренда
    Веб-сайти
    • Конструктор веб-сайту
    • Електронна комерція
    • Блог
    • Форум
    • Живий чат
    • Електронне навчання
    Ланцюг поставок
    • Склад
    • Виробництво
    • PLM
    • Купівлі
    • Технічне обслуговування
    • Якість
    Кадри
    • Співробітники
    • Рекрутинг
    • Відпустки
    • Оцінювання
    • Рекомендації
    • Автотранспорт
    Маркетинг
    • Маркетинг соцмереж
    • Email-маркетинг
    • SMS-маркетинг
    • Події
    • Автом. маркетингу
    • Опитування
    Послуги
    • Проект
    • Табелі
    • Виїзне обслуговування
    • Служба підтримки
    • Планування
    • Призначення
    Продуктивність
    • Обговорення
    • Схвалення
    • IoT
    • IP-телефонія
    • База знань
    • WhatsApp
    Сторонні модулі Odoo Studio Платформа Odoo Cloud
  • Сфери
    Роздрібна торгівля
    • Книжковий магазин
    • Магазин одягу
    • Магазин меблів
    • Продуктовий магазин
    • Магазин будівельних матеріалів
    • Магазин іграшок
    Food & Hospitality
    • Бар та паб
    • Ресторан
    • Фастфуд
    • Guest House
    • Дистриб'ютор напоїв
    • Hotel
    Нерухомість
    • Real Estate Agency
    • Архітектурна фірма
    • Будівництво
    • Управління нерухомістю
    • Садівництво
    • Асоціація власників нерухомості
    Консалтинг
    • Бухгалтерська компанія
    • Партнер Odoo
    • Агенція маркетингу
    • Юридична фірма
    • Придбання Талантів
    • Аудит та сертифікація
    Виробництво
    • Textile
    • Metal
    • Меблі
    • Їжа
    • Brewery
    • Корпоративні подарунки
    Здоров'я & Фітнес
    • Спортивний клуб
    • Оптика
    • Фітнес-центр
    • Практики здоров'я
    • Аптека
    • Салон краси
    Trades
    • Ремонтник
    • IT-обладнання та Підтримка
    • Системи сонячної енергії
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Інші
    • Nonprofit Organization
    • Екологічна агенція
    • Оренда білбордів
    • Фотографія
    • Лізинг велосипедів
    • Реселлер програмного забезпечення
    Browse all Industries
  • Спільнота
    Навчання
    • Навчальний посібник
    • Документація
    • Сертифікації
    • Тренування
    • Блог
    • Подкаст
    Сприяйте Освіті
    • Програма навчання
    • Бізнес гра Scale Up!
    • Відвідайте Odoo
    Отримайте програмне забезпечення
    • Завантаження
    • Порівняйте версії
    • Релізи
    Співпрацюйте
    • Github
    • Форум
    • Події
    • Переклади
    • Стати партнером
    • Services for Partners
    • Зареєструйте вашу бухгалтерську фірму
    Отримайте послуги
    • Знайдіть партнера
    • Знайдіть бухгалтера
    • Зустріньтеся з консультантом
    • Послуги з впровадження
    • Референси клієнтів
    • Підтримка
    • Оновлення
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Отримати демо
  • Ціни
  • Допомога

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

  • CRM
  • e-Commerce
  • Бухоблік
  • Склад
  • PoS
  • Проект
  • MRP
All apps
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
All Posts Люди Значки
Мітки (View all)
odoo accounting v14 pos v15
Про цей форум
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
All Posts Люди Значки
Мітки (View all)
odoo accounting v14 pos v15
Про цей форум
Допомога

[V14] Conditionally change attribute

Підписатися

Отримуйте сповіщення про активність щодо цієї публікації

Це запитання позначене
conditionalattributev14
1 Відповісти
12030 Переглядів
Аватар
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
Аватар
Відмінити
Аватар
Ray Carnes (ray)
Найкраща відповідь

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
Аватар
Відмінити
Tristan Fullmer
Автор

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
Автор

Thanks for your answer Ray!

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

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

Реєстрація
Related Posts Відповіді Переглядів Дія
14: How to set conditional domain on res_partner based on move_type in account.move.form?
views conditional Domain v14
Аватар
Аватар
Аватар
2
жовт. 21
5296
How can I mask Tax ID for most Users, but allow access to certain Users? Вирішено
field conditional v14 mask
Аватар
Аватар
1
вер. 21
3116
ver 14: hide a page conditionally under notebook, but showing error (please...)
hide page conditional v14
Аватар
Аватар
Аватар
2
черв. 21
5213
Odoo14 alternative for Automated Translations through Gengo API module
v14
Аватар
Аватар
Аватар
Аватар
3
вер. 25
3608
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Аватар
0
серп. 25
1059
Спільнота
  • Навчальний посібник
  • Документація
  • Форум
Open Source
  • Завантаження
  • Github
  • Runbot
  • Переклади
Послуги
  • Хостинг Odoo.sh
  • Підтримка
  • Оновлення
  • Кастомні доробки
  • Навчання
  • Знайдіть бухгалтера
  • Знайдіть партнера
  • Стати партнером
Про нас
  • Наша компанія
  • Торгові активи
  • Зв'яжіться з нами
  • Вакансії
  • Події
  • Подкаст
  • Блог
  • Клієнти
  • Юридичні документи • Конфіденційність
  • Безпека
الْعَرَبيّة 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 - це набір програм для роботи з відкритим кодом, які охоплюють всі ваші потреби компанії: CRM, електронна комерція, бухгалтерський облік, склад, точка продажу, управління проектами тощо.

Унікальна пропозиція Odoo - це одночасно дуже проста у використанні та повністю інтегрована.

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