Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

How to write for loop in inline_template Odoo15?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
templatemailtemplatejinja2v15inlinetemplate
2 Odpowiedzi
12792 Widoki
Awatar
Tri Nanda

When Odoo still using jinja2 template, we can make for loop like example the code bellow:


% for i in range(len(object.invoice_line_ids)):
${i+1}${'.'.ljust(2)}
% endfor


But in Odoo15, the code doesn't work again,

I try to read this document and trying to apply the for loop like qweb code:

https://www.odoo.com/documentation/15.0/developer/reference/frontend/qweb.html#loops


Like the example bellow:

isn't it will be working on CDATA?


When I try to check the result, it showing the code directly, not the loopin result:


I also try to create for loop like the bellow ways:

{% for item in range(10) }}
{ item }
{% endfor }}

% for item in range(10):
${item}
% endfor

{% for item in range(10):}
${item}
{% endfor }

{% for item in range(10)}:
${item}
{% endfor }

{% item for item in range(10) %}

{% for item in range(10) %}
    {{ item }}
{% endfor %}

{% for item in range(10) %}
    {{{ item }}}
{% endfor %}

{{item for item in range(10)}}

{{% item for item in range(10) %}}

{% item for item in range(10) %}

But nothing is working in Odoo15 using the code above.


This is the worked code on Odoo13:
https://paste.opensuse.org/29906326


And I try to upgrade it to Odoo15 with few adjusemtn like bellow snippet of code:
https://paste.opensuse.org/75175196

But still don't work correctly.


My goals on this is, how to print customer invoice to dotmatrix printer, so I using CDATA.


So how to write for loop in inline_template Odoo15?,or is there any source, tutorial, documentations to learn about that things?


Thanks,

Tri Nanda

1
Awatar
Odrzuć
Joseph A. Flerimé

Hello Tri Nanda, did you find the solution to this problem? I have the same issue.

Joseph A. Flerimé

Interesting. Can you share the method, please?
Another question. My document doesn't show the actual format. It shows up as a string with this at the beginning {1: Markup(' Invoice INV/2022/00001\n .... how can I fix it?

Awatar
Tri Nanda
Autor Najlepsza odpowiedź

I have solved this, instead of doing loop in mail template, I do it in python directly instead, then render it to template.

Here is the example code:

invoice.py

class invoice(models.Model):
_name = 'account.move'
_inherit = 'account.move'

printer_data = fields.Char("Printer Data", readonly=True)

def action_refresh_printer_data(self):
company_name = self.env.company.name.rjust(45) if self.env.company.name else "My Company".rjust(45)
address = self.env.company.street.rjust(65) if self.env.company.street else "Address".rjust(65)
phone = self.env.company.phone if self.env.company.phone else "Phone"
mobile = self.env.company.mobile if self.env.company.mobile else "Mobile"
contact = str('Telp. ' + phone + 'Hp. ' + mobile).rjust(64)
invoice_name = 'INVOICE'.rjust(33) + ' ' + self.name if self.name else ''
stripe_space = ''.rjust(80, '-')
invoice_bill = 'Tagihan Faktur'.rjust(0) + ':'.rjust(4) + self.partner_id.display_name.ljust(
30) if self.partner_id else ''.ljust(30)
date = 'Tanggal'.rjust(13) + ':'.rjust(1) + str(self.invoice_date) if self.invoice_date else ''.ljust(30)
invoice_address = 'Alamat Pengiriman'.rjust(0) + ':'.ljust(0) + self.partner_id.display_name.ljust(
30) if self.partner_id else ''.ljust(30)
cashier = 'Kasir'.rjust(11) + ':'.rjust(3) + self.user_id.name if self.user_id else ''.ljust(20)
street = ''.rjust(19) + self.partner_id.street[:30].ljust(31) if self.partner_id.street else ''.ljust(31)
street2 = ''.rjust(19) + self.partner_id.street2[:30].ljust(31) if self.partner_id.street2 else ''.ljust(31)
mobile = ''.rjust(19) + self.partner_id.mobile[:13].ljust(31) if self.partner_id.mobile else ''.ljust(31)
number = 'No'.ljust(3)
product_name = 'Nama Barang'.ljust(40)

qty = 'Qty'.ljust(0)
price = 'Harga'.rjust(13)
subtotal = 'Subtotal'.rjust(16)

sign = 'Tanda Terima'.rjust(10) + ''.ljust(6) + 'Sopir'.rjust(10) + ''.ljust(8) + 'Hormat Kami'.rjust(10)
total = 'Total:'.rjust(13) + "{:4,.0f}".format(self.total_before_discount).rjust(15)
discount = 'Diskon:'.rjust(60) + "{:4,.0f}".format(self.ks_amount_discount).rjust(
15) if self.ks_amount_discount else 'Diskon:'.rjust(60) + '-'.rjust(11)
amount_residual = ''.rjust(12, '-') + ''.ljust(7) + ''.rjust(12, '-') + ''.rjust(4) + ''.rjust(13,
'-') + 'Sisa:'.rjust(
12) + "{:4,.0f}".format(self.amount_residual).rjust(15)

paid = 'Bayar:'.rjust(60) + "{:4,.0f}".format(json.loads(self.invoice_payments_widget)['content'][0]['amount'] \
if self.invoice_payments_widget != 'false' else 0).rjust(
15) if self.invoice_payments_widget != False else '{}'

data_list = []

for i in range(len(self.invoice_line_ids)):
data_list.append([str(i + 1) + '.'.ljust(2),
self.invoice_line_ids[i].name[:34].ljust(34) if self.invoice_line_ids[
i].name else ''.ljust(34),
str(int(self.invoice_line_ids[i].quantity)).rjust(9) if self.invoice_line_ids[
i].quantity else ''.ljust(9),
"{:4,.0f}".format(self.invoice_line_ids[i].price_unit).rjust(13) if self.invoice_line_ids[
i].price_unit else ''.ljust(13),
"{:4,.0f}".format(self.invoice_line_ids[i].price_subtotal).rjust(16) if
self.invoice_line_ids[i].price_subtotal else ''.ljust(16)])

data = company_name + '\n' + address + '\n' + contact + '\n' + stripe_space + '\n' + invoice_name + '\n' + \
stripe_space + '\n' + invoice_bill + date + '\n' + invoice_address + cashier + '\n' + street + '\n' + \
street2 + '\n' + mobile + '\n' + stripe_space + '\n' + number + product_name + qty + price + subtotal + '\n' + \
stripe_space + '\n'
for count, value in enumerate(data_list):
data2 = ''.join(value)
data = data + data2 + '\n'
data = data + '\n' + stripe_space + '\n' + sign + total + '\n' + discount + '\n' + paid + '\n' + amount_residual

self.printer_data = data

templates.xml

invoice.xml



I also try to sell it on odoo apps:

https://apps.odoo.com/apps/modules/15.0/dotmatrix/


Feel free to contact me if anyone need help.

Thanks,

Tri Nanda

1
Awatar
Odrzuć
Awatar
Joseph A. Flerimé
Najlepsza odpowiedź

I found this link Core changes between v14 -> v15 | Odoo

I don't think the inline_template has support for loops. They use Qweb for the email body.

1
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Template does not exist Rozwiązane
template v15 OWL
Awatar
Awatar
Awatar
Awatar
Awatar
4
maj 25
14107
AttributeError: module 'odoo.addons.web.controllers.main' has no attribute 'jinja2' Rozwiązane
jinja2 v15 AttributeError odoo.addons.web.controllers.main
Awatar
Awatar
Awatar
2
gru 24
8697
ODOO 15 EE : export in xslx any reporting Rozwiązane
report template v15 xslx
Awatar
Awatar
1
lut 23
4623
ODOO 15 EE : Use docx template for all the accounting reports
docx report template v15
Awatar
0
lut 23
2883
How to update text in template with a variable Odoo 15
template js odoosh v15
Awatar
0
lip 22
3268
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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