Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to write for loop in inline_template Odoo15?

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
templatemailtemplatejinja2v15inlinetemplate
2 Réponses
12804 Vues
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
Ignorer
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
Auteur Meilleure réponse

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
Ignorer
Avatar
Joseph A. Flerimé
Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Template does not exist Résolu
template v15 OWL
Avatar
Avatar
Avatar
Avatar
Avatar
4
mai 25
14118
AttributeError: module 'odoo.addons.web.controllers.main' has no attribute 'jinja2' Résolu
jinja2 v15 AttributeError odoo.addons.web.controllers.main
Avatar
Avatar
Avatar
2
déc. 24
8708
ODOO 15 EE : export in xslx any reporting Résolu
report template v15 xslx
Avatar
Avatar
1
févr. 23
4627
ODOO 15 EE : Use docx template for all the accounting reports
docx report template v15
Avatar
0
févr. 23
2888
How to update text in template with a variable Odoo 15
template js odoosh v15
Avatar
0
juil. 22
3276
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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