[FIX] calculate days when remove asset
This commit is contained in:
parent
80bfe5b91b
commit
d95641888f
@ -524,8 +524,8 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
|||||||
wiz.remove()
|
wiz.remove()
|
||||||
asset.refresh()
|
asset.refresh()
|
||||||
self.assertEqual(len(asset.depreciation_line_ids), 3)
|
self.assertEqual(len(asset.depreciation_line_ids), 3)
|
||||||
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 81.46, places=2)
|
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 83.33, places=2)
|
||||||
self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 4918.54, places=2)
|
self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 4916.67, places=2)
|
||||||
|
|
||||||
def test_09_asset_from_invoice(self):
|
def test_09_asset_from_invoice(self):
|
||||||
all_asset = self.env["account.asset"].search([])
|
all_asset = self.env["account.asset"].search([])
|
||||||
|
@ -153,7 +153,11 @@ class AccountAssetRemove(models.TransientModel):
|
|||||||
residual_value = asset.value_residual
|
residual_value = asset.value_residual
|
||||||
|
|
||||||
dlines = asset_line_obj.search(
|
dlines = asset_line_obj.search(
|
||||||
[("asset_id", "=", asset.id), ("type", "=", "depreciate")],
|
[
|
||||||
|
("asset_id", "=", asset.id),
|
||||||
|
("type", "=", "depreciate"),
|
||||||
|
("move_check", "!=", False),
|
||||||
|
],
|
||||||
order="line_date desc",
|
order="line_date desc",
|
||||||
)
|
)
|
||||||
if dlines:
|
if dlines:
|
||||||
@ -254,9 +258,9 @@ class AccountAssetRemove(models.TransientModel):
|
|||||||
)
|
)
|
||||||
last_depr_date = create_dl.line_date
|
last_depr_date = create_dl.line_date
|
||||||
|
|
||||||
period_number_days = (first_date - last_depr_date).days
|
period_number_days = (first_date - last_depr_date).days + 1
|
||||||
new_line_date = date_remove + relativedelta(days=-1)
|
new_line_date = date_remove + relativedelta(days=-1)
|
||||||
to_depreciate_days = (new_line_date - last_depr_date).days
|
to_depreciate_days = (new_line_date - last_depr_date).days + 1
|
||||||
to_depreciate_amount = round(
|
to_depreciate_amount = round(
|
||||||
float(to_depreciate_days)
|
float(to_depreciate_days)
|
||||||
/ float(period_number_days)
|
/ float(period_number_days)
|
||||||
@ -265,7 +269,11 @@ class AccountAssetRemove(models.TransientModel):
|
|||||||
)
|
)
|
||||||
residual_value = asset.value_residual - to_depreciate_amount
|
residual_value = asset.value_residual - to_depreciate_amount
|
||||||
if to_depreciate_amount:
|
if to_depreciate_amount:
|
||||||
update_vals = {"amount": to_depreciate_amount, "line_date": new_line_date}
|
update_vals = {
|
||||||
|
"amount": to_depreciate_amount,
|
||||||
|
"line_date": new_line_date,
|
||||||
|
"line_days": to_depreciate_days,
|
||||||
|
}
|
||||||
first_to_depreciate_dl.write(update_vals)
|
first_to_depreciate_dl.write(update_vals)
|
||||||
dlines[0].create_move()
|
dlines[0].create_move()
|
||||||
dlines -= dlines[0]
|
dlines -= dlines[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user