Skip to content
Draft
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
146 changes: 146 additions & 0 deletions mis_builder_bi_sql_editor/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
=========================
MIS Builder BI SQL Editor
=========================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fmis--builder--contrib-lightgray.png?logo=github
:target: https://github.com/OCA/mis-builder-contrib/tree/18.0/mis_builder_bi_sql_editor
:alt: OCA/mis-builder-contrib
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mis-builder-contrib-18-0/mis-builder-contrib-18-0-mis_builder_bi_sql_editor
: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/mis-builder-contrib&target_branch=18.0
:alt: Try me on Runboat

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

This module make the BI SQL Editor query models compatible with MIS
Builder.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

Create a query with SQL BI Editor:

- Use the BI SQL Editor to create your query.
- Make sure your query includes the required fields: x_credit, x_debit,
x_account_id, x_date and x_company_id.
- Optionally, you can include the x_analytic_account_id field for
analytical account support.

Field Requirements:

- \`x_credit\`: Must have type float.
- \`x_debit\`: Must have type float.
- \`x_date\`: Must have the date type.
- \`x_account_id\`: Must have the type many2one and be associated with
the account.account model.
- \`x_company_id\`: Must have the type many2one and be associated with
the res.company model.
- x_analytic_account_id (optional): Must have the type many2one and be
associated with the account.analytic.account model.

Activate MIS Builder in the query model:

- Once your query meets the above requirements, click the “Activate MIS
Builder” button.
- This will signal that the query should be used in the "Refresh MIS
Builder BI SQL Lines" cron.
- Refreshing materialized view will also create new lines in the model
(if there are new lines).

Remove MIS Builder in the query model:

- If you no longer need MIS Builder compatibility, click the "Remove MIS
Builder" button.
- This will delete the rows and columns related to your BI SQL model.

Create MIS Builder report:

- When creating a MIS Builder Report, select "BI SQL MIS Builder Line"
as the source.
- Afterwards, select the BI SQL View you want to use (The view must have
MIS Builder activated).
- When creating kpis for this report, you can use MIS expressions to
filter the fields in your query.
- To do this, it is necessary to use the name of the BI SQL View.
- Example: bal[][('x_bi_sql_view_mis.x_name', '=', 'test')].
- This will filter out the lines in your query that have the x_name
field with "test" as the value.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mis-builder-contrib/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/mis-builder-contrib/issues/new?body=module:%20mis_builder_bi_sql_editor%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
-------

* Escodoo

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

- `Escodoo <https://www.escodoo.com.br>`__:

- Marcel Savegnago <marcel.savegnago@escodoo.com.br>
- Wesley Oliveira <wesley.oliveira@escodoo.com.br>

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-WesleyOliveira98| image:: https://github.com/WesleyOliveira98.png?size=40px
:target: https://github.com/WesleyOliveira98
:alt: WesleyOliveira98

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

|maintainer-WesleyOliveira98|

This module is part of the `OCA/mis-builder-contrib <https://github.com/OCA/mis-builder-contrib/tree/18.0/mis_builder_bi_sql_editor>`_ 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 mis_builder_bi_sql_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions mis_builder_bi_sql_editor/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2025 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "MIS Builder BI SQL Editor",
"summary": """
Integrate MIS Builder to BI SQL Editor""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/mis-builder-contrib",
"depends": ["mis_builder", "bi_sql_editor"],
"data": [
"views/bi_sql_view.xml",
"views/mis_builder_bi_sql_line.xml",
"views/mis_report_instance.xml",
"views/mis_report.xml",
"security/ir.model.access.csv",
"data/mis_builder_bi_sql_line_cron.xml",
],
"installable": True,
"application": True,
"development_status": "Alpha",
"maintainers": ["WesleyOliveira98"],
}
14 changes: 14 additions & 0 deletions mis_builder_bi_sql_editor/data/mis_builder_bi_sql_line_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2025 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.cron" id="mis_builder_bi_sql_line_cron">
<field name="name">Refresh MIS Builder BI SQL Lines</field>
<field name="model_id" ref="model_mis_builder_bi_sql_line" />
<field name="state">code</field>
<field name="code">model._create_mis_builder_bi_sql_lines()</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
</record>
</odoo>
4 changes: 4 additions & 0 deletions mis_builder_bi_sql_editor/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import bi_sql_view
from . import mis_builder_bi_sql_line
from . import mis_report_instance
from . import mis_report
111 changes: 111 additions & 0 deletions mis_builder_bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright 2025 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class BiSQLView(models.Model):
_inherit = "bi.sql.view"

mis_builder_compatible = fields.Boolean(
compute="_compute_mis_builder_compatible",
)
mis_builder_activated = fields.Boolean(default=False)

@api.depends(
"bi_sql_view_field_ids.name",
"bi_sql_view_field_ids.ttype",
"bi_sql_view_field_ids.many2one_model_id",
)
def _compute_mis_builder_compatible(self):
for record in self:
model_sql_fields = record.bi_sql_view_field_ids
credit_field = model_sql_fields.filtered(
lambda x: x.name == "x_credit" and x.ttype == "float"
)
debit_field = model_sql_fields.filtered(
lambda x: x.name == "x_debit" and x.ttype == "float"
)
account_field = model_sql_fields.filtered(
lambda x: x.name == "x_account_id" and x.ttype == "many2one"
)
date_field = model_sql_fields.filtered(
lambda x: x.name == "x_date" and x.ttype == "date"
)
company_field = model_sql_fields.filtered(
lambda x: x.name == "x_company_id" and x.ttype == "many2one"
)
analytic_account_field = model_sql_fields.filtered(
lambda x: x.name == "x_analytic_account_id" and x.ttype == "many2one"
)
record.mis_builder_compatible = not (
not credit_field
or not debit_field
or not account_field
or account_field.many2one_model_id.model != "account.account"
or not date_field
or not company_field
or company_field.many2one_model_id.model != "res.company"
or (
analytic_account_field
and analytic_account_field.many2one_model_id.model
!= "account.analytic.account"
)
)

def activate_mis_builder(self):
self.ensure_one()
if self.mis_builder_compatible:
model_id = (
self.env["ir.model"]
.search([("model", "=", "mis.builder.bi.sql.line")])
.id
)
self.env["ir.model.fields"].create(
{
"name": self.view_name,
"model_id": model_id,
"state": "manual",
"ttype": "many2one",
"relation": self.model_name,
}
)
self.mis_builder_activated = True

def remove_mis_builder(self):
self.ensure_one()
if self.mis_builder_compatible and self.mis_builder_activated:
self.env["mis.builder.bi.sql.line"].search(
[("bi_sql_model", "=", self.model_id.id)]
).unlink()

model_id = (
self.env["ir.model"]
.search([("model", "=", "mis.builder.bi.sql.line")])
.id
)
self.env["ir.model.fields"].search(
[
("name", "=", self.view_name),
("model_id", "=", model_id),
]
).unlink()

self.mis_builder_activated = False

def button_set_draft(self):
if self.mis_builder_activated:
self.remove_mis_builder()
return super().button_set_draft()

def button_refresh_materialized_view(self):
res = super().button_refresh_materialized_view()
if self.mis_builder_activated:
self.env["mis.builder.bi.sql.line"]._create_mis_builder_bi_sql_lines()
return res

def copy_data(self, default=None):
vals_list = super().copy_data(default=default)
for vals in vals_list:
vals["mis_builder_activated"] = False
return vals_list
51 changes: 51 additions & 0 deletions mis_builder_bi_sql_editor/models/mis_builder_bi_sql_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2025 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MisBuilderBiSqlLine(models.Model):
_name = "mis.builder.bi.sql.line"
_description = "MIS Builder BI SQL Line"

credit = fields.Float()
debit = fields.Float()
account_id = fields.Many2one(comodel_name="account.account")
date = fields.Date()
company_id = fields.Many2one(comodel_name="res.company")
analytic_account_id = fields.Many2one(comodel_name="account.analytic.account")
bi_sql_model = fields.Many2one(comodel_name="ir.model")
res_id = fields.Integer()

def _create_mis_builder_bi_sql_lines(self):
sql_view_ids = self.env["bi.sql.view"].search(
[
("mis_builder_compatible", "=", True),
("mis_builder_activated", "=", True),
]
)
vals_list = []
for sql_view in sql_view_ids:
existing_res_ids = set(
self.search([("bi_sql_model", "=", sql_view.model_id.id)]).mapped(
"res_id"
)
)
for line in self.env[sql_view.model_id.model].search([]):
if line.id in existing_res_ids:
continue
vals_list.append(
{
"credit": line.x_credit,
"debit": line.x_debit,
"account_id": line.x_account_id.id,
"date": line.x_date,
"company_id": line.x_company_id.id,
"analytic_account_id": line.x_analytic_account_id.id or False,
"bi_sql_model": sql_view.model_id.id,
"res_id": line.id,
sql_view.view_name: line.id,
}
)
if vals_list:
self.create(vals_list)
27 changes: 27 additions & 0 deletions mis_builder_bi_sql_editor/models/mis_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2025 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class MisReport(models.Model):
_inherit = "mis.report"

bi_sql_view = fields.Many2one(
string="BI SQL View",
comodel_name="bi.sql.view",
domain=[("mis_builder_activated", "=", True)],
)
bi_sql_view_required = fields.Boolean(
default=False, compute="_compute_bi_sql_view_required"
)

@api.depends("move_lines_source")
def _compute_bi_sql_view_required(self):
for record in self:
model_id = (
self.env["ir.model"]
.search([("model", "=", "mis.builder.bi.sql.line")])
.id
)
record.bi_sql_view_required = record.move_lines_source.id == model_id
Loading
Loading