A comprehensive guide to developing applications and customizations with Odoo 10.0, covering all aspects from module creation to UI design. Includes practical examples and step-by-step instructions to help developers master the Odoo platform.
Odoo, a popular open-source ERP platform, has released its latest version - Odoo 10.0, with a wide range of new features and improvements. One of the key enhancements in this version is the development framework, which allows users to build custom modules and apps using Python programming language. In this article, we will walk through a step-by-step example of how to create a simple PDF report module in Odoo 10.0.
Setting up the Development Environment
Before we start developing our PDF report module, we need to set up the development environment. To do this, we need to install Odoo 10.0 on our system. You can download the latest version of Odoo from the official website and follow the installation instructions.
Once Odoo is installed, we need to create a new custom module directory in the addons directory of Odoo. Let's name our module 'pdf_report'. Inside this directory, we need to create the following files:
- __init__.py
- __manifest__.py
- report.xml (for defining our PDF report)
- models.py (for defining the model and data)
- controllers.py (for defining controller logic)
- templates.xml (for defining report template)
Defining the Model
In the models.py file, we will define our custom model for the PDF report. Let's create a simple model with a single field 'name':
```python
from odoo import models, fields
class PDFReport(models.Model):
_name = 'pdf.report'
name = fields.Char('Name')
```
Defining the Report Template
In the templates.xml file, we will define the template for our PDF report. Let's create a simple template with a header and footer:
```xml
PDF Report
```
Defining the Report
In the report.xml file, we will define the PDF report using QWeb template. Let's create a simple report that displays the 'name' field from our model:
```xml
model=pdf.report
string=PDF Report
report_type=qweb-pdf
name=pdf_report.report_pdf
file=pdf_report.report_pdf
/>
```
Defining the Controller
In the controllers.py file, we will define the controller logic for generating the PDF report. Let's create a simple controller that fetches the data from the model and sends it to the QWeb template:
```python
from odoo import http
from odoo.http import request
class PDFReportController(http.Controller):
@http.route('/pdf_report', type='http', auth='public')
def generate_pdf_report(self):
pdf_report_obj = request.env['pdf.report']
pdf_report_ids = pdf_report_obj.sudo().search([])
values = {
'docs': pdf_report_ids,
}
return request.env['report'].get_report_from_name('pdf_report.report_pdf').render(values)
```
Testing the PDF Report Module
Now that we have defined all the necessary components for our PDF report module, let's test it by accessing the following URL:
```
http://localhost:8069/pdf_report
```
This will generate a PDF report with the data from our model and display it in the browser. You can also download the PDF report by clicking on the download button.
Conclusion
In this article, we have demonstrated how to create a simple PDF report module in Odoo 10.0 using the new development framework. By following the steps outlined in this example, you can easily create custom modules and apps to extend the functionality of Odoo according to your business needs.
Odoo 10.0 offers a powerful development platform that allows users to build custom modules with ease. Whether you are a seasoned developer or a beginner, Odoo provides extensive documentation and support to help you get started with custom development. So, why wait? Start developing your own Odoo modules today and take your business to the next level.