From 075b424427a426c62dd69e28172ca48fcc844316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 22 Mar 2021 08:11:23 +0100 Subject: [PATCH] [FIX] account_asset_management: Prevent create lines with init=True when account_lock_date_update addon is installed and lock date defined --- .../models/account_asset.py | 16 +++++--- .../tests/test_account_asset_management.py | 40 +++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index 6994b49ce..634066acb 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -576,6 +576,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 @@ -600,7 +604,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) @@ -992,6 +996,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): @@ -1047,6 +1055,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 @@ -1096,11 +1105,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"] ) @@ -1115,7 +1120,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) diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index 59fe5ee00..402cfbcdb 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -114,6 +114,46 @@ class TestAssetManagement(SavepointCase): 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.ref( + "account_asset_management." "account_asset_profile_car_5Y" + ), + "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.ref( + "account_asset_management." "account_asset_profile_car_5Y" + ), + "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.""" #