Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Custom Qweb report works in html but not in PDF

Subscribe

Get notified when there's activity on this post

This question has been flagged
qwebreportswkhtmltopdfodoo12
1 Reply
7890 Views
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
Discard
Avatar
Thomas Brouwer
Author Best Answer

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
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Reporte de Odoo hecho con qweb no se actualiza
qweb reports Docker odoo12
Avatar
0
Mar 25
1329
How to Change TABLE Format in QWEB reports? With different table Border and Color.? Solved
qweb reports
Avatar
Avatar
Avatar
Avatar
Avatar
4
Jan 25
46167
QWEB Report template has inconsistent row heights (see screenshot)
qweb reports
Avatar
0
Oct 24
2333
Qweb reports inconsistent table row height
qweb reports
Avatar
0
Oct 24
5
custom layout qweb report odoo 12 Solved
pdf qweb reports odoo odoo12
Avatar
Avatar
Avatar
2
Mar 24
3841
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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