Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to write for loop in inline_template Odoo15?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
templatemailtemplatejinja2v15inlinetemplate
2 Replies
12803 Tampilan
Avatar
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
Avatar
Buang
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?

Avatar
Tri Nanda
Penulis Jawaban Terbai

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
Avatar
Buang
Avatar
Joseph A. Flerimé
Jawaban Terbai

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
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Template does not exist Diselesaikan
template v15 OWL
Avatar
Avatar
Avatar
Avatar
Avatar
4
Mei 25
14117
AttributeError: module 'odoo.addons.web.controllers.main' has no attribute 'jinja2' Diselesaikan
jinja2 v15 AttributeError odoo.addons.web.controllers.main
Avatar
Avatar
Avatar
2
Des 24
8706
ODOO 15 EE : export in xslx any reporting Diselesaikan
report template v15 xslx
Avatar
Avatar
1
Feb 23
4627
ODOO 15 EE : Use docx template for all the accounting reports
docx report template v15
Avatar
0
Feb 23
2888
How to update text in template with a variable Odoo 15
template js odoosh v15
Avatar
0
Jul 22
3274
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik 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