From b1b09521539e4eb71cbd85a1c7904ee0341d2dc6 Mon Sep 17 00:00:00 2001 From: mreficent Date: Mon, 19 Apr 2021 13:04:19 +0200 Subject: [PATCH] [FIX] account_asset_management: include 'number' method_time --- .../models/account_asset.py | 10 ++++-- .../models/account_asset_profile.py | 13 ++++---- .../tests/test_account_asset_management.py | 31 ++++++++++++++++++- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index 332f241b..408519e9 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -211,7 +211,9 @@ class AccountAsset(models.Model): help="Choose the method to use to compute the dates and " "number of depreciation lines.\n" " * Number of Years: Specify the number of years " - "for the depreciation.\n", + "for the depreciation.\n" + " * Number of Depreciations: Fix the number of " + "depreciation lines and the time between 2 depreciations.\n", ) days_calc = fields.Boolean( string="Calculate by days", @@ -395,10 +397,12 @@ class AccountAsset(models.Model): _("Degressive-Linear is only supported for Time Method = Year.") ) - @api.constrains("date_start", "method_end", "method_time") + @api.constrains("date_start", "method_end", "method_number", "method_time") def _check_dates(self): if self.filtered( - lambda a: a.method_time == "end" and a.method_end <= a.date_start + lambda a: a.method_time == "year" + and not a.method_number + and a.method_end <= a.date_start ): raise UserError(_("The Start Date must precede the Ending Date.")) diff --git a/account_asset_management/models/account_asset_profile.py b/account_asset_management/models/account_asset_profile.py index 96b588ee..1d43d2b0 100644 --- a/account_asset_management/models/account_asset_profile.py +++ b/account_asset_management/models/account_asset_profile.py @@ -110,7 +110,9 @@ class AccountAssetProfile(models.Model): help="Choose the method to use to compute the dates and " "number of depreciation lines.\n" " * Number of Years: Specify the number of years " - "for the depreciation.\n", + "for the depreciation.\n" + " * Number of Depreciations: Fix the number of " + "depreciation lines and the time between 2 depreciations.\n", ) days_calc = fields.Boolean( string="Calculate by days", @@ -173,11 +175,10 @@ class AccountAssetProfile(models.Model): @api.model def _selection_method_time(self): - """ - Install the 'account_asset_management_method_number_end' to enable the - 'Number' and 'End' Time Methods. - """ - return [("year", _("Number of Years or end date"))] + return [ + ("year", _("Number of Years or end date")), + ("number", _("Number of Depreciations")), + ] @api.constrains("method", "method_time") def _check_method(self): diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index b44ec269..ecb975b4 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -17,7 +17,7 @@ class TestAssetManagement(AccountTestInvoicingCommon): @classmethod def setUpClass(cls): super().setUpClass() - # ENVIRONEMENTS + # ENVIRONMENTS cls.asset_model = cls.env["account.asset"] cls.asset_profile_model = cls.env["account.asset.profile"] cls.dl_model = cls.env["account.asset.line"] @@ -731,3 +731,32 @@ class TestAssetManagement(AccountTestInvoicingCommon): [(group_tfa.id, "Tangible Fixed A...")], ) self.assertFalse(self.env["account.asset.group"].name_search("stessA dexiF")) + + def test_16_use_number_of_depreciations(self): + # When you run a depreciation with method = 'number' + profile = self.car5y + profile.method_time = "number" + asset = self.asset_model.create( + { + "name": "test asset", + "profile_id": profile.id, + "purchase_value": 10000, + "salvage_value": 0, + "date_start": time.strftime("2019-01-01"), + "method_time": "year", + "method_number": 5, + "method_period": "month", + "prorata": False, + "days_calc": False, + "use_leap_years": False, + } + ) + asset.compute_depreciation_board() + asset.refresh() + for _i in range(1, 11): + self.assertAlmostEqual( + asset.depreciation_line_ids[1].amount, 166.67, places=2 + ) + # 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)