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

Odoo qweb dynamic html generation

S'inscrire

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

Cette question a été signalée
xmlqwebreporting8.0
15 Réponses
16031 Vues
Avatar
Paul Catinean

Hello everyone

I wanted to know how does one handle a dynamically generated xml code that is invalid before being proccessed 

For example generating a table that displays the information in two cells per row:

<t t-foreach="list" t-as="item">

    <tr t-if="item_even">

        <td><span t-field="item"></td>

    </tr t-if="item_odds>

</t>

This will not work since it's invalid xml because the closing tag has a property and neither will <t t-if="condition"> </tr> </t> since the closing tag is embeded in what the xml sees another tag

Alternatives to this would be looping over grouped items, two by two or how many you want per column, and placing them inside one <tr> in one loop but it's not that elegant

Any way around this?

3
Avatar
Ignorer
Paul Catinean
Auteur

That is the purpose of the var_last var_first and var_odds var_even (in your case i_last, i_first) to hold index information see: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#loops The logic of achieving this is not the problem it's just that it does not work in qweb.You need two in the same to make a two columned table. This means you have to open on even and close on odds so the end result is 1 2

Yenthe Van Ginneken (Mainframe Monkey)

Hmm I see I understood your question wrong so I've deleted my reply as it wasn't of any value then. I'm not sure about this though, interesting question. Upvoted it :)

Yenthe Van Ginneken (Mainframe Monkey)

Have a look at this by the way: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#attributes

Paul Catinean
Auteur

My theory (though could very well be wrong) is that the error comes in even before qweb can kick into action.If qweb would come in and resolve the t-tags and loops it would result in valid xml code But before the qweb is parsed it's actually read as standard xml where it sees a closing tag having a attribute which is invalid syntax and stops dead.It does not know that the attribute is actually a qweb condition that will output a empty closing tag which will in the end compose valid XML

Leonardo Donelli

IMO looping on a grouped list it's the correct way and a lot more elegant than a conditional closing tag.

Sajin Aziz

is this what you are trying for (last answer) , it works in qweb reports.

Avatar
Leonardo Donelli
Meilleure réponse

You say:

Alternatives to this would be looping over grouped items, two by two or how many you want per column, and placing them inside one <tr> in one loop but it's not that elegant

But I don't think that's true at all. Conceptually, it better represents what you are trying to do, while the conditional closing tag feels more like an hack.

Also notice that your code would not generate valid XML if the number of items is odd (it would never close the last <tr> tag), and generally that's the problem with what you wanted to do: you cannot be sure that the generated html will be valid after evaluation because it depends on the context.

To create a grouped list with groups of size n:

[ l[i:i+n] for i in xrange(0, len(l), n) ]

Examples:  

 l = range(7)
>>> [ l[i:i+2] for i in xrange(0, len(l), 2) ]
[[0, 1], [2, 3], [4, 5], [6]]
>>> [ l[i:i+3] for i in xrange(0, len(l), 3) ]
[[0, 1, 2], [3, 4, 5], [6]]
>>> [ l[i:i+4] for i in xrange(0, len(l), 4) ]
[[0, 1, 2, 3], [4, 5, 6]]

1
Avatar
Ignorer
Paul Catinean
Auteur

While indeed it is a limitation you cannot do conditional closing tags your explanation makes a lot of sense and it is the proper/better method of tackling this issue regardless of the templating system.Thank you for your complete and eloquent answer!

Avatar
Sajin Aziz
Meilleure réponse

try This :

 <tr>
            <t t-foreach="list" t-as="item">

                    <td><span t-esc="item_index"/></td>
                    <t t-if="item_odd">
                        &lt;/tr &gt;
                        &lt;tr &gt;
                    </t>
            </t>

</tr>

5
Avatar
Ignorer
Paul Catinean
Auteur

Sajin indeed this solution works and provides the possibility of doing conditional closing tags i.e parsing xml that would otherwise be invalid.Thank you for your help!

Mersed Kahrimanovic

Actually this is the only and complete solution on the question above. I can confirm that it works now as well. Grouping is indeed better in some of the solutions - but somtimes - grouping is bad idea as well. Consider the "one data source" for the lets say select field. If you want to implement behaviour based on the data source - and present that select field as well on the frontend, then its much easier to have one object instead grouped one.

Avatar
Hardikgiri Goswami
Meilleure réponse

Hello Paul,

As I observed you theory is on opposite way of qweb tag (specially for the ending tag).

But I can understand what kind of output you want.

You need to create list of list.

I am explaining by your example

<t t-foreach="list" t-as="item">

    <tr t-if="item_even">

        <td><span t-field="item"></td>

    </tr t-if="item_odds>

</t>

Here "list" is a list something like [1,2,3,4,5].
and it will print like 
1
2
3
4
5

and you want it like
1   2
3   4
5

If you want something like this, then you need to pass list of list like,
your "list" should be like [[1,2],[3,4],[5]] instead of [1,2,3,4,5].
Now you xml code should be something like.

<t t-foreach="list" t-as="row">

    <tr>
        <t t-foreach="row" t-as="item">

            <td><span t-field="item"></td>
        </t>
    </tr>

</t>

and python code for converting simple "list" this "list of list" is

Option 1 :


your_list = [1,2,3,4,5,6,1,2,3,4,5,6]
new_list = []
for i in range(0, len(your_list), 2):
    temp_list = [your_list[i]]
    if i < len(your_list)-1:
        temp_list.append(your_list[i+1])
    new_list.append(temp_list)
print new_list

Option 2 :

your_list = [1,2,3,4,5,6,1,2,3,4,5,6]
new_list1 = zip(*[iter(your_list)]*2)
print new_list1

4
Avatar
Ignorer
Paul Catinean
Auteur

Indeed Hardikgiri that is the alternative when looping through a grouped set

Hardikgiri Goswami

As per my knowledge solution for this question is not possible. I have tried two other ways but I got the error and stuck over there.

Avatar
Aldennis
Meilleure réponse

I have a similar requirement but with three columns for a pay slip report. 

The solution that I came up with is to construct some part of the Qweb report in python and save the generated html in a text field.


Call the text field in the Qweb report like this:

<div t-field="o.field_name" t-options="{'widget':'html'}"/>


When the Qweb report gets generated, the content of the text field is rendered together with the rest of the report. I use this approach in Odoo13 but I guess will work on previous versions as well.

0
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é
Replace stock inventory report
stock xml qweb reporting
Avatar
0
nov. 15
4058
How can I display all tasks (including completed ones) in a QWeb report in Odoo?
qweb reporting
Avatar
Avatar
2
sept. 24
3066
t-att-href url get error Résolu
xml qweb
Avatar
Avatar
2
avr. 23
9711
odoo report columns not displaying
xml qweb layout reporting css
Avatar
0
mars 23
3319
v15: object has no attribute 'generate_report'
xml reporting
Avatar
0
mai 22
2874
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