From 289e4e7d6b67241620cfcc5284e7c5af3ff01bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 26 Jan 2021 15:56:46 +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 | 15 +++++--- .../readme/CONTRIBUTORS.rst | 5 +++ .../tests/test_account_asset_management.py | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py index a052141f8..c98bba812 100644 --- a/account_asset_management/models/account_asset.py +++ b/account_asset_management/models/account_asset.py @@ -471,6 +471,10 @@ class AccountAsset(models.Model): line_obj = self.env['account.asset.line'] 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') + ) for asset in self: if asset.value_residual == 0.0: @@ -593,7 +597,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 = line_obj.create(vals) @@ -871,6 +875,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): @@ -923,6 +931,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 @@ -972,10 +981,7 @@ class AccountAsset(models.Model): if self.method_time in ['year', 'number'] \ and not self.method_number 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']) depreciation_stop_date = self._get_depreciation_stop_date( @@ -987,7 +993,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) # Step 1: diff --git a/account_asset_management/readme/CONTRIBUTORS.rst b/account_asset_management/readme/CONTRIBUTORS.rst index 6afc965f8..69d08b786 100644 --- a/account_asset_management/readme/CONTRIBUTORS.rst +++ b/account_asset_management/readme/CONTRIBUTORS.rst @@ -9,3 +9,8 @@ - Maxence Groine - Kitti Upariphutthiphong - Saran Lim. + + +* `Tecnativa `_: + + * Víctor Martínez diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py index 3cf7647fd..9419df223 100644 --- a/account_asset_management/tests/test_account_asset_management.py +++ b/account_asset_management/tests/test_account_asset_management.py @@ -110,6 +110,40 @@ class TestAssetManagement(SavepointCase): 'invoice_line_ids': [(4, cls.invoice_line_2.id), (4, cls.invoice_line_3.id)]}) + 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.""" #