Skip to content

Commit 7d97678

Browse files
committed
Merge PR #2047 into 17.0
Signed-off-by pedrobaeza
2 parents ef1ba94 + 9757e6f commit 7d97678

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

account_asset_management/models/account_asset.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class AccountAsset(models.Model):
5757
"\nPurchase Value - Salvage Value.",
5858
)
5959
salvage_value = fields.Monetary(
60+
compute="_compute_salvage_value",
61+
store=True,
62+
readonly=False,
6063
help="The estimated value that an asset will realize upon "
6164
"its sale at the end of its useful life.\n"
6265
"This value is used to determine the depreciation amounts.",
@@ -261,6 +264,18 @@ def _compute_move_line_check(self):
261264
asset.depreciation_line_ids.filtered("move_id")
262265
)
263266

267+
def _get_salvage_value_profile(self):
268+
self.ensure_one()
269+
salvage_value = self.profile_id.salvage_value
270+
if self.profile_id.salvage_type == "percent":
271+
salvage_value = (salvage_value / 100) * self.purchase_value
272+
return salvage_value
273+
274+
@api.depends("profile_id")
275+
def _compute_salvage_value(self):
276+
for asset in self:
277+
asset.salvage_value = asset._get_salvage_value_profile()
278+
264279
@api.depends("purchase_value", "salvage_value", "method")
265280
def _compute_depreciation_base(self):
266281
for asset in self:
@@ -404,13 +419,7 @@ def _onchange_purchase_salvage_value(self):
404419
@api.model_create_multi
405420
def create(self, vals_list):
406421
asset_ids = super().create(vals_list)
407-
create_asset_from_move_line = self.env.context.get(
408-
"create_asset_from_move_line"
409-
)
410422
for asset_id in asset_ids:
411-
if create_asset_from_move_line:
412-
# Trigger compute of depreciation_base
413-
asset_id.salvage_value = 0.0
414423
asset_id._create_first_asset_line()
415424
return asset_ids
416425

account_asset_management/models/account_asset_profile.py

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ class AccountAssetProfile(models.Model):
7474
check_company=True,
7575
string="Asset Groups",
7676
)
77+
salvage_value = fields.Float(
78+
digits="Account",
79+
help="The estimated value that an asset will realize upon "
80+
"its sale at the end of its useful life.\n"
81+
"This value is used to determine the depreciation amounts.",
82+
)
83+
salvage_type = fields.Selection(
84+
selection=[("fixed", "Fixed"), ("percent", "Percentage of Price")]
85+
)
7786
method = fields.Selection(
7887
selection=lambda self: self._selection_method(),
7988
string="Computation Method",

account_asset_management/tests/test_account_asset_management.py

+27
Original file line numberDiff line numberDiff line change
@@ -952,3 +952,30 @@ def test_20_asset_removal_with_value_residual(self):
952952
last_line.create_move()
953953
self.assertEqual(asset.value_residual, 0)
954954
self.assertEqual(asset.state, "close")
955+
956+
def test_21_asset_profile_salvage_value(self):
957+
"""Compute salvage value from asset profile."""
958+
# Case percent
959+
self.car5y.salvage_type = "percent"
960+
self.car5y.salvage_value = 5
961+
asset = self.asset_model.create(
962+
{
963+
"name": "test asset",
964+
"profile_id": self.car5y.id,
965+
"purchase_value": 1000,
966+
"date_start": time.strftime("%Y-07-07"),
967+
}
968+
)
969+
self.assertEqual(asset.salvage_value, 50)
970+
# Case fixed amount
971+
self.car5y.salvage_type = "fixed"
972+
self.car5y.salvage_value = 5
973+
asset = self.asset_model.create(
974+
{
975+
"name": "test asset",
976+
"profile_id": self.car5y.id,
977+
"purchase_value": 1000,
978+
"date_start": time.strftime("%Y-07-07"),
979+
}
980+
)
981+
self.assertEqual(asset.salvage_value, 5)

account_asset_management/views/account_asset_profile.xml

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
</div>
2121
<group>
2222
<group>
23+
<label for="salvage_value" />
24+
<div>
25+
<field
26+
name="salvage_value"
27+
class="oe_inline"
28+
nolabel="1"
29+
/>
30+
<span
31+
class="o_form_label oe_inline"
32+
invisible="salvage_type != 'percent'"
33+
>%</span>
34+
</div>
35+
<field
36+
name="salvage_type"
37+
required="salvage_value != 0.0"
38+
/>
2339
<field name="company_id" invisible="1" />
2440
<field name="group_ids" widget="many2many_tags" />
2541
<field name="asset_product_item" />

0 commit comments

Comments
 (0)