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

Custom Qweb report works in html but not in PDF

S'inscrire

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

Cette question a été signalée
qwebreportswkhtmltopdfodoo12
1 Répondre
7885 Vues
Avatar
Thomas Brouwer

Hi ! I have a problem while generating a custom qweb report on Odoo 12.

In HTML, my report works fine, but when I want to generate it in PDF, I have the following error.

Odoo Server Error
Traceback (most recent call last): File "/home/thomas/Documents/Developpement/odoo/odoo/tools/safe_eval.py", line 350, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in <module> NameError: name 'menuweek_report' is not defined During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/thomas/Documents/Developpement/odoo/addons/web/controllers/main.py", line 1684, in report_download report_name = safe_eval(report.print_report_name, {'object': obj, 'time': time}) File "/home/thomas/Documents/Developpement/odoo/odoo/tools/safe_eval.py", line 373, in safe_eval pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2]) File "/home/thomas/Documents/Developpement/odoo/odoo/tools/pycompat.py", line 86, in reraise raise value.with_traceback(tb) File "/home/thomas/Documents/Developpement/odoo/odoo/tools/safe_eval.py", line 350, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in <module> ValueError: <class 'NameError'>: "name 'menuweek_report' is not defined" while evaluating 'menuweek_report' 

Here my report define in my XML file :

<odoo>
<report
id="action_report_menu"
string="Weeks menu"
model="dt.menu"
report_type="qweb-pdf"
name="dietetique.menuweek_report"
print_report_name="menuweek_report"
/>

<template id="menuweek_report">
<t t-call="web.html_container">
<t t-call="web.basic_layout">
<div class="article">
<hr />
<h2>Week's menu</h2>

<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
</thead>

<tbody>
<tr>
<td>Breakfast</td>
<t t-foreach="data['breakfast']" t-as="breakfast">
<td><span t-esc="breakfast" /></td>
</t>
</tr>

<tr>
<td>Lunch</td>
<t t-foreach="data['lunch']" t-as="lunch">
<td><span t-esc="lunch" /></td>
</t>
</tr>

<tr>
<td>Snack</td>
<t t-foreach="data['snack']" t-as="snack">
<td><span t-esc="snack" /></td>
</t>
</tr>

<tr>
<td>Dinner</td>
<t t-foreach="data['dinner']" t-as="dinner">
<td><span t-esc="dinner" /></td>
</t>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</template>
</odoo>

And here my Python code :


class MenuReport(models.AbstractModel):
_name = 'report.dietetique.menuweek_report'
_description = 'report menu'

@api.model
def _get_report_values(self, docids, data=None):
report_obj = self.env['ir.actions.report']
report = report_obj._get_report_from_name('dietetique.menuweek_report')

selected_menu = self.env['dt.menu'].sudo().search([
('id', '=', docids[0])
])

day = self.first_date_of_week(selected_menu.date.year, selected_menu.week_number) - timedelta(days=1)
start_date = day + timedelta(days=1)
end_date = start_date + timedelta(days=7)
breakfast = []
lunch = []
dinner = []
snack = []

i = 0
while i < 7:
day = day + timedelta(days=1)

menu_day = self.env['dt.menu'].sudo().search([
('date', '=', day)
])


breakfast.append((menu_day.breakfast_recipe.title if menu_day.breakfast_recipe.id else menu_day.breakfast_description))
lunch.append((menu_day.lunch_recipe.title if menu_day.lunch_recipe.id else menu_day.lunch_description))
dinner.append((menu_day.dinner_recipe.title if menu_day.dinner_recipe.id else menu_day.dinner_description))
snack.append((menu_day.snack_recipe.title if menu_day.snack_recipe.id else menu_day.snack_description))

i += 1

data = {
'start_date': start_date,
'end_date': end_date,
'breakfast': breakfast,
'lunch': lunch,
'dinner': dinner,
'snack': snack
}

docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
'data': data
}
return docargs

def first_date_of_week (self, year, week):
return datetime.strptime(f'{year}-W{int(week) - 1}-1', "%Y-W%W-%w").date()


I tried to unistall / reinstall wkhtmltopdf with no success ... I thing the problem is in the print_report_name attribute but I'm not sure !

If you can help you'll save my life :)

Thanks!         


0
Avatar
Ignorer
Avatar
Thomas Brouwer
Auteur Meilleure réponse

Found how to do ... I just put something like : 

print_report_name="('menu_'+str(object.week_number))"

And it works ... Sorry for that, topic can be mark as solved ;)

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é
Reporte de Odoo hecho con qweb no se actualiza
qweb reports Docker odoo12
Avatar
0
mars 25
1329
How to Change TABLE Format in QWEB reports? With different table Border and Color.? Résolu
qweb reports
Avatar
Avatar
Avatar
Avatar
Avatar
4
janv. 25
46165
QWEB Report template has inconsistent row heights (see screenshot)
qweb reports
Avatar
0
oct. 24
2331
Qweb reports inconsistent table row height
qweb reports
Avatar
0
oct. 24
5
custom layout qweb report odoo 12 Résolu
pdf qweb reports odoo odoo12
Avatar
Avatar
Avatar
2
mars 24
3828
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