Skip to content

[v16] mis_builder: "AttributeError: 'NoneType' object has no attribute 'subkpis'" when using calculated column in comparison #709

@smaddlsoft

Description

@smaddlsoft

Module

mis_builder

Describe the bug

I had raised in the OCA MIS builder webinar the question if calculated columns can also be used as comparison columns. If you do this, the report breaks and you get the below error message. It was said in the webinar that this is possible. I was then asked to submit this behaviour as bug ticket here. Thanks for looking into it!

The following error appears:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo/lib/odoo/odoo/http.py", line 1823, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/service/model.py", line 152, in retrying
    result = func()
             ^^^^^^
  File "/opt/odoo/lib/odoo/odoo/http.py", line 1851, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/http.py", line 2055, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/addons/website/models/ir_http.py", line 237, in _dispatch
    response = super()._dispatch(endpoint)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/http.py", line 763, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/addons/web/controllers/dataset.py", line 43, in call_kw
    return self._call_kw(model, method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/addons/web/controllers/dataset.py", line 34, in _call_kw
    return call_kw(Model, method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/api.py", line 484, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/odoo/odoo/api.py", line 469, in _call_kw_multi
    result = method(recs, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/addons/oca-mirror-mis-builder/mis_builder/models/mis_report_instance.py", line 890, in compute
    kpi_matrix = self._compute_matrix()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/addons/oca-mirror-mis-builder/mis_builder/models/mis_report_instance.py", line 884, in _compute_matrix
    kpi_matrix.compute_comparisons()
  File "/opt/odoo/lib/addons/oca-mirror-mis-builder/mis_builder/models/kpimatrix.py", line 307, in compute_comparisons
    common_subkpis = self._common_subkpis([col, base_col])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/odoo/lib/addons/oca-mirror-mis-builder/mis_builder/models/kpimatrix.py", line 293, in _common_subkpis
    common_subkpis = common_subkpis & set(col.subkpis)
                                          ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'subkpis'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (https://stage-v16.humanilog.org/web/assets/73053-c8dc568/web.assets_backend.min.js:1003:163)
        at XMLHttpRequest.<anonymous> (https://stage-v16.humanilog.org/web/assets/73053-c8dc568/web.assets_backend.min.js:1011:13)

To Reproduce

Affected versions:
v16

Steps to reproduce the behavior:
This is a simple reproduction way (in reality, a more realistic example would be using budgets, forecasts, etc. but this requires more modules and data than necessary to recreate this bug)

  1. Crete Mis builder template based on journal item as source and one line only with expression "balp[]). You may want to select "Display details by account"
  2. Create mis builder report with 2 columns based on the actual journal items (e.g. for 2 years)
  3. Create one Sum column that sums column 1 and 2
  4. Create a comparison column that compares column 1 with column 2 (just for testing)
  5. Preview the report to make sure its working as intended until here, and the comparison feature works
  6. Change the comparison column to compare column 1 with column 3 (the sum column)
  7. Preview report. You should get the error message listed above

Expected behavior
I would expect that comparing column1 (actuals) with a calculated column(e.g. a sum of two other columns) gives me a % value just like it does with non-calculated columns, and not breaking the report with an error message

Additional context
/

Image Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions