Skip to content

Commit

Permalink
[FIX] mis_builder: let non-admins print reports
Browse files Browse the repository at this point in the history
Before this patch, normal users would get `AccessError` when trying to preview or print reports.

Fixes OCA#415.

@moduon MT-1527
  • Loading branch information
yajo committed Nov 9, 2022
1 parent 4f354aa commit 2b4e7b2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions mis_builder/models/mis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,11 @@ def _compute_all_kpi_ids(self):
@api.depends("move_lines_source")
def _compute_account_model(self):
for record in self:
record.account_model = record.move_lines_source.field_id.filtered(
lambda r: r.name == "account_id"
).relation
record.account_model = (
record.move_lines_source.sudo()
.field_id.filtered(lambda r: r.name == "account_id")
.relation
)

@api.onchange("subkpi_ids")
def _on_change_subkpi_ids(self):
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def _onchange_source(self):
def _get_aml_model_name(self):
self.ensure_one()
if self.source == SRC_ACTUALS:
return self.report_id.move_lines_source.model
return self.report_id.move_lines_source.sudo().model
elif self.source == SRC_ACTUALS_ALT:
return self.source_aml_model_name
return False
Expand Down
1 change: 1 addition & 0 deletions mis_builder/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
* `CorporateHub <https://corporatehub.eu/>`__

* Alexey Pelykh <[email protected]>
* Jairo Llopis (https://www.moduon.team/)
1 change: 1 addition & 0 deletions mis_builder/readme/newsfragments/access-error.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix access error when previewing or printing report.
4 changes: 4 additions & 0 deletions mis_builder/tests/test_mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,7 @@ def test_raise_when_unknown_kpi_value_type(self):
def test_raise_when_wrong_tuple_length_with_subkpis(self):
with self.assertRaises(SubKPITupleLengthError):
self.report_instance_3.compute()

def test_unprivileged(self):
test_user = common.new_test_user(self.env, "mis_you")
self.report_instance.with_user(test_user).compute()

0 comments on commit 2b4e7b2

Please sign in to comment.