From e6b9dd5f053f1068a149fcfd24ca9824fea58304 Mon Sep 17 00:00:00 2001 From: "Ujjvala Collins (OpenERP)" Date: Mon, 4 Jul 2011 15:45:44 +0530 Subject: [PATCH] [FIX] account_asset: Fixed ending date method problem. bzr revid: uco@tinyerp.com-20110704101544-bceuzm55examobp3 --- addons/account_asset/account_asset.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/addons/account_asset/account_asset.py b/addons/account_asset/account_asset.py index 32e568165a1..08579d678d4 100644 --- a/addons/account_asset/account_asset.py +++ b/addons/account_asset/account_asset.py @@ -1,4 +1,4 @@ - # -*- encoding: utf-8 -*- +# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -130,30 +130,37 @@ class account_asset_asset(osv.osv): undone_dotation_number = asset.method_delay if asset.method_time == 'end': end_date = datetime.strptime(asset.method_end, '%Y-%m-%d') + total_days = asset.method_period * 30 undone_dotation_number = (end_date - depreciation_date).days / total_days + if end_date.strftime('%m-%d') < depreciation_date.strftime('%m-%d'): + undone_dotation_number -= 1 if asset.prorata or asset.method_time == 'end': undone_dotation_number += 1 return undone_dotation_number + + def _compute_board_depreciation_date(self, date, period): + return datetime(date.year, date.month, date.day) + relativedelta(months=+period) - def compute_depreciation_board(self, cr, uid,ids, context=None): + def compute_depreciation_board(self, cr, uid, ids, context=None): depreciation_lin_obj = self.pool.get('account.asset.depreciation.line') for asset in self.browse(cr, uid, ids, context=context): if asset.value_residual == 0.0: continue posted_depreciation_line_ids = depreciation_lin_obj.search(cr, uid, [('asset_id', '=', asset.id), ('move_check', '=', True)]) + last_depr_id = posted_depreciation_line_ids[-1:] and posted_depreciation_line_ids[-1:][0] old_depreciation_line_ids = depreciation_lin_obj.search(cr, uid, [('asset_id', '=', asset.id), ('move_id', '=', False)]) if old_depreciation_line_ids: depreciation_lin_obj.unlink(cr, uid, old_depreciation_line_ids, context=context) amount_to_depr = residual_amount = asset.value_residual - depreciation_date = datetime.strptime(self._get_last_depreciation_date(cr, uid, [asset.id], context)[asset.id], '%Y-%m-%d') - day = depreciation_date.day - month = depreciation_date.month - year = depreciation_date.year - total_days = (year % 4) and 365 or 366 + total_days = (depreciation_date.year % 4) and 365 or 366 undone_dotation_number = self._compute_board_undone_dotation_nb(cr, uid, asset, depreciation_date, total_days, context=context) + if last_depr_id: + depreciation_date = datetime.strptime(depreciation_lin_obj.browse(cr, uid, last_depr_id, context=context).depreciation_date, '%Y-%m-%d') + depreciation_date = self._compute_board_depreciation_date(depreciation_date, asset.method_period) + for x in range(len(posted_depreciation_line_ids), undone_dotation_number): i = x + 1 amount = self._compute_board_amount(cr, uid, asset, i, residual_amount, amount_to_depr, undone_dotation_number, posted_depreciation_line_ids, total_days, depreciation_date, context=context) @@ -169,10 +176,7 @@ class account_asset_asset(osv.osv): } depreciation_lin_obj.create(cr, uid, vals, context=context) # Considering Depr. Period as months - depreciation_date = (datetime(year, month, day) + relativedelta(months=+asset.method_period)) - day = depreciation_date.day - month = depreciation_date.month - year = depreciation_date.year + depreciation_date = self._compute_board_depreciation_date(depreciation_date, asset.method_period) return True def validate(self, cr, uid, ids, context={}):