I am currently learning how to use Odoo. I am doing the following tutorial on PDF report generation.
The instruction is to allow the user to generate a pdf file gathering the offers that have been made for the purchase of a real estate property
It took me a long time to make the "Print" (on which clicking should generate a .pdf) button usable without getting an error telling me that wkhtmltopdf was not found on my computer.
It works now but I can't open the .pdf generated by Odoo.
Here is what I did on my side to get there
.xml files in Odoo
I work with version 16
I created a reports folder with two .xml files based on the examples in the tutorial
report_property_offers.xml
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="report_property_offers">
<t t-foreach="docs" t-as="property">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<h2>
<span t-field="property.name"/>
</h2>
<div>
<strong>Expected Price: </strong>
<span t-field="property.expected_price"/>
</div>
<table class="table">
<thead>
<tr>
<th>Price</th>
</tr>
</thead>
<tbody>
<t t-set="offers" t-value="property.mapped('offers_ids')"/>
<tr t-foreach="offers" t-as="offer">
<td>
<span t-field="offer.price"/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
</template>
</odoo>
event_reports.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="action_report_property_offers" model="ir.actions.report">
<field name="name">Report Property Offers</field>
<field name="model">estate.property</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">estate.report_property_offers</field>
<field name="report_file">estate.report_property_offers</field>
<field name="print_report_name">'Property Offers - %s' % (object.name or 'Attendee').replace('/','')</field>
<field name="binding_model_id" ref="model_estate_property"/>
<field name="binding_type">report</field>
</record>
</odoo>
The files are well indicated in the manifest in the data part
wkhtmltopdf installation
I work on Windows 11
- According to this wiki, i have installed version 0.12.5-1
- I have downloaded the wkhtmltox-0.12.5-1.msvc2015-win64.exe version on this page
- I added in the PATH of my environment variables the following path : C:\Program Files\wkhtmltopdf\bin
- The command wkthmltopdf --version in my console gives the following result:
wkhtmltopdf 0.12.5 (with patched qt)
- At that time, the pdf generation was still not working and Odoo told me every time : Unable to find Wkhtmltopdf on this system, i found this video by chance and I added in Odoo in
Settings->Technical->System Parameters
the following key :webkit_path : C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf
- When I start my Odoo application, I see the following line in logs :
INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe
The problem
After all this when I click on the print button, it generates a .pdf file on my computer. The problem is that I can't open the file (with chrome for example).
When I open the .pdf file with VSCode, I see that the data is present....but in html format !
<!DOCTYPE html>
<html lang="en-US" web-base-url="http://localhost:8069">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1"/>
<title>Odoo Report</title>
<link type="text/css" rel="stylesheet" href="/web/assets/debug/web.report_assets_common.css" data-asset-bundle="web.report_assets_common" data-asset-version="83a2b21"/>
....
<div class="page">
<h2>
<span>Big Villa</span>
</h2>
<div>
<strong>Expected Price: </strong>
<span>1,600,000.0</span>
</div>
....
How to make this file generated by Odoo is really a pdf and not html ?
Thank you in advance for your answers.