2
0

[FIX] account_asset_management: include 'number' method_time

This commit is contained in:
mreficent 2021-04-19 13:04:19 +02:00 committed by Rodrigo
parent 2cbf50e056
commit b1b0952153
3 changed files with 44 additions and 10 deletions

View File

@ -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."))

View File

@ -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):

View File

@ -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)