[IMP] account_asset_management: add carry_forward_missed_depreciations
This commit is contained in:
parent
7987089dc6
commit
c62bab7c9e
@ -286,6 +286,13 @@ class AccountAsset(models.Model):
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
carry_forward_missed_depreciations = fields.Boolean(
|
||||
string="Accumulate missed depreciations",
|
||||
help="""If create an asset in a fiscal period that is now closed
|
||||
the accumulated amount of depreciations that cannot be posted will be
|
||||
carried forward to the first depreciation line of the current open
|
||||
period.""",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _default_company_id(self):
|
||||
@ -614,18 +621,26 @@ class AccountAsset(models.Model):
|
||||
depr_line = last_line
|
||||
last_date = table[-1]["lines"][-1]["date"]
|
||||
depreciated_value = depreciated_value_posted
|
||||
amount_to_allocate = 0.0
|
||||
for entry in table[table_i_start:]:
|
||||
for line in entry["lines"][line_i_start:]:
|
||||
seq += 1
|
||||
name = self._get_depreciation_entry_name(seq)
|
||||
amount = line["amount"]
|
||||
if self.carry_forward_missed_depreciations:
|
||||
if line["init"]:
|
||||
amount_to_allocate += amount
|
||||
amount = 0
|
||||
else:
|
||||
amount += amount_to_allocate
|
||||
amount_to_allocate = 0.0
|
||||
if line["date"] == last_date:
|
||||
# ensure that the last entry of the table always
|
||||
# depreciates the remaining value
|
||||
amount = self.depreciation_base - depreciated_value
|
||||
if self.method in ["linear-limit", "degr-limit"]:
|
||||
amount -= self.salvage_value
|
||||
if amount:
|
||||
if amount or self.carry_forward_missed_depreciations:
|
||||
vals = {
|
||||
"previous_id": depr_line.id,
|
||||
"amount": round(amount, digits),
|
||||
|
@ -761,6 +761,48 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
# deviations if that is necessary.
|
||||
self.assertAlmostEqual(asset.depreciation_line_ids[12].amount, 166.63, places=2)
|
||||
|
||||
def test_17_carry_forward_missed_depreciations(self):
|
||||
"""Asset with accumulate missed depreciations."""
|
||||
asset_profile = self.car5y
|
||||
# Create an asset with carry_forward_missed_depreciations
|
||||
# Theoretically, the depreciation would be 5000 / 12 months
|
||||
# which is 416.67 per month
|
||||
asset = self.asset_model.create(
|
||||
{
|
||||
"name": "test asset",
|
||||
"profile_id": asset_profile.id,
|
||||
"purchase_value": 5000,
|
||||
"salvage_value": 0,
|
||||
"date_start": time.strftime("2021-01-01"),
|
||||
"method_time": "year",
|
||||
"method_number": 1,
|
||||
"method_period": "month",
|
||||
"carry_forward_missed_depreciations": True,
|
||||
}
|
||||
)
|
||||
# Set the fiscalyear lock date for the company
|
||||
self.company_data["company"].fiscalyear_lock_date = time.strftime("2021-05-31")
|
||||
# Compute the depreciation board
|
||||
asset.compute_depreciation_board()
|
||||
asset.refresh()
|
||||
d_lines = asset.depreciation_line_ids
|
||||
init_lines = d_lines[1:6]
|
||||
# Jan to May entries are before the lock date -> marked as init
|
||||
self.assertTrue(init_lines.mapped("init_entry"))
|
||||
# Depreciation amount for these lines is set to 0
|
||||
for line in init_lines:
|
||||
self.assertEqual(line.amount, 0.0)
|
||||
# The amount to be carried is 416.67 * 5 = 2083.35
|
||||
# This amount is accumulated in the first depreciation for the current
|
||||
# available period -> 416.67 + 2083.35 = 2500.02
|
||||
self.assertAlmostEqual(d_lines[6].amount, 2500.02, places=2)
|
||||
# The rest of the lines should have the corresponding amount of 416.67
|
||||
# just as usual
|
||||
for _i in range(7, 12):
|
||||
self.assertAlmostEqual(d_lines[_i].amount, 416.67, places=2)
|
||||
# In the last month the small deviations are compensated
|
||||
self.assertAlmostEqual(d_lines[12].amount, 416.63, places=2)
|
||||
|
||||
def test_20_asset_removal_with_value_residual(self):
|
||||
"""Asset removal with value residual"""
|
||||
asset = self.asset_model.create(
|
||||
|
@ -154,6 +154,7 @@
|
||||
name="prorata"
|
||||
attrs="{'readonly': [('method_time', '!=', 'year')]}"
|
||||
/>
|
||||
<field name="carry_forward_missed_depreciations" />
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
Loading…
Reference in New Issue
Block a user