İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

%if %endif does not seem to work with mail templates. Sent e-mails are blank.

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
emailtemplatesmailtemplateodoo8.0
8 Cevaplar
37796 Görünümler
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Why aren't %if %endif statements working in Odoo V8?

When you create a new e-mail template (under 'Marketing' > 'Mail templates' and when you then click on 'Edit template' you could add %if %endif statements. 
For example:

Dear ${(object.name or 'Sir / Madam')|safe} Thank you for registering.. We have these details: % if object.street: ${(object.street or '-') | safe} % endif

However, when you save this template and preview it you'll see it is not working. If I send the e-mail to the person it will be empty like this:

The content isn't printed and it seems that %if %endif ruins the whole e-mail.

Could anybody explain me why this is not working and what I'm doing wrong?

8
Avatar
Vazgeç
Avatar
Olivier Dony (odo)
En İyi Yanıt

When a non-empty [email] template is rendered blank, it means the rendering engine failed to parse the template.

This parsing problem is likely caused by a combination of factors:

  • The `%` syntax in Jinja2/Mako templates corresponds to line statements, and this only works as soon as the % sign is the first non-blank character on the line.
  • When you're dealing with HTML templates (as is the case for email templates), there's a very very good chance every line has a lot of invisible HTML tags before the % sign, or that the % sign is not on its own line.

To convince yourself, switch to the source view of your template (the rightmost icon in the HTML editor toolbar, looking like `[<>]`), and you'll see the mixup.

This is why it works when you change the templates in the XML source files of Odoo directly, as you're dealing with the raw HTML source in that case.

Solution: use the source view to write HTML directly, where you can use the full Jinja2 syntax including line statements. Some advanced users might also want to permanently switch to a plaintext version of the template body, by editing the form view of mail templates and forcing `widget="text"` for the `body_html` field. This is safer if you do advanced things, because the HTML editor could also reject/mess up templates that do not contain valid HTML, for example with % line statements in between `<tr>` or `<td>` elements in a table.
You could also try to use the ``<%`` and ``%>`` markers for block statements, but that will definitely fail with the HTML editor (even in source mode) because the angle brackets will be auto-escaped, being invalid HTML tags.

One more possible issue: watch out that you cannot use variables expressions on the line statement itself,  another common mistake that seems present in the issue description... 

This is invalid:
  % if object.street2: ${(object.street or '-') | safe}
  % endif

While this is valid (even if quite strange, mixing 2 different fields):
  % if object.street2:
      ${(object.street or '-') | safe}
  % endif

If you're not sure, check the Jinja2 documentation.

 

16
Avatar
Vazgeç
Avatar
Roland
En İyi Yanıt

We are having a similar issue in Odoo v9. Modifying the templates without being aware of the tag requirements can result in this error. However, editing the mail template again and using the 'code' view in the content editor to reinstate the default system template did not fix it. We compared this template to a fresh install and there was no difference.

In the end, the only thing that worked was finding the corresponding entry in the PostgreSQL database and reverting that back to the system default. Suddenly it works fine.

It certainly seems from here that the Odoo editor features for mail templates will break the formatting no matter how you submit them (wysiwyg or code view). I think it should be considered a bug.

1
Avatar
Vazgeç
Avatar
Michael Espinosa
En İyi Yanıt

Hi I am on version 15 of odoo and the way to use IF conditions is with
And inside the t you write what you want to do

0
Avatar
Vazgeç
Avatar
Ossi Mantylahti
En İyi Yanıt

Updating a bit for this original question for Odoo 13. The issue is still present and can easily cause total e-mail template rendering failing if one evaluation fails. We ran into this when modifying Spanish language version of the offer e-mail template. A typical use case is to check if a field has content or not before printing it out to the e-mail template as fields without any content set to them evaluate as text "False".

In our case we wanted to print tittle of the recipient if he has one ("Dear doctor Stephen Strange" if Stephen Strange has tittle defined). The field is object.partner_id.title.name and to check if it is filled, the code is following:

% if object.partner_id.title.name:
 ${object.partner_id.title.name}
% endif


So the whole block becomes:


<div style="font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;margin:0px;padding: 0px;">
    <p style="margin:15px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;padding: 2px; font-size: 13px;">
% set doc_name = 'oferta' if object.state in ('draft', 'sent') else 'orden'
        Estimado  
% if object.partner_id.title.name:
 ${object.partner_id.title.name}
% endif

${object.partner_id.name},
        <br><br>
        Su
% if ctx.get('proforma'):
            Pro forma factura ${doc_name} <strong style="font-weight:bolder;">${object.name}</strong>
% if object.origin:
                (with reference: ${object.origin} )
% endif
            con el precio total de <strong style="font-weight:bolder;">${format_amount(object.amount_total, object.pricelist_id.currency_id)}</strong> está disponible.
% else:
            ${doc_name} <strong style="font-weight:bolder;">${object.name}</strong>
% if object.origin:
                (with reference: ${object.origin} )
% endif
            con el precio total de <strong style="font-weight:bolder;">${format_amount(object.amount_total, object.pricelist_id.currency_id)}</strong> está listo para su revisión.
% endif
        <br><br>
        No dude en contactarnos si tiene alguna pregunta.
        <br><br></p>
    <p style="margin:15px;font-size:10px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;padding: 2px; font-size: 8px;">
Términos y condiciones generales: ...Terms and conditions here...
    </p>
</div>
            
0
Avatar
Vazgeç
Avatar
Victor Efimov
En İyi Yanıt

Oh, through years I've stumbled on this issue again. Thank for sharing this remedy!

0
Avatar
Vazgeç
Avatar
Luis Triana
En İyi Yanıt

There is an issue there the %if &endif is not working, i don't know why, the way i solved was this:

I did it in the mail template for sale.order:

     Order reference: ${(object.origin or 'No Origin Document'}

Hope this works in your mail template.


0
Avatar
Vazgeç
Avatar
Jonas Hoekman
En İyi Yanıt

I have almost the same problem the template is just not fully parsed, I have edited the default invoice and sales order templates and need to be able to restore these back to the original ones, on a development server I was able to do this by removing the templates and update the module account_voucher, but on my production server I have always 504 Gateway Time-out (nginx)

have tried another way by exporting these both the templates and the Dutch (BE)/ Nederlands (BE) translations on a new server installation and import it on the production server but seems not to work. 


0
Avatar
Vazgeç
Avatar
Lithin T
En İyi Yanıt

It should work if the fields are specifed are in the object you selected.
see the below sample applied to sale.order object which %if %endif works perfect.

  Order number: ${object.name}

  Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}

  Order date: ${object.date_order}
% if object.origin:   Order reference: ${object.origin}
% endif % if object.client_order_ref:   Your reference: ${object.client_order_ref}
% endif % if object.user_id:   Your contact: ${object.user_id.name} % endif 


 

0
Avatar
Vazgeç
Yenthe Van Ginneken (Mainframe Monkey)
Üretici

Thanks for your answer Lithin. Did you create a new template for mass mailing and through the webinterface though? This shouldn't work as it is even confirmed by the Odoo developers. This question was made to intentionally be answered by one of the Odoo developers & to promote it to the docs, as you can see in this Github report which explains everything: https://github.com/odoo/odoo/issues/4671

Lithin T

Yes Yenthe,I confirmed. through webinterface it is not working fine as expected.

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

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Odoo Email Template Question Çözüldü
email format templates odoo8.0
Avatar
Avatar
2
Eyl 21
6485
Email Template subject parameters Çözüldü
email templates
Avatar
Avatar
1
Şub 24
3606
Nothing rendered into email body_html (Odoo 16) Çözüldü
email templates
Avatar
1
Tem 23
4595
How to add company logo to email templates? Çözüldü
email templates
Avatar
Avatar
Avatar
Avatar
3
Ara 23
19935
Failed to render template Çözüldü
email templates
Avatar
Avatar
1
Şub 22
7142
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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