From 18126ea829c0dfa05dc48d18bb77c8595a6cf8b7 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 | 9 ++++-- .../tests/test_account_asset_management.py | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index 0efd5fde8..462be84a9 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -204,7 +204,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", @@ -388,10 +390,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 53707e78d..ee4ba67f2 100644 --- a/account_asset_management/models/account_asset_profile.py +++ b/account_asset_management/models/account_asset_profile.py @@ -119,7 +119,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", @@ -186,7 +188,10 @@ class AccountAssetProfile(models.Model): 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 8d3b29aac..778cb32a0 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -721,3 +721,32 @@ class TestAssetManagement(SavepointCase): [(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.env.ref("account_asset_management.account_asset_profile_car_5Y") + 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)