Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions report_builder/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
==============
Report Builder
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f45b4a6b59a17fad4d9603c51083eb77b9b988b216b103b3600394c638819ffb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/18.0/report_builder
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-report_builder
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This modules is a grid-based KPI reporting tool that works across any
Odoo model — not just accounting. Rows are KPIs defined by readable
formulas referencing pre-definied KPI computations.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

This module is inspired by mis-builder and shares its goal of grid-based
KPI reporting. However, it takes a different architectural approach:
rather than being tightly coupled to accounting, it is designed to be
pluggable on any Odoo model through small glue modules.

A migration path from mis-builder is planned but not yet available. Both
modules can coexist in the meantime.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_builder%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Dixmit

Contributors
------------

- `Dixmit <https://www.dixmit.com>`__

- Enric Tobella

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
:target: https://github.com/etobella
:alt: etobella

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-etobella|

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/report_builder>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions report_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
37 changes: 37 additions & 0 deletions report_builder/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2025 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Report Builder",
"summary": """Allow to generate dynamic reports easily in Odoo""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"depends": [
"board",
"date_range",
"report_xlsx",
],
"data": [
"security/ir.model.access.csv",
"views/menu.xml",
"views/report_instance.xml",
"views/report_instance_column.xml",
"views/report_template.xml",
"views/report_template_kpi.xml",
"views/report_style.xml",
],
"demo": [],
"assets": {
"web.assets_backend": [
"report_builder/static/src/components/**/*.esm.js",
"report_builder/static/src/components/**/*.xml",
"report_builder/static/src/components/**/*.scss",
],
"web.assets_unit_tests": [
"report_builder/static/tests/**/*.test.js",
],
},
"maintainers": ["etobella"],
}
7 changes: 7 additions & 0 deletions report_builder/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import report_template
from . import report_instance
from . import report_template_kpi
from . import report_template_kpi_item
from . import report_template_kpi_query_kind
from . import report_style
from . import report_instance_column
106 changes: 106 additions & 0 deletions report_builder/models/report_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright 2025 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import api, fields, models


class ReportInstance(models.Model):
_name = "report.instance"
_description = "Instance of Report"

name = fields.Char(required=True)
template_id = fields.Many2one("report.template", required=True)
source = fields.Selection(related="template_id.source", store=True)
show_search_bar = fields.Boolean(default=False)
search_view_id = fields.Many2one(related="template_id.search_view_id")
search_res_model = fields.Char(related="template_id.search_model_id.model")
show_settings = fields.Boolean(default=True)
show_pivot_date = fields.Boolean(default=True)
base_date = fields.Date()
currency_id = fields.Many2one(
"res.currency",
required=True,
default=lambda self: self.env.company.currency_id,
)

data = fields.Json(compute="_compute_data")
column_ids = fields.One2many(
"report.instance.column",
"instance_id",
)
active = fields.Boolean(default=True)

@api.depends("template_id", "column_ids")
def _compute_data(self):
for record in self:
record.data = record._get_data()

def _get_data(self):
rows = []
style = self.template_id.style_id._get_style()
for kpi in self.template_id.kpi_ids:
kpi_style, kpi_parameters = kpi.style_id._get_style_css(style)
rows.append(
{
"id": kpi.id,
"name": kpi.name,
"is_currency": kpi.is_currency,
"style": kpi_style,
"parameters": kpi_parameters,
}
)
columns = self.column_ids._get_data()
return {
"date": fields.Date.to_string(self.base_date or fields.Date.today()),
"rows": rows,
"columns": columns,
}

def process_information(self, pivot_date, domain=None):
self.ensure_one()
cols = self.column_ids._get_data(fields.Date.from_string(pivot_date))
kpi_data = {}
self.template_id.kpi_ids._process_information(
cols, kpi_data, domain=domain, **self._extra_process_keys()
)
return kpi_data

def _extra_process_keys(self):
"""
This method can be overridden in subclasses to provide extra keys
for the _process_information method.
"""
return {}

def view_report_instance(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"report_builder.report_instance_view_act_window"
)
action.update({"res_id": self.id})
return action

def get_display_settings_action(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"report_builder.report_instance_act_window"
)
action.update(
{
"res_id": self.id,
"view_mode": "form",
"views": [view for view in action["views"] if view[1] == "form"],
}
)
return action

def get_pdf_report_action(self, pivot_date, domain=None):
# TODO: implement the method to return the action for PDF report generation
self.ensure_one()
return {}

def get_xlsx_report_action(self, pivot_date, domain=None):
# TODO: implement the method to return the action for XLSX report generation
self.ensure_one()
return {}
104 changes: 104 additions & 0 deletions report_builder/models/report_instance_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright 2025 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

from odoo import api, fields, models


class ReportInstanceColumn(models.Model):
_name = "report.instance.column"
_description = "Report Instance Column" # TODO

name = fields.Char(required=True)
instance_id = fields.Many2one("report.instance", required=True)
mode = fields.Selection(
[
("date", "Fixed Date"),
("relative", "Relative to Base Date"),
],
default="relative",
)
date_from = fields.Date()
date_to = fields.Date()
date_type = fields.Selection(
[
("days", "Day"),
("weeks", "Week"),
("months", "Month"),
("years", "Year"),
],
default="months",
string="Period type",
)
duration_type = fields.Selection(
[
("days", "Day"),
("weeks", "Week"),
("months", "Month"),
("years", "Year"),
],
default="months",
)
is_ytd = fields.Boolean(
default=False,
string="Year to date",
help="Forces the start date to Jan 1st of the relevant year",
)
offset = fields.Integer(help="Offset from current period", default=-1)
duration = fields.Integer(help="Number of periods", default=1)
compute_date_from = fields.Date(
compute="_compute_compute_date",
)
compute_date_to = fields.Date(
compute="_compute_compute_date",
)
sequence = fields.Integer(
default=10,
)

@api.depends(
"instance_id.base_date",
"date_type",
"date_from",
"date_to",
"mode",
"is_ytd",
"offset",
"duration",
"duration_type",
)
def _compute_compute_date(self):
for record in self:
record.compute_date_from, record.compute_date_to = (
record._get_compute_date()
)

def _get_compute_date(self, pivot_date=None):
if self.mode == "date":
return self.date_from, self.date_to
elif self.mode == "relative":
compute_date_from = (
pivot_date or self.instance_id.base_date or fields.Date.today()
) + relativedelta(**{self.date_type: self.offset})
compute_date_to = compute_date_from + relativedelta(
**{self.duration_type: self.duration}
)
if self.is_ytd:
compute_date_from = compute_date_from.replace(month=1, day=1)
return compute_date_from, compute_date_to

def _get_data(self, pivot_date=None):
columns = []
for column in self:
date_from, date_to = column._get_compute_date(pivot_date)
columns.append(
{
"id": column.id,
"name": column.name,
"mode": column.mode,
"date_from": fields.Date.to_string(date_from),
"date_to": fields.Date.to_string(date_to),
}
)
return columns
Loading
Loading