diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 084ca9102..4c970f2e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,8 @@ exclude: | (?x) # NOT INSTALLABLE ADDONS + ^mis_builder_budget/| + ^mis_builder_demo/| # END NOT INSTALLABLE ADDONS # Files and folders generated by bots, to avoid loops ^setup/|/static/description/index\.html$| diff --git a/docs/conf.py b/docs/conf.py index ba4210bd4..bbca483d5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,12 +15,12 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) -from datetime import datetime +from datetime import datetime, timezone # -- Project information ----------------------------------------------------- project = "MIS Builder" -year = datetime.now().year +year = datetime.now(tz=timezone.utc).year # pylint: disable=redefined-builtin copyright = f"{year}, Odoo Community Association (OCA)" author = "Odoo Community Association (OCA)" diff --git a/mis_builder/README.rst b/mis_builder/README.rst index 27a628b70..fcf0ab92a 100644 --- a/mis_builder/README.rst +++ b/mis_builder/README.rst @@ -21,13 +21,13 @@ MIS Builder :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-lightgray.png?logo=github - :target: https://github.com/OCA/mis-builder/tree/19.0/mis_builder + :target: https://github.com/OCA/mis-builder/tree/20.0/mis_builder :alt: OCA/mis-builder .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/mis-builder-19-0/mis-builder-19-0-mis_builder + :target: https://translation.odoo-community.org/projects/mis-builder-20-0/mis-builder-20-0-mis_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/mis-builder&target_branch=19.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/mis-builder&target_branch=20.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -59,14 +59,14 @@ Usage To configure this module, you need to: -- Go to Accounting > Configuration > MIS Reporting > MIS Report - Templates where you can create report templates by defining KPI's. - KPI's constitute the rows of your reports. Such report templates are - time independent. +- Go to Invoicing > Configuration > MIS Reporting > MIS Report Templates + where you can create report templates by defining KPI's. KPI's + constitute the rows of your reports. Such report templates are time + independent. |image1| -- Then in Accounting > Reports > MIS Reporting > MIS Reports you can +- Then in Invoicing > Reporting > MIS Reporting > MIS Reports you can create report instance by binding the templates to time periods, hence defining the columns of your reports. @@ -85,7 +85,7 @@ To configure this module, you need to: .. |image1| image:: https://raw.githubusercontent.com/OCA/mis-builder/10.0/mis_builder/static/description/ex_report_template.png .. |image2| image:: https://raw.githubusercontent.com/OCA/mis-builder/10.0/mis_builder/static/description/ex_report_settings.png -.. |image3| image:: https://raw.githubusercontent.com/OCA/mis-builder/10.0/mis_builder/static/description/ex_report_preview.png +.. |image3| image:: https://raw.githubusercontent.com/OCA/mis-builder/20.0/mis_builder/static/img/mis_report_preview.png Development =========== @@ -731,7 +731,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -798,6 +798,6 @@ Current `maintainer `__: |maintainer-sbidoul| -This module is part of the `OCA/mis-builder `_ project on GitHub. +This module is part of the `OCA/mis-builder `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mis_builder/__manifest__.py b/mis_builder/__manifest__.py index 43246b5d4..ae3110733 100644 --- a/mis_builder/__manifest__.py +++ b/mis_builder/__manifest__.py @@ -3,11 +3,9 @@ { "name": "MIS Builder", - "version": "19.0.1.2.1", + "version": "20.0.1.0.0", "category": "Reporting", - "summary": """ - Build 'Management Information System' Reports and Dashboards - """, + "summary": "Build 'Management Information System' Reports and Dashboards", "author": "ACSONE SA/NV, Odoo Community Association (OCA)", "website": "https://github.com/OCA/mis-builder", "depends": [ @@ -18,13 +16,12 @@ ], "data": [ "security/res_groups.xml", + "security/ir.access.csv", "wizard/mis_builder_dashboard.xml", "views/mis_report.xml", "views/mis_report_instance.xml", "views/mis_report_style.xml", "datas/ir_cron.xml", - "security/ir.model.access.csv", - "security/mis_builder_security.xml", "report/mis_report_instance_qweb.xml", "report/mis_report_instance_xlsx.xml", ], @@ -41,7 +38,7 @@ ], }, "qweb": ["static/src/xml/mis_report_widget.xml"], - "installable": False, + "installable": True, "application": True, "license": "AGPL-3", "development_status": "Production/Stable", diff --git a/mis_builder/datas/ir_cron.xml b/mis_builder/datas/ir_cron.xml index 4a10c4729..fa55570da 100644 --- a/mis_builder/datas/ir_cron.xml +++ b/mis_builder/datas/ir_cron.xml @@ -2,7 +2,7 @@ Vacuum temporary reports - 4 + hours model._vacuum_report() diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index 94bc33859..02725f86f 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -217,7 +217,7 @@ def _parse_match_object(self, mo): inner_account_sel = account_sel[1:-1].strip() if not inner_account_sel: # empty selector: select all accounts - acc_domain = tuple() + acc_domain = () elif _is_domain(inner_account_sel): # account selector is a domain acc_domain = tuple(safe_eval(account_sel, domain_eval_context)) @@ -229,7 +229,7 @@ def _parse_match_object(self, mo): assert ml_domain[0] == "[" and ml_domain[-1] == "]" ml_domain = tuple(safe_eval(ml_domain, domain_eval_context)) else: - ml_domain = tuple() + ml_domain = () return field, mode, fld_name, acc_domain, ml_domain def parse_expr(self, expr): @@ -336,9 +336,9 @@ def get_aml_domain_for_expr(self, expr, date_from, date_to, account_id=None): else: continue if field == "crd": - aml_domain.append(("credit", "<>", 0.0)) + aml_domain.append(("credit", "!=", 0.0)) elif field == "deb": - aml_domain.append(("debit", "<>", 0.0)) + aml_domain.append(("debit", "!=", 0.0)) elif fld_name: aml_domain.append((fld_name, "!=", False)) aml_domains.append(aml_domain) @@ -472,7 +472,7 @@ def do_queries( ) ) from e for account_id, company_id, debit, credit, *custom_fields_sums in accs: - rate, dp = company_rates[company_id.id] + rate, _dp = company_rates[company_id.id] debit = debit or 0.0 credit = credit or 0.0 if mode in (self.MODE_INITIAL, self.MODE_UNALLOCATED) and float_is_zero( diff --git a/mis_builder/models/data_error.py b/mis_builder/models/data_error.py index 400ad3989..560e90445 100644 --- a/mis_builder/models/data_error.py +++ b/mis_builder/models/data_error.py @@ -10,7 +10,7 @@ def __init__(self, name, msg): self.msg = msg def __repr__(self): - return f"{self.__class__.__name__}({repr(self.name)})" + return f"{self.__class__.__name__}({self.name!r})" class NameDataError(DataError): diff --git a/mis_builder/models/kpimatrix.py b/mis_builder/models/kpimatrix.py index 9f417d0c9..b64f25ae3 100644 --- a/mis_builder/models/kpimatrix.py +++ b/mis_builder/models/kpimatrix.py @@ -115,7 +115,7 @@ def get_cell_for_row(self, row): return cell_tuple[self.index] -class KpiMatrixCell: # noqa: B903 (immutable data class) +class KpiMatrixCell: def __init__( self, row, @@ -257,10 +257,9 @@ def set_values_detail_account( row.kpi.style_expression, col.locals_dict ) except Exception: - _logger.error( + _logger.exception( "Error evaluating style expression <%s>", row.kpi.style_expression, - exc_info=True, ) if style_name: style = self._style_model.search([("name", "=", style_name)]) @@ -452,8 +451,7 @@ def iter_cols(self): yields KpiMatrixCol: one for each column or comparison. """ - for _col_key, col in self._cols.items(): - yield col + yield from self._cols.values() def iter_subcols(self): """Iterate sub columns in display order. diff --git a/mis_builder/models/mis_report.py b/mis_builder/models/mis_report.py index 048af8012..b20e21389 100644 --- a/mis_builder/models/mis_report.py +++ b/mis_builder/models/mis_report.py @@ -7,9 +7,9 @@ import re import time from collections import defaultdict +from zoneinfo import ZoneInfo import dateutil -import pytz from odoo import api, fields, models from odoo.exceptions import UserError, ValidationError @@ -56,10 +56,12 @@ def __init__(self, **kwargs): def _utc_midnight(d, tz_name, add_day=0): d = fields.Datetime.from_string(d) + datetime.timedelta(days=add_day) - utc_tz = pytz.timezone("UTC") - context_tz = pytz.timezone(tz_name) - local_timestamp = context_tz.localize(d, is_dst=False) - return fields.Datetime.to_string(local_timestamp.astimezone(utc_tz)) + local_timestamp = d.replace(tzinfo=ZoneInfo(tz_name)) + # on an ambiguous time, prefer the standard time (as pytz is_dst=False did) + other_fold = local_timestamp.replace(fold=1) + if other_fold.utcoffset() != local_timestamp.utcoffset() and not other_fold.dst(): + local_timestamp = other_fold + return fields.Datetime.to_string(local_timestamp.astimezone(datetime.timezone.utc)) def _python_var(var_str): @@ -145,7 +147,7 @@ class MisReportKpi(models.Model): _order = "sequence, id" - _rec_names_search = ["name", "description"] + _rec_names_search = ("name", "description") @api.depends("description", "name") def _compute_display_name(self): @@ -598,7 +600,7 @@ def _fetch_queries(self, date_from, date_to, get_additional_query_filter=None): ] ) field_names = [f.name for f in query_sudo.field_ids] - all_stored = all([model._fields[f].store for f in field_names]) + all_stored = all(model._fields[f].store for f in field_names) if not query.aggregate: data = model.search_read(domain, field_names) res[query.name] = [AutoStruct(**d) for d in data] diff --git a/mis_builder/models/mis_report_instance.py b/mis_builder/models/mis_report_instance.py index e8dc1f8d2..6768a51ac 100644 --- a/mis_builder/models/mis_report_instance.py +++ b/mis_builder/models/mis_report_instance.py @@ -358,12 +358,11 @@ def _onchange_date_range(self): @api.onchange("manual_date_from", "manual_date_to") def _onchange_dates(self): - if self.date_range_id: - if ( - self.manual_date_from != self.date_range_id.date_start - or self.manual_date_to != self.date_range_id.date_end - ): - self.date_range_id = False + if self.date_range_id and ( + self.manual_date_from != self.date_range_id.date_start + or self.manual_date_to != self.date_range_id.date_end + ): + self.date_range_id = False @api.onchange("source") def _onchange_source(self): @@ -427,14 +426,13 @@ def _check_mode_source(self): rec.name, ) ) - elif rec.source in (SRC_SUMCOL, SRC_CMPCOL): - if rec.mode != MODE_NONE: - raise DateFilterForbidden( - self.env._( - "No date filter is allowed for this source in column %s.", - rec.name, - ) + elif rec.source in (SRC_SUMCOL, SRC_CMPCOL) and rec.mode != MODE_NONE: + raise DateFilterForbidden( + self.env._( + "No date filter is allowed for this source in column %s.", + rec.name, ) + ) @api.constrains("source", "source_cmpcol_from_id", "source_cmpcol_to_id") def _check_source_cmpcol(self): @@ -667,7 +665,7 @@ def save_report(self): @api.model def _vacuum_report(self, hours=24): clear_date = fields.Datetime.to_string( - datetime.datetime.now() - datetime.timedelta(hours=hours) + fields.Datetime.now() - datetime.timedelta(hours=hours) ) reports = self.search( [("write_date", "<", clear_date), ("temporary", "=", True)] @@ -716,12 +714,11 @@ def _onchange_date_range(self): @api.onchange("date_from", "date_to") def _onchange_dates(self): - if self.date_range_id: - if ( - self.date_from != self.date_range_id.date_start - or self.date_to != self.date_range_id.date_end - ): - self.date_range_id = False + if self.date_range_id and ( + self.date_from != self.date_range_id.date_start + or self.date_to != self.date_range_id.date_end + ): + self.date_range_id = False def _add_analytic_filters_to_context(self, context): self.ensure_one() @@ -788,12 +785,12 @@ def print_pdf(self): return ( self.env.ref("mis_builder.qweb_pdf_export") .with_context(landscape=self.landscape_pdf) - .report_action(self, data=dict(dummy=True)) # required to propagate context + .report_action(self, data={"dummy": True}) # required to propagate context ) def export_xls(self): return self.env.ref("mis_builder.xls_export").report_action( - self, data=dict(dummy=True) + self, data={"dummy": True} ) # required to propagate context def display_settings(self): @@ -854,11 +851,7 @@ def _add_column_cmpcol(self, aep, kpi_matrix, period, label, description): ) def _add_column(self, aep, kpi_matrix, period, label, description): - if period.source == SRC_ACTUALS: - return self._add_column_move_lines( - aep, kpi_matrix, period, label, description - ) - elif period.source == SRC_ACTUALS_ALT: + if period.source == SRC_ACTUALS or period.source == SRC_ACTUALS_ALT: return self._add_column_move_lines( aep, kpi_matrix, period, label, description ) @@ -878,9 +871,7 @@ def _compute_matrix(self): kpi_matrix = self.report_id.prepare_kpi_matrix(self.query_company_ids) for period in self.period_ids: description = None - if period.mode == MODE_NONE: - pass - elif not self.display_columns_description: + if period.mode == MODE_NONE or not self.display_columns_description: pass elif period.date_from == period.date_to and period.date_from: description = self._format_date(period.date_from) @@ -952,7 +943,7 @@ def _get_drilldown_model_views(self, model_name): views_records = set(views_records.mapped("type")) views_order = self._get_drilldown_views_and_orders() views = {view_type for view_type in views_records if view_type in views_order} - return sorted(list(views), key=lambda x: views_order[x]) + return sorted(views, key=lambda x: views_order[x]) def drilldown(self, arg): self.ensure_one() diff --git a/mis_builder/models/mis_report_style.py b/mis_builder/models/mis_report_style.py index a0cb21c7c..1191e6f05 100644 --- a/mis_builder/models/mis_report_style.py +++ b/mis_builder/models/mis_report_style.py @@ -57,11 +57,11 @@ def check_positive_val(self): self.env._("Indent level must be greater than or equal to 0") ) - _font_style_selection = [("normal", "Normal"), ("italic", "Italic")] + _font_style_selection = [("normal", "Normal"), ("italic", "Italic")] # noqa: RUF012 - _font_weight_selection = [("nornal", "Normal"), ("bold", "Bold")] + _font_weight_selection = [("nornal", "Normal"), ("bold", "Bold")] # noqa: RUF012 - _font_size_selection = [ + _font_size_selection = [ # noqa: RUF012 ("medium", "medium"), ("xx-small", "xx-small"), ("x-small", "x-small"), @@ -71,7 +71,7 @@ def check_positive_val(self): ("xx-large", "xx-large"), ] - _font_size_to_xlsx_size = { + _font_size_to_xlsx_size = { # noqa: RUF012 "medium": 11, "xx-small": 5, "x-small": 7, diff --git a/mis_builder/models/mis_safe_eval.py b/mis_builder/models/mis_safe_eval.py index fad438de4..1425deb09 100644 --- a/mis_builder/models/mis_safe_eval.py +++ b/mis_builder/models/mis_safe_eval.py @@ -7,8 +7,8 @@ _BUILTINS, _SAFE_OPCODES, assert_valid_codeobj, - compile_codeobj, ) +from odoo.tools.safe_eval.evaluation import compile_codeobj from .data_error import DataError, NameDataError @@ -33,6 +33,6 @@ def mis_safe_eval(expr, locals_dict): val = NameDataError("#NAME", traceback.format_exc()) except ZeroDivisionError: val = DataError("#DIV/0", traceback.format_exc()) - except Exception: + except Exception: # noqa: BLE001 val = DataError("#ERR", traceback.format_exc()) return val diff --git a/mis_builder/models/prorata_read_group_mixin.py b/mis_builder/models/prorata_read_group_mixin.py index 9abb395f1..f65389d5e 100644 --- a/mis_builder/models/prorata_read_group_mixin.py +++ b/mis_builder/models/prorata_read_group_mixin.py @@ -77,13 +77,14 @@ def _read_group( for domain_item in domain: if isinstance(domain_item, list | tuple): field, op, value = domain_item - if field == "date" and op == ">=": + if field == "date" and op == ">=" or field == "date_to" and op == ">=": date_from = value - elif field == "date_to" and op == ">=": - date_from = value - elif field == "date" and op == "<=": - date_to = value - elif field == "date_from" and op == "<=": + elif ( + field == "date" + and op == "<=" + or field == "date_from" + and op == "<=" + ): date_to = value if ( date_from is not None diff --git a/mis_builder/models/simple_array.py b/mis_builder/models/simple_array.py index 891b5398d..ee0a93d87 100644 --- a/mis_builder/models/simple_array.py +++ b/mis_builder/models/simple_array.py @@ -99,7 +99,7 @@ def _o2(x, y): return op(x, y) except ZeroDivisionError: return DataError("#DIV/0", traceback.format_exc()) - except Exception: + except Exception: # noqa: BLE001 return DataError("#ERR", traceback.format_exc()) if isinstance(other, tuple): diff --git a/mis_builder/readme/USAGE.md b/mis_builder/readme/USAGE.md index d57f80200..30d172c2f 100644 --- a/mis_builder/readme/USAGE.md +++ b/mis_builder/readme/USAGE.md @@ -1,13 +1,13 @@ To configure this module, you need to: -- Go to Accounting \> Configuration \> MIS Reporting \> MIS Report +- Go to Invoicing \> Configuration \> MIS Reporting \> MIS Report Templates where you can create report templates by defining KPI's. KPI's constitute the rows of your reports. Such report templates are time independent. ![](https://raw.githubusercontent.com/OCA/mis-builder/10.0/mis_builder/static/description/ex_report_template.png) -- Then in Accounting \> Reports \> MIS Reporting \> MIS Reports you can +- Then in Invoicing \> Reporting \> MIS Reporting \> MIS Reports you can create report instance by binding the templates to time periods, hence defining the columns of your reports. @@ -16,6 +16,6 @@ To configure this module, you need to: - From the MIS Reports view, you can preview the report, add it to and Odoo dashboard, and export it to PDF or Excel. -![](https://raw.githubusercontent.com/OCA/mis-builder/10.0/mis_builder/static/description/ex_report_preview.png) +![](../static/img/mis_report_preview.png) - On the MIS Reports view, you can add annotations on each cells (except cells coming from the option "details by account"). Added notes will be pinted when exporting to PDF and Excel. Only users having either the group to read or the group to update annotations can see those annotations. \ No newline at end of file diff --git a/mis_builder/report/mis_report_instance_qweb.xml b/mis_builder/report/mis_report_instance_qweb.xml index abdfebec2..b66b91917 100644 --- a/mis_builder/report/mis_report_instance_qweb.xml +++ b/mis_builder/report/mis_report_instance_qweb.xml @@ -99,8 +99,8 @@ t-out="cell and cell.val_rendered or ''" /> ir.actions.report mis_builder.mis_report_instance_xlsx xlsx - mis_report_instance - + Export XLS diff --git a/mis_builder/security/ir.access.csv b/mis_builder/security/ir.access.csv new file mode 100644 index 000000000..56599f532 --- /dev/null +++ b/mis_builder/security/ir.access.csv @@ -0,0 +1,25 @@ +id,name,model_id,group_id/id,operation,domain +manage_mis_report_kpi,manage_mis_report_kpi,mis.report.kpi,account.group_account_manager,crud, +access_mis_report_kpi,access_mis_report_kpi,mis.report.kpi,base.group_user,r, +manage_mis_report_query,manage_mis_report_query,mis.report.query,account.group_account_manager,crud, +access_mis_report_query,access_mis_report_query,mis.report.query,base.group_user,r, +manage_mis_report,manage_mis_report,mis.report,account.group_account_manager,crud, +access_mis_report,access_mis_report,mis.report,base.group_user,r, +manage_mis_report_instance_period,manage_mis_report_instance_period,mis.report.instance.period,account.group_account_manager,crud, +access_mis_report_instance_period,access_mis_report_instance_period,mis.report.instance.period,base.group_user,r, +manage_mis_report_instance_period_sum,manage_mis_report_instance_period_sum,mis.report.instance.period.sum,account.group_account_manager,crud, +access_mis_report_instance_period_sum,access_mis_report_instance_period_sum,mis.report.instance.period.sum,base.group_user,r, +manage_mis_report_instance,manage_mis_report_instance,mis.report.instance,account.group_account_manager,crud, +access_mis_report_instance,access_mis_report_instance,mis.report.instance,base.group_user,r, +mis_builder_multi_company_rule,Mis Report Instance multi company,mis.report.instance,,crud,"['|', ('company_id', '=', False), ('company_id', 'in', company_ids), '|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]" +manage_mis_report_subkpi,access_mis_report_subkpi,mis.report.subkpi,account.group_account_manager,crud, +access_mis_report_subkpi,access_mis_report_subkpi,mis.report.subkpi,base.group_user,r, +manage_mis_report_kpi_expression,access_mis_report_kpi_expression,mis.report.kpi.expression,account.group_account_manager,crud, +access_mis_report_kpi_expression,access_mis_report_kpi_expression,mis.report.kpi.expression,base.group_user,r, +manage_mis_report_subreport,access_mis_report_subreport,mis.report.subreport,account.group_account_manager,crud, +access_mis_report_subreport,access_mis_report_subreport,mis.report.subreport,base.group_user,r, +manage_mis_report_style,access_mis_report_style,mis.report.style,account.group_account_manager,crud, +access_mis_report_style,access_mis_report_style,mis.report.style,base.group_user,r, +access_add_to_dashboard_wizard,access_add_to_dashboard_wizard,add.mis.report.instance.dashboard.wizard,base.group_user,cru, +access_read_mis_report_annotation, access_read_mis_report_annotation,mis.report.instance.annotation,mis_builder.group_read_annotation,r, +access_edit_mis_report_annotation, access_edit_mis_report_annotation,mis.report.instance.annotation,mis_builder.group_edit_annotation,crud, diff --git a/mis_builder/security/ir.model.access.csv b/mis_builder/security/ir.model.access.csv deleted file mode 100644 index 01027f8be..000000000 --- a/mis_builder/security/ir.model.access.csv +++ /dev/null @@ -1,24 +0,0 @@ -"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -manage_mis_report_kpi,manage_mis_report_kpi,model_mis_report_kpi,account.group_account_manager,1,1,1,1 -access_mis_report_kpi,access_mis_report_kpi,model_mis_report_kpi,base.group_user,1,0,0,0 -manage_mis_report_query,manage_mis_report_query,model_mis_report_query,account.group_account_manager,1,1,1,1 -access_mis_report_query,access_mis_report_query,model_mis_report_query,base.group_user,1,0,0,0 -manage_mis_report,manage_mis_report,model_mis_report,account.group_account_manager,1,1,1,1 -access_mis_report,access_mis_report,model_mis_report,base.group_user,1,0,0,0 -manage_mis_report_instance_period,manage_mis_report_instance_period,model_mis_report_instance_period,account.group_account_manager,1,1,1,1 -access_mis_report_instance_period,access_mis_report_instance_period,model_mis_report_instance_period,base.group_user,1,0,0,0 -manage_mis_report_instance_period_sum,manage_mis_report_instance_period_sum,model_mis_report_instance_period_sum,account.group_account_manager,1,1,1,1 -access_mis_report_instance_period_sum,access_mis_report_instance_period_sum,model_mis_report_instance_period_sum,base.group_user,1,0,0,0 -manage_mis_report_instance,manage_mis_report_instance,model_mis_report_instance,account.group_account_manager,1,1,1,1 -access_mis_report_instance,access_mis_report_instance,model_mis_report_instance,base.group_user,1,0,0,0 -manage_mis_report_subkpi,access_mis_report_subkpi,model_mis_report_subkpi,account.group_account_manager,1,1,1,1 -access_mis_report_subkpi,access_mis_report_subkpi,model_mis_report_subkpi,base.group_user,1,0,0,0 -manage_mis_report_kpi_expression,access_mis_report_kpi_expression,model_mis_report_kpi_expression,account.group_account_manager,1,1,1,1 -access_mis_report_kpi_expression,access_mis_report_kpi_expression,model_mis_report_kpi_expression,base.group_user,1,0,0,0 -manage_mis_report_subreport,access_mis_report_subreport,model_mis_report_subreport,account.group_account_manager,1,1,1,1 -access_mis_report_subreport,access_mis_report_subreport,model_mis_report_subreport,base.group_user,1,0,0,0 -manage_mis_report_style,access_mis_report_style,model_mis_report_style,account.group_account_manager,1,1,1,1 -access_mis_report_style,access_mis_report_style,model_mis_report_style,base.group_user,1,0,0,0 -access_add_to_dashboard_wizard,access_add_to_dashboard_wizard,model_add_mis_report_instance_dashboard_wizard,base.group_user,1,1,1,0 -access_read_mis_report_annotation, access_read_mis_report_annotation,model_mis_report_instance_annotation,mis_builder.group_read_annotation,1,0,0,0 -access_edit_mis_report_annotation, access_edit_mis_report_annotation,model_mis_report_instance_annotation,mis_builder.group_edit_annotation,1,1,1,1 diff --git a/mis_builder/security/mis_builder_security.xml b/mis_builder/security/mis_builder_security.xml deleted file mode 100644 index 158b3a0f0..000000000 --- a/mis_builder/security/mis_builder_security.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - Mis Report Instance multi company - - - ['|',('company_id','=',False),('company_id','in',company_ids), '|', - ('company_ids', '=', False), ('company_ids', 'in', company_ids)] - - - diff --git a/mis_builder/security/res_groups.xml b/mis_builder/security/res_groups.xml index 4e1b5fae4..23985d253 100644 --- a/mis_builder/security/res_groups.xml +++ b/mis_builder/security/res_groups.xml @@ -1,9 +1,9 @@ - + - + MIS Report: view annotations - + MIS Report: add annotations -README.rst +MIS Builder + + +
+ + + +Odoo Community Association + +
+

MIS Builder Analytic Source

+ +

Alpha License: AGPL-3 OCA/mis-builder Translate me on Weblate Try me on Runboat

+

Since Odoo 16 a journal item no longer has one analytic account: it has +an analytic_distribution that can split it between several accounts. +The analytic filter of a MIS report on journal items keeps the full +balance of every item whose distribution contains the analytic account, +so a P&L per project, contract or department is overstated whenever an +item is split. Costs that only exist as analytic lines, such as +timesheets, are not seen at all.

+

This module adds mis.analytic.move.line, a SQL view over +account.analytic.line with the fields MIS Builder expects from a +move lines source (account_id, company_id, date, debit, +credit, parent_state, analytic_distribution). Analytic lines +already carry the prorated amount, so a MIS report that uses this model +as its move lines source gives the exact figures per analytic account, +including timesheet costs.

+

Each analytic line holds one account per root analytic plan. The view +exposes them as one distribution key +("project_account,department_account" at 100%), the same format as +journal items, so the analytic filter works for the accounts of every +plan and a line is never counted twice.

+
+

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

+
+

Table of contents

+ +
+

Configuration

+

Analytic lines without a financial account (timesheets, manual analytic +entries) are reported on the company’s MIS Analytic Fallback Account +(Invoicing > Configuration > Settings, Analytics section). When it is +not set, the first Cost of Revenue account of the company (by code) is +used.

+
+
+

Usage

+
    +
  1. In the MIS report template, set Move lines source to Analytic line +as MIS move line.
  2. +
  3. Use the analytic filter of the report instance, or an analytic domain +per column.
  4. +
  5. Expressions can also filter on the origin of the line, for example +balp[5%][('line_origin', '=', 'timesheet')] or +-balp[6%][('category', '=', 'invoice')].
  6. +
+

The sign follows journal items: a positive analytic amount (revenue) is +a credit and a negative one (cost) is a debit, so the usual +-balp[...] expressions for income keep working.

+
+
+

Known issues / Roadmap

+
    +
  • Analytic lines are always in the company currency; amounts in another +currency are not converted.
  • +
  • Draft journal items have no analytic lines, so the posted and draft +target move option shows the same figures as posted only. Manual +analytic entries and timesheets count as posted.
  • +
  • The view is rebuilt when an analytic plan is created, moved or +deleted, because each root plan is a column of the analytic lines.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • KMEE
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

mileo

+

This module is part of the OCA/mis-builder project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/mis_builder_analytic_source/tests/__init__.py b/mis_builder_analytic_source/tests/__init__.py new file mode 100644 index 000000000..1c4a706c5 --- /dev/null +++ b/mis_builder_analytic_source/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mis_analytic_move_line diff --git a/mis_builder_analytic_source/tests/test_mis_analytic_move_line.py b/mis_builder_analytic_source/tests/test_mis_analytic_move_line.py new file mode 100644 index 000000000..2ddb904fe --- /dev/null +++ b/mis_builder_analytic_source/tests/test_mis_analytic_move_line.py @@ -0,0 +1,177 @@ +# Copyright 2026 KMEE +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command, fields +from odoo.tests import tagged +from odoo.tools.safe_eval import safe_eval + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.mis_builder.models.accounting_none import AccountingNone +from odoo.addons.mis_builder.models.aep import AccountingExpressionProcessor as AEP + + +@tagged("post_install", "-at_install") +class TestMisAnalyticMoveLine(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.company_data["company"] + projects, departments = cls.env["account.analytic.plan"].create( + [{"name": "Projects MIS"}, {"name": "Departments MIS"}] + ) + cls.project_a, cls.project_b, cls.department = cls.env[ + "account.analytic.account" + ].create( + [ + {"name": "Project A", "plan_id": projects.id}, + {"name": "Project B", "plan_id": projects.id}, + {"name": "Sales department", "plan_id": departments.id}, + ] + ) + cls.expense = cls.company_data["default_account_expense"] + cls.date = fields.Date.from_string("2026-03-15") + # one expense of 1000 split 60/40 between two projects, all of it on the + # sales department (second analytic plan) + cls.move = cls.env["account.move"].create( + { + "move_type": "entry", + "journal_id": cls.company_data["default_journal_misc"].id, + "date": cls.date, + "line_ids": [ + Command.create( + { + "name": "Shared cost", + "account_id": cls.expense.id, + "debit": 1000.0, + "analytic_distribution": { + f"{cls.project_a.id},{cls.department.id}": 60, + f"{cls.project_b.id},{cls.department.id}": 40, + }, + } + ), + Command.create( + { + "name": "Shared cost", + "account_id": cls.company_data[ + "default_account_payable" + ].id, + "credit": 1000.0, + } + ), + ], + } + ) + cls.move.action_post() + cls.View = cls.env["mis.analytic.move.line"] + + def _balp(self, aml_model, domain): + aep = AEP(self.company) + expr = f"balp[{self.expense.code}]" + aep.parse_expr(expr) + aep.done_parsing() + aep.do_queries( + date_from=self.date, + date_to=self.date, + additional_move_line_filter=domain, + aml_model=aml_model, + ) + return safe_eval(aep.replace_expr(expr), {"AccountingNone": AccountingNone}) + + def _filter(self, account): + return [("distribution_analytic_account_ids", "in", account.ids)] + + def test_lines_of_the_move(self): + """The view has the analytic lines of the move, with debit and credit.""" + lines = self.View.search([("move_line_id.move_id", "=", self.move.id)]) + self.assertTrue(lines) + self.assertEqual(set(lines.mapped("line_origin")), {"journal"}) + self.assertEqual(set(lines.mapped("parent_state")), {"posted"}) + self.assertEqual(lines.account_id, self.expense) + self.assertFalse(any(lines.mapped("credit"))) + + def test_analytic_filter_full_vs_prorated(self): + """The analytic filter on journal items keeps the full balance. + + The same filter on this source gives the prorated amount, for the accounts + of every analytic plan. + """ + project_filter = self._filter(self.project_a) + self.assertAlmostEqual(self._balp("account.move.line", project_filter), 1000.0) + self.assertAlmostEqual( + self._balp("mis.analytic.move.line", project_filter), 600.0 + ) + self.assertAlmostEqual( + self._balp("mis.analytic.move.line", self._filter(self.project_b)), 400.0 + ) + self.assertAlmostEqual( + self._balp("mis.analytic.move.line", self._filter(self.department)), 1000.0 + ) + + def test_new_plan_rebuilds_view(self): + """A new root plan adds a column to analytic lines: the view follows.""" + plan = self.env["account.analytic.plan"].create({"name": "Regions MIS"}) + region = self.env["account.analytic.account"].create( + {"name": "North", "plan_id": plan.id} + ) + manual = self.env["account.analytic.line"].create( + { + "name": "Regional cost", + plan._column_name(): region.id, + "amount": -30.0, + "date": self.date, + "company_id": self.company.id, + } + ) + line = self.View.search([("analytic_line_id", "=", manual.id)]) + self.assertAlmostEqual(line.debit, 30.0) + self.assertEqual(line.analytic_distribution, {str(region.id): 100}) + self.assertEqual(self.View.search(self._filter(region)), line) + + def test_manual_line_fallback_account(self): + """A line without financial account falls back to a cost account.""" + manual = self.env["account.analytic.line"].create( + { + "name": "Manual cost", + "account_id": self.project_a.id, + "amount": -50.0, + "date": self.date, + "company_id": self.company.id, + } + ) + line = self.View.search([("analytic_line_id", "=", manual.id)]) + self.assertEqual(line.line_origin, "manual") + self.assertAlmostEqual(line.debit, 50.0) + first_cost = self.env["account.account"].search( + [ + ("company_ids", "in", self.company.id), + ("account_type", "=", "expense_direct_cost"), + ], + order="code, id", + limit=1, + ) + self.assertEqual(line.account_id, first_cost) + fallback = self.company_data["default_account_expense"] + self.company.mis_analytic_fallback_account_id = fallback + self.env.flush_all() + self.View.invalidate_model() + self.assertEqual(line.account_id, fallback) + + def test_multi_company_rule(self): + """Users only see the lines of their companies.""" + other = self.env["res.company"].create({"name": "Other MIS company"}) + user = self.env["res.users"].create( + { + "name": "MIS reader", + "login": "mis_reader_analytic", + "company_id": other.id, + "company_ids": [Command.set(other.ids)], + "group_ids": [ + Command.set(self.env.ref("account.group_account_readonly").ids) + ], + } + ) + self.assertFalse( + self.View.with_user(user).search( + [("move_line_id.move_id", "=", self.move.id)] + ) + ) diff --git a/mis_builder_analytic_source/views/mis_analytic_move_line_views.xml b/mis_builder_analytic_source/views/mis_analytic_move_line_views.xml new file mode 100644 index 000000000..4f17f8f46 --- /dev/null +++ b/mis_builder_analytic_source/views/mis_analytic_move_line_views.xml @@ -0,0 +1,78 @@ + + + + + mis.analytic.move.line.list + mis.analytic.move.line + + + + + + + + + + + + + + + + + + + + + + + + mis.analytic.move.line.search + mis.analytic.move.line + + + + + + + + + + + + + + + + + + diff --git a/mis_builder_analytic_source/views/res_config_settings_views.xml b/mis_builder_analytic_source/views/res_config_settings_views.xml new file mode 100644 index 000000000..237a1b6aa --- /dev/null +++ b/mis_builder_analytic_source/views/res_config_settings_views.xml @@ -0,0 +1,27 @@ + + + + + res.config.settings.form (mis_builder_analytic_source) + res.config.settings + + + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt index e69de29bb..df0bf12d7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-report_xlsx @ git+https://github.com/OCA/reporting-engine@refs/pull/1203/head#subdirectory=report_xlsx