mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
@@ -18,20 +18,44 @@ def adjust_asset_values(env):
|
||||
FROm account_asset_profile aap
|
||||
WHERE aa.profile_id = aap.id""",
|
||||
)
|
||||
# Adjust method_time, method_number and method_period
|
||||
number = sql.Identifier(openupgrade.get_legacy_name('method_number'))
|
||||
period = sql.Identifier(openupgrade.get_legacy_name('method_period'))
|
||||
# Adjust method_time, method_end, method_number and method_period
|
||||
method_number = sql.Identifier(openupgrade.get_legacy_name('method_number'))
|
||||
method_period = sql.Identifier(openupgrade.get_legacy_name('method_period'))
|
||||
method_time = sql.Identifier(openupgrade.get_legacy_name('method_time'))
|
||||
for table in ['account_asset_profile', 'account_asset']:
|
||||
table = sql.Identifier(table)
|
||||
openupgrade.logged_query(
|
||||
env.cr, sql.SQL("""
|
||||
UPDATE {table}
|
||||
SET method_time = 'year',
|
||||
method_end = NULL,
|
||||
method_number = ({number} * {period}) / 12
|
||||
WHERE MOD({number} * {period}, 12) = 0
|
||||
WHERE MOD({number} * {period}, 12) = 0 AND {time} != 'end'
|
||||
""").format(
|
||||
number=number,
|
||||
period=period,
|
||||
number=method_number,
|
||||
period=method_period,
|
||||
time=method_time,
|
||||
table=table,
|
||||
),
|
||||
)
|
||||
openupgrade.logged_query(
|
||||
env.cr, sql.SQL("""
|
||||
UPDATE {table}
|
||||
SET method_time = 'year',
|
||||
method_number = 0
|
||||
WHERE {time} = 'end'
|
||||
""").format(
|
||||
time=method_time,
|
||||
table=table,
|
||||
),
|
||||
)
|
||||
openupgrade.logged_query(
|
||||
env.cr, sql.SQL("""
|
||||
UPDATE {table}
|
||||
SET method_end = NULL
|
||||
WHERE {time} = 'number'
|
||||
""").format(
|
||||
time=method_time,
|
||||
table=table,
|
||||
),
|
||||
)
|
||||
@@ -45,7 +69,7 @@ def adjust_asset_values(env):
|
||||
END)
|
||||
WHERE {period} IN (1, 3, 12)
|
||||
""").format(
|
||||
period=period,
|
||||
period=method_period,
|
||||
table=table,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -157,10 +157,8 @@ class AccountAsset(models.Model):
|
||||
"number of depreciation lines.\n"
|
||||
" * Number of Years: Specify the number of years "
|
||||
"for the depreciation.\n"
|
||||
# " * Number of Depreciations: Fix the number of "
|
||||
# "depreciation lines and the time between 2 depreciations.\n"
|
||||
# " * Ending Date: Choose the time between 2 depreciations "
|
||||
# "and the date the depreciations won't go beyond."
|
||||
" * Number of Depreciations: Fix the number of "
|
||||
"depreciation lines and the time between 2 depreciations.\n"
|
||||
)
|
||||
days_calc = fields.Boolean(
|
||||
string='Calculate by days',
|
||||
@@ -258,10 +256,10 @@ class AccountAsset(models.Model):
|
||||
"Year."))
|
||||
|
||||
@api.multi
|
||||
@api.constrains('date_start', 'method_end', 'method_time')
|
||||
@api.constrains('date_start', 'method_end', 'method_number', 'method_time')
|
||||
def _check_dates(self):
|
||||
for asset in self:
|
||||
if asset.method_time == 'end':
|
||||
if asset.method_time == 'year' and not asset.method_number:
|
||||
if asset.method_end <= asset.date_start:
|
||||
raise UserError(
|
||||
_("The Start Date must precede the Ending Date."))
|
||||
|
||||
@@ -99,7 +99,10 @@ 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',
|
||||
default=False,
|
||||
@@ -164,6 +167,7 @@ class AccountAssetProfile(models.Model):
|
||||
"""
|
||||
return [
|
||||
('year', _('Number of Years or end date')),
|
||||
('number', _('Number of Depreciations')),
|
||||
]
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -679,3 +679,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)
|
||||
|
||||
Reference in New Issue
Block a user