diff --git a/mis_builder/models/mis_report_instance.py b/mis_builder/models/mis_report_instance.py index 935f8efe6..1c8cc3af3 100644 --- a/mis_builder/models/mis_report_instance.py +++ b/mis_builder/models/mis_report_instance.py @@ -332,8 +332,7 @@ def _get_additional_move_line_filter(self): Returns an Odoo domain expression (a python list) compatible with account.move.line.""" self.ensure_one() - filters = self._get_filter_domain_from_context() - return filters + return self._get_filter_domain_from_context() @api.multi def _get_additional_query_filter(self, query): diff --git a/mis_builder/pyproject.toml b/mis_builder/pyproject.toml index 7ef453a20..2d560e05f 100644 --- a/mis_builder/pyproject.toml +++ b/mis_builder/pyproject.toml @@ -5,3 +5,6 @@ issue_format = "`#{issue} `_" directory = "readme/newsfragments" filename = "readme/HISTORY.rst" + +[tool.black] + line-length=79 diff --git a/mis_builder/tests/__init__.py b/mis_builder/tests/__init__.py index c39ffac02..13cac9c0e 100644 --- a/mis_builder/tests/__init__.py +++ b/mis_builder/tests/__init__.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import test_accounting_none +from . import test_analytic_filters from . import test_aep from . import test_multi_company_aep from . import test_aggregate diff --git a/mis_builder/tests/test_analytic_filters.py b/mis_builder/tests/test_analytic_filters.py new file mode 100644 index 000000000..a8cd5b161 --- /dev/null +++ b/mis_builder/tests/test_analytic_filters.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestAnalyticFilters(TransactionCase): + def test_context_with_filters(self): + aaa = self.env["account.analytic.account"].search([], limit=1) + mri = self.env["mis.report.instance"].new() + mri.analytic_account_id = False + assert mri._context_with_filters().get("mis_report_filters") == {} + mri.analytic_account_id = aaa + assert mri._context_with_filters().get("mis_report_filters") == { + "analytic_account_id": {"value": aaa.id} + } + # test _context_with_filters does nothing is a filter is already + # in the context + mri.with_context( + mis_report_filters={"f": 1} + )._context_with_filters().get("mis_report_filters") == {"f": 1} + + def _check_get_filter_domain_from_context( + self, mis_report_filters, expected_domain + ): + domain = ( + self.env["mis.report.instance.period"] + .with_context(mis_report_filters=mis_report_filters) + ._get_filter_domain_from_context() + ) + assert domain == expected_domain + + def test_get_filter_domain_from_context_1(self): + # no filter, no domain + self._check_get_filter_domain_from_context({}, []) + # the most basic analytic account filter (default operator is =) + self._check_get_filter_domain_from_context( + {"analytic_account_id": {"value": 1}}, + [("analytic_account_id", "=", 1)], + ) + # custom operator + self._check_get_filter_domain_from_context( + {"analytic_account_id": {"value": 1, "operator": "!="}}, + [("analytic_account_id", "!=", 1)], + ) + # any field name works + self._check_get_filter_domain_from_context( + {"some_field": {"value": "x"}}, [("some_field", "=", "x")] + ) + # filter name without value => no domain + self._check_get_filter_domain_from_context({"some_field": None}, [])