2
0

[FIX] account_asset_management: Provide hook _compute_depreciation_amount_per_fiscal_year

This way, other method_time mechanism like localization ones is able to overwrite it.

You also got an error of variable `number` not set due to previous code. Although no
alternate implementation for a new method_time, now you don't have any error,
fallbacking to standard proportional repartition.
This commit is contained in:
Pedro M. Baeza 2019-08-12 11:42:21 +02:00 committed by Rodrigo
parent 8b376f3b88
commit 68509d7386
3 changed files with 68 additions and 63 deletions

View File

@ -1,9 +1,10 @@
# Copyright 2009-2018 Noviat
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Assets Management',
'version': '12.0.1.0.0',
'version': '12.0.1.0.1',
'license': 'AGPL-3',
'depends': [
'account',

View File

@ -14,7 +14,7 @@ msgstr ""
"Plural-Forms: \n"
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:1076
#: code:addons/account_asset_management/models/account_asset.py:1080
#, python-format
msgid "\n"
"Error while processing asset '%s': %s"
@ -399,7 +399,7 @@ msgid "Degressive-Linear"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:261
#: code:addons/account_asset_management/models/account_asset.py:262
#: code:addons/account_asset_management/models/account_asset_profile.py:148
#, python-format
msgid "Degressive-Linear is only supported for Time Method = Year."
@ -506,13 +506,13 @@ msgid "Entries"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:252
#: code:addons/account_asset_management/models/account_asset.py:253
#, python-format
msgid "Error ! You can not create recursive assets."
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:1079
#: code:addons/account_asset_management/models/account_asset.py:1083
#, python-format
msgid "Error while processing asset '%s': \n"
"\n"
@ -541,7 +541,7 @@ msgid "General"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:443
#: code:addons/account_asset_management/models/account_asset.py:444
#, python-format
msgid "Generate Asset Removal entries"
msgstr ""
@ -577,7 +577,7 @@ msgid "ID"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:770
#: code:addons/account_asset_management/models/account_asset.py:771
#, python-format
msgid "Illegal value %s in asset.method."
msgstr ""
@ -618,7 +618,7 @@ msgid "Journal"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:463
#: code:addons/account_asset_management/models/account_asset.py:464
#: model:ir.model,name:account_asset_management.model_account_move
#: model_terms:ir.ui.view,arch_db:account_asset_management.account_asset_view_form
#, python-format
@ -708,7 +708,7 @@ msgid "Next Period Depreciation"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:924
#: code:addons/account_asset_management/models/account_asset.py:972
#, python-format
msgid "No Fiscal Year defined."
msgstr ""
@ -931,7 +931,7 @@ msgid "Status"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:743
#: code:addons/account_asset_management/models/account_asset.py:744
#, python-format
msgid "The '_compute_year_amount' method is only intended for Time Method 'Number of Years."
msgstr ""
@ -949,13 +949,13 @@ msgid "The Sale Value must be positive!"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:271
#: code:addons/account_asset_management/models/account_asset.py:272
#, python-format
msgid "The Start Date must precede the Ending Date."
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:535
#: code:addons/account_asset_management/models/account_asset.py:536
#, python-format
msgid "The duration of the asset conflicts with the posted depreciation table entry dates."
msgstr ""
@ -1081,7 +1081,7 @@ msgid "You are not allowed to remove an accounting entry linked to an asset.\n"
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:381
#: code:addons/account_asset_management/models/account_asset.py:382
#, python-format
msgid "You can only delete assets in draft state."
msgstr ""
@ -1111,13 +1111,13 @@ msgid "You cannot change an accounting item linked to an asset depreciation line
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:294
#: code:addons/account_asset_management/models/account_asset.py:295
#, python-format
msgid "You cannot change the profile of an asset with accounting entries."
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:931
#: code:addons/account_asset_management/models/account_asset.py:979
#, python-format
msgid "You cannot compute a depreciation table for an asset starting in an undefined future fiscal year.\n"
"Please correct the start date for asset '%s'."
@ -1130,7 +1130,7 @@ msgid "You cannot delete a depreciation line with an associated accounting entry
msgstr ""
#. module: account_asset_management
#: code:addons/account_asset_management/models/account_asset.py:385
#: code:addons/account_asset_management/models/account_asset.py:386
#, python-format
msgid "You cannot delete an asset that contains posted depreciation lines."
msgstr ""

View File

@ -1,4 +1,5 @@
# Copyright 2009-2018 Noviat
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import calendar
@ -807,6 +808,53 @@ class AccountAsset(models.Model):
return line_dates
def _compute_depreciation_amount_per_fiscal_year(self, table, line_dates):
digits = self.env['decimal.precision'].precision_get('Account')
fy_residual_amount = self.depreciation_base
i_max = len(table) - 1
asset_sign = self.depreciation_base >= 0 and 1 or -1
for i, entry in enumerate(table):
if self.method_time == 'year':
year_amount = self._compute_year_amount(fy_residual_amount)
if self.method_period == 'year':
period_amount = year_amount
elif self.method_period == 'quarter':
period_amount = year_amount / 4
elif self.method_period == 'month':
period_amount = year_amount / 12
if i == i_max:
if self.method in ['linear-limit', 'degr-limit']:
fy_amount = fy_residual_amount - self.salvage_value
else:
fy_amount = fy_residual_amount
else:
firstyear = i == 0 and True or False
fy_factor = self._get_fy_duration_factor(
entry, firstyear)
fy_amount = year_amount * fy_factor
if asset_sign * (fy_amount - fy_residual_amount) > 0:
fy_amount = fy_residual_amount
period_amount = round(period_amount, digits)
fy_amount = round(fy_amount, digits)
else:
fy_amount = False
if self.method_time == 'number':
number = self.method_number
else:
number = len(line_dates)
period_amount = round(self.depreciation_base / number, digits)
entry.update({
'period_amount': period_amount,
'fy_amount': fy_amount,
})
if self.method_time == 'year':
fy_residual_amount -= fy_amount
if round(fy_residual_amount, digits) == 0:
break
i_max = i
table = table[:i_max + 1]
return table
def _compute_depreciation_table_lines(self, table, depreciation_start_date,
depreciation_stop_date, line_dates):
@ -980,55 +1028,11 @@ class AccountAsset(models.Model):
# Step 1:
# Calculate depreciation amount per fiscal year.
# This is calculation is skipped for method_time != 'year'.
digits = self.env['decimal.precision'].precision_get('Account')
fy_residual_amount = self.depreciation_base
i_max = len(table) - 1
asset_sign = self.depreciation_base >= 0 and 1 or -1
line_dates = self._compute_line_dates(
table, depreciation_start_date, depreciation_stop_date)
for i, entry in enumerate(table):
if self.method_time == 'year':
year_amount = self._compute_year_amount(fy_residual_amount)
if self.method_period == 'year':
period_amount = year_amount
elif self.method_period == 'quarter':
period_amount = year_amount / 4
elif self.method_period == 'month':
period_amount = year_amount / 12
if i == i_max:
if self.method in ['linear-limit', 'degr-limit']:
fy_amount = fy_residual_amount - self.salvage_value
else:
fy_amount = fy_residual_amount
else:
firstyear = i == 0 and True or False
fy_factor = self._get_fy_duration_factor(
entry, firstyear)
fy_amount = year_amount * fy_factor
if asset_sign * (fy_amount - fy_residual_amount) > 0:
fy_amount = fy_residual_amount
period_amount = round(period_amount, digits)
fy_amount = round(fy_amount, digits)
else:
fy_amount = False
if self.method_time == 'number':
number = self.method_number
elif self.method_time == 'end':
number = len(line_dates)
period_amount = round(self.depreciation_base / number, digits)
entry.update({
'period_amount': period_amount,
'fy_amount': fy_amount,
})
if self.method_time == 'year':
fy_residual_amount -= fy_amount
if round(fy_residual_amount, digits) == 0:
break
i_max = i
table = table[:i_max + 1]
table = self._compute_depreciation_amount_per_fiscal_year(
table, line_dates,
)
# Step 2:
# Spread depreciation amount per fiscal year
# over the depreciation periods.