[ADD,FIX] account_asset: Added onchange method for computation method and time method.

Fixed problem of depreciation dates.

bzr revid: uco@tinyerp.com-20110609132559-1r9hml4d1j73dtfv
This commit is contained in:
Ujjvala Collins (OpenERP) 2011-06-09 18:55:59 +05:30
parent b21a1bfcfd
commit 5aed3a1b0c
2 changed files with 14 additions and 5 deletions

View File

@ -110,12 +110,14 @@ class account_asset_asset(osv.osv):
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
if asset.account_move_line_ids:
add_months = asset.method_period * len(asset.account_move_line_ids)
depreciation_date = (datetime(year, month, day) + relativedelta(months=+add_months))
undone_dotation_number = asset.method_delay - len(asset.account_move_line_ids)
if asset.method_time == 'end':
@ -123,6 +125,7 @@ class account_asset_asset(osv.osv):
undone_dotation_number = (end_date - depreciation_date).days / total_days
if asset.prorata or asset.method_time == 'end':
undone_dotation_number += 1
for i in range(1, undone_dotation_number+1):
if i == undone_dotation_number + 1:
amount = residual_amount
@ -139,7 +142,6 @@ class account_asset_asset(osv.osv):
else:
amount = residual_amount * asset.method_progress_factor
residual_amount -= amount
vals = {
'amount': amount,
'asset_id': asset.id,
@ -152,10 +154,11 @@ 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 = (datetime(year, month, day) + relativedelta(months=+asset.method_period))
return True
def validate(self, cr, uid, ids, context={}):
@ -248,6 +251,12 @@ class account_asset_asset(osv.osv):
'prorata': category_obj.prorata,
}
return res
def onchange_method_time(self, cr, uid, ids, method='linear', method_time='delay', context=None):
res = {'value': {}}
if method != 'linear' or method_time != 'delay':
res['value'] = {'prorata': False}
return res
def copy(self, cr, uid, id, default=None, context=None):
if default is None:

View File

@ -85,10 +85,10 @@
type="action"
colspan="2"/>
<newline/>
<field name="method"/>
<field name="method" on_change="onchange_method_time(method)"/>
<field name="method_progress_factor" attrs="{'invisible':[('method','=','linear')]}"/>
<newline/>
<field name="method_time"/>
<field name="method_time" on_change="onchange_method_time(method_time)"/>
<field name="method_period"/>
<field name="method_delay" attrs="{'invisible': [('method_time','=','end')]}"/>
<field name="prorata" colspan="1" attrs="{'invisible': ['|',('method_time','=','end'),('method','!=','linear')]}"/>