From fe8f976aa882077223952a74eba0eaaeb4539bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 21 Dec 2014 22:11:47 +0100 Subject: [PATCH] [FIX] account_asset_management: support init entries in current fy Fixes test_4. Handle situations where we have depreciation init entries in the same fiscal year as real depreciation lines. --- account_asset_management/account_asset.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/account_asset_management/account_asset.py b/account_asset_management/account_asset.py index 53a4a7f18..344bc983e 100644 --- a/account_asset_management/account_asset.py +++ b/account_asset_management/account_asset.py @@ -735,6 +735,7 @@ class account_asset_asset(orm.Model): if amount_diff: entry = table[table_i_start] if entry['fy_id']: + # check account moves cr.execute( """ SELECT COALESCE(SUM(aml.debit) -SUM(aml.credit), 0.0) AS depreciated_value @@ -751,6 +752,21 @@ class account_asset_asset(orm.Model): entry['fy_id'])) res = cr.fetchone() fy_amount_check = res[0] + # check init entries with no corresponding account move + cr.execute( + """ + SELECT COALESCE(SUM(amount), 0.0) AS depreciated_value + FROM account_asset_depreciation_line + WHERE id in %s + AND init_entry + AND move_id is null + AND line_date >= %s and line_date <= %s + """, + (tuple(posted_depreciation_line_ids), + entry['date_start'], + entry['date_stop'])) + res = cr.fetchone() + fy_amount_check += res[0] else: fy_amount_check = 0.0 lines = entry['lines']