-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sbidoul
- Loading branch information
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, []) |