You are currently viewing How to Create a Custom Revenue Report in Odoo

How to Create a Custom Revenue Report in Odoo

How to Create a Custom Revenue Report in Odoo. In Odoo, generating financial reports, such as a revenuea report, is essential for monitoring business performance. This article provides a step-by-step guide on how to create a custom Revenue Report in Odoo that calculates the total revenue based on sales invoices over a specified period.

Also Read:

How to Create a Custom Revenue Report in Odoo

Before you begin, make sure you have the following prerequisites:

  • Odoo Environment: A running Odoo instance.
  • Basic Knowledge of Odoo Modules: Understanding Odoo’s framework, models, views, and reports.
  • Access to the Accounting Module: The accounting module should be installed for revenue-related reports.
  • Custom Odoo Module: We will create a custom module to define and manage the revenue report.

Step 1: Create a Custom Revenue Report in Odoo

To start, you need to create a new custom Odoo module where we will define the custom report. If you’re new to Odoo development, creating a custom module involves the following steps:

  1. Create the directory: Navigate to your Odoo addons directory and create a folder for your custom module (e.g., custom_revenue_report).
  2. Create the required files:
    • __init__.py: To indicate it’s a Python package.
    • __manifest__.py: To define module metadata.
    • models.py: For the revenue report model.
    • views.xml: For defining the user interface and report.
    • reports.xml: (Optional) For defining a QWeb report template.

Let’s dive deeper into each part of the custom module.

Step 2: Define the Revenue Report Model

Create the file models.py in your custom module directory. This model will define the logic for calculating the total revenue from invoices within a given date range.

python

from odoo import models, fields, api

class RevenueReport(models.Model):
_name = ‘revenue.report’
_description = ‘Revenue Report’

start_date = fields.Date(string=“Start Date”)
end_date = fields.Date(string=“End Date”)
total_revenue = fields.Float(string=“Total Revenue”, compute=‘_compute_total_revenue’)

def _compute_total_revenue(self):
for record in self:
# Get all invoices between the start_date and end_date
invoices = self.env[‘account.move’].search([
(‘type’, ‘=’, ‘out_invoice’), # Only sales invoices
(‘invoice_date’, ‘>=’, record.start_date),
(‘invoice_date’, ‘<=’, record.end_date),
(‘state’, ‘=’, ‘posted’) # Only posted invoices
])

total = 0.0
for invoice in invoices:
total += invoice.amount_total # Total amount for each invoice

record.total_revenue = total

Explanation:

  • start_date and end_date: These fields allow the user to select a date range for the report.
  • total_revenue: This computed field calculates the total revenue by summing the total amounts of all invoices within the selected date range.
  • _compute_total_revenue: The method that searches for sales invoices (out_invoice), filters them by the date range, and calculates the total revenue.

Step 3: Define the Report View

Next, define the form view where users will input the start and end dates for the revenue report. This will go in the views.xml file.

xml
<odoo>
<data>
<!-- Revenue Report Form View -->
<record id="view_revenue_report_form" model="ir.ui.view">
<field name="name">revenue.report.form</field>
<field name="model">revenue.report</field>
<field name="arch" type="xml">
<form string="Revenue Report">
<group>
<field name="start_date"/>
<field name="end_date"/>
</group>
<group>
<field name="total_revenue" readonly="1"/>
</group>
<footer>
<button string="Generate Report" type="object" name="action_generate_report"/>
</footer>
</form>
</field>
</record>
<!– Revenue Report Action –>
<record id=“action_revenue_report” model=“ir.actions.act_window”>
<field name=“name”>Revenue Report</field>
<field name=“res_model”>revenue.report</field>
<field name=“view_mode”>form</field>
<field name=“view_id” ref=“view_revenue_report_form”/>
</record>

<!– Add the menu item –>
<menuitem id=“menu_revenue_report” name=“Revenue Report” parent=“account.menu_finance” action=“action_revenue_report”/>
</data>
</odoo>

Explanation:

  • Form View: The form lets users input the start and end dates.
  • action_generate_report: A button that triggers the action to calculate and display the revenue.
  • Menu Item: The menu item under the Accounting module will make the report easily accessible.

Step 4: Define the Report (Optional)

If you want the report to be printable as a PDF, you can define a QWeb template. Create a reports.xml file in the module.

xml
<odoo>
<data>
<template id="report_revenue_report">
<t t-call="web.basic_layout">
<div class="page">
<h2>Revenue Report</h2>
<p><strong>Date Range: </strong><t t-esc="doc.start_date"/> to <t t-esc="doc.end_date"/></p>
<p><strong>Total Revenue: </strong><t t-esc="doc.total_revenue"/></p>
</div>
</t>
</template>
<report
id=“action_report_revenue”
model=“revenue.report”
string=“Revenue Report”
report_type=“qweb-pdf”
file=“custom_revenue_report.report_revenue_report”
name=“custom_revenue_report.report_revenue_report”
attachment_use=“False”/>

</data>
</odoo>

Explanation:

  • QWeb Template: This defines how the report will be displayed in PDF format.
  • report_revenue_report: The name of the QWeb template that will be used for the PDF generation.

Step 5: Add the Module Metadata

Create the __manifest__.py file to define the module’s metadata.

python
{
'name': 'Custom Revenue Report',
'version': '1.0',
'category': 'Accounting',
'summary': 'Generates a revenue report based on sales invoices',
'author': 'Your Name',
'depends': ['account'],
'data': [
'views.xml',
'reports.xml',
],
'installable': True,
'application': True,
}

Step 6: Install and Use the Module

  1. Update the Odoo Apps List: After creating the custom module, go to Apps in Odoo, click Update Apps List, and install your custom module.
  2. Access the Report: Navigate to the Accounting menu and click on Revenue Report under the newly added Reports section.

You will be able to input the Start Date and End Date, and the system will calculate and display the Total Revenue for the selected period. You can also print the report as a PDF.

Conclusion

This guide provides the steps to create a custom Revenue Report in Odoo. You have learned how to:

  • Define a model to compute revenue based on sales invoices.
  • Create views and actions to allow users to input date ranges and view the results.
  • Optionally, generate a printable report using QWeb.

By following these steps, you can extend Odoo’s accounting functionality and tailor it to your business’s reporting needs.

For more information about the Create a Custom Revenue Report in Odoo, visit this link.

If you want to Free Trail Zoho, click on this link.

Yasir Baig

My name is Mirza Yasir Baig. As an experienced content writer and web developer, I specialize in creating impactful digital experiences. With expertise in WordPress programming and the MERN stack, I have built and managed various web platforms, including the different a dedicated resource for both Pakistani and international students seeking quality courses and training programs. My work is driven by a passion for education and technology, ensuring that content is not only engaging but also optimized for search engines (SEO) to reach a wider audience.

Leave a Reply