Skip to content

Commit

Permalink
Merge PR #231 into 10.0
Browse files Browse the repository at this point in the history
Signed-off-by sbidoul
  • Loading branch information
OCA-git-bot committed Sep 29, 2019
2 parents ae9fa57 + 45d7df0 commit b047743
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
3 changes: 1 addition & 2 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions mis_builder/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
issue_format = "`#{issue} <https://github.com/oca/mis-builder/issues/{issue}>`_"
directory = "readme/newsfragments"
filename = "readme/HISTORY.rst"

[tool.black]
line-length=79
1 change: 1 addition & 0 deletions mis_builder/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions mis_builder/tests/test_analytic_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
# 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}, [])

0 comments on commit b047743

Please sign in to comment.