From ab6476c866ee490f9abf1a69c0e7c06bdf30242c Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Wed, 3 Feb 2021 20:22:01 +0100 Subject: [PATCH] [IMP] Actually generate report in test Plus other tests to make it to the codecov target --- .../tests/test_account_asset_management.py | 34 +++++++++++++++++++ .../tests/test_asset_management_xls.py | 8 ++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index 4a0c3c683..a64772bb3 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -610,3 +610,37 @@ class TestAssetManagement(SavepointCase): # In the last month of the fiscal year we compensate for the small # deviations if that is necessary. self.assertAlmostEqual(asset.depreciation_line_ids[12].amount, 166.63, places=2) + + def test_15_account_asset_group(self): + """ Group's name_get behaves differently depending on code and context + """ + group_fa = self.env.ref("account_asset_management.account_asset_group_fa") + group_tfa = self.env.ref("account_asset_management.account_asset_group_tfa") + # Groups are displayed by code (if any) plus name + self.assertEqual( + self.env["account.asset.group"]._name_search("FA"), + [(group_fa.id, "FA Fixed Assets")], + ) + # Groups with code are shown by code in list views + self.assertEqual( + self.env["account.asset.group"] + .with_context(params={"view_type": "list"}) + ._name_search("FA"), + [(group_fa.id, "FA")], + ) + self.assertEqual( + self.env["account.asset.group"]._name_search("TFA"), + [(group_tfa.id, "TFA Tangible Fixed Assets")], + ) + group_tfa.code = False + group_fa.code = False + self.assertEqual(group_fa.name_get(), [(group_fa.id, "Fixed Assets")]) + # Groups without code are shown by truncated name in lists + self.assertEqual( + group_tfa.name_get(), [(group_tfa.id, "Tangible Fixed Assets")] + ) + self.assertEqual( + group_tfa.with_context(params={"view_type": "list"}).name_get(), + [(group_tfa.id, "Tangible Fixed A...")], + ) + self.assertFalse(self.env["account.asset.group"]._name_search("stessA dexiF")) diff --git a/account_asset_management/tests/test_asset_management_xls.py b/account_asset_management/tests/test_asset_management_xls.py index 2858c95d3..88e0f6d0f 100644 --- a/account_asset_management/tests/test_asset_management_xls.py +++ b/account_asset_management/tests/test_asset_management_xls.py @@ -30,6 +30,8 @@ class TestAssetManagementXls(SavepointCase): cls.xls_report_name = "{}.asset_report_xls".format(module) cls.wiz_model = cls.env["wiz.account.asset.report"] cls.company = cls.env.ref("base.main_company") + # Ensure we have something to report on + cls.env.ref("account_asset_management." "account_asset_asset_ict0").validate() asset_group_id = cls.wiz_model._default_asset_group_id() fy_dates = cls.company.compute_fiscalyear_dates(fields.date.today()) @@ -42,7 +44,7 @@ class TestAssetManagementXls(SavepointCase): cls.report_action = cls.xls_report.xls_export() def test_01_action_xls(self): - """ Check report XLS action """ + """ Check report XLS action and generate report """ self.assertDictContainsSubset( { "type": "ir.actions.report", @@ -51,3 +53,7 @@ class TestAssetManagementXls(SavepointCase): }, self.report_action, ) + model = self.env["report.%s" % self.report_action["report_name"]].with_context( + active_model=self.xls_report._name, **self.report_action["context"] + ) + model.create_xlsx_report(self.xls_report.ids, data=self.report_action["data"])