[FIX] account_asset_management: Prevent create lines with init=True when account_lock_date_update addon is installed and lock date defined
This commit is contained in:
parent
8bb45eb2f4
commit
0325891a82
@ -583,6 +583,10 @@ class AccountAsset(models.Model):
|
||||
posted_lines,
|
||||
):
|
||||
digits = self.env["decimal.precision"].precision_get("Account")
|
||||
company = self.company_id
|
||||
fiscalyear_lock_date = company.fiscalyear_lock_date or fields.Date.to_date(
|
||||
"1901-01-01"
|
||||
)
|
||||
|
||||
seq = len(posted_lines)
|
||||
depr_line = last_line
|
||||
@ -607,7 +611,7 @@ class AccountAsset(models.Model):
|
||||
"name": name,
|
||||
"line_date": line["date"],
|
||||
"line_days": line["days"],
|
||||
"init_entry": entry["init"],
|
||||
"init_entry": fiscalyear_lock_date >= line["date"],
|
||||
}
|
||||
depreciated_value += round(amount, digits)
|
||||
depr_line = self.env["account.asset.line"].create(vals)
|
||||
@ -999,6 +1003,10 @@ class AccountAsset(models.Model):
|
||||
i_max = len(table) - 1
|
||||
remaining_value = self.depreciation_base
|
||||
depreciated_value = 0.0
|
||||
company = self.company_id
|
||||
fiscalyear_lock_date = company.fiscalyear_lock_date or fields.Date.to_date(
|
||||
"1901-01-01"
|
||||
)
|
||||
|
||||
for i, entry in enumerate(table):
|
||||
|
||||
@ -1054,6 +1062,7 @@ class AccountAsset(models.Model):
|
||||
"amount": amount,
|
||||
"depreciated_value": depreciated_value,
|
||||
"remaining_value": remaining_value,
|
||||
"init": fiscalyear_lock_date >= line_date,
|
||||
}
|
||||
lines.append(line)
|
||||
depreciated_value += amount
|
||||
@ -1103,11 +1112,7 @@ class AccountAsset(models.Model):
|
||||
and not self.method_end
|
||||
):
|
||||
return table
|
||||
company = self.company_id
|
||||
asset_date_start = self.date_start
|
||||
fiscalyear_lock_date = company.fiscalyear_lock_date or fields.Date.to_date(
|
||||
"1901-01-01"
|
||||
)
|
||||
depreciation_start_date = self._get_depreciation_start_date(
|
||||
self._get_fy_info(asset_date_start)["record"]
|
||||
)
|
||||
@ -1122,7 +1127,6 @@ class AccountAsset(models.Model):
|
||||
"fy": fy_info["record"],
|
||||
"date_start": fy_info["date_from"],
|
||||
"date_stop": fy_info["date_to"],
|
||||
"init": fiscalyear_lock_date >= fy_info["date_from"],
|
||||
}
|
||||
)
|
||||
fy_date_start = fy_info["date_to"] + relativedelta(days=1)
|
||||
|
@ -118,6 +118,42 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
invoice = move_form.save()
|
||||
self.assertEqual(invoice.partner_id, self.partner)
|
||||
|
||||
def test_00_fiscalyear_lock_date_month(self):
|
||||
asset = self.asset_model.create(
|
||||
{
|
||||
"name": "test asset",
|
||||
"profile_id": self.car5y.id,
|
||||
"purchase_value": 1500,
|
||||
"date_start": "1901-02-01",
|
||||
"method_time": "year",
|
||||
"method_number": 3,
|
||||
"method_period": "month",
|
||||
}
|
||||
)
|
||||
asset.compute_depreciation_board()
|
||||
asset.refresh()
|
||||
self.assertTrue(asset.depreciation_line_ids[0].init_entry)
|
||||
for i in range(1, 36):
|
||||
self.assertFalse(asset.depreciation_line_ids[i].init_entry)
|
||||
|
||||
def test_00_fiscalyear_lock_date_year(self):
|
||||
asset = self.asset_model.create(
|
||||
{
|
||||
"name": "test asset",
|
||||
"profile_id": self.car5y.id,
|
||||
"purchase_value": 1500,
|
||||
"date_start": "1901-02-01",
|
||||
"method_time": "year",
|
||||
"method_number": 3,
|
||||
"method_period": "year",
|
||||
}
|
||||
)
|
||||
asset.compute_depreciation_board()
|
||||
asset.refresh()
|
||||
self.assertTrue(asset.depreciation_line_ids[0].init_entry)
|
||||
for i in range(1, 4):
|
||||
self.assertFalse(asset.depreciation_line_ids[i].init_entry)
|
||||
|
||||
def test_01_nonprorata_basic(self):
|
||||
"""Basic tests of depreciation board computations and postings."""
|
||||
# First create demo assets and do some sanity checks
|
||||
|
Loading…
Reference in New Issue
Block a user