[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:
parent
b21a1bfcfd
commit
5aed3a1b0c
|
@ -110,12 +110,14 @@ class account_asset_asset(osv.osv):
|
||||||
depreciation_lin_obj.unlink(cr, uid, old_depreciation_line_ids, context=context)
|
depreciation_lin_obj.unlink(cr, uid, old_depreciation_line_ids, context=context)
|
||||||
|
|
||||||
amount_to_depr = residual_amount = asset.value_residual
|
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')
|
depreciation_date = datetime.strptime(self._get_last_depreciation_date(cr, uid, [asset.id], context)[asset.id], '%Y-%m-%d')
|
||||||
day = depreciation_date.day
|
day = depreciation_date.day
|
||||||
month = depreciation_date.month
|
month = depreciation_date.month
|
||||||
year = depreciation_date.year
|
year = depreciation_date.year
|
||||||
total_days = (year % 4) and 365 or 366
|
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)
|
undone_dotation_number = asset.method_delay - len(asset.account_move_line_ids)
|
||||||
if asset.method_time == 'end':
|
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
|
undone_dotation_number = (end_date - depreciation_date).days / total_days
|
||||||
if asset.prorata or asset.method_time == 'end':
|
if asset.prorata or asset.method_time == 'end':
|
||||||
undone_dotation_number += 1
|
undone_dotation_number += 1
|
||||||
|
|
||||||
for i in range(1, undone_dotation_number+1):
|
for i in range(1, undone_dotation_number+1):
|
||||||
if i == undone_dotation_number + 1:
|
if i == undone_dotation_number + 1:
|
||||||
amount = residual_amount
|
amount = residual_amount
|
||||||
|
@ -139,7 +142,6 @@ class account_asset_asset(osv.osv):
|
||||||
else:
|
else:
|
||||||
amount = residual_amount * asset.method_progress_factor
|
amount = residual_amount * asset.method_progress_factor
|
||||||
residual_amount -= amount
|
residual_amount -= amount
|
||||||
|
|
||||||
vals = {
|
vals = {
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'asset_id': asset.id,
|
'asset_id': asset.id,
|
||||||
|
@ -152,10 +154,11 @@ class account_asset_asset(osv.osv):
|
||||||
depreciation_lin_obj.create(cr, uid, vals, context=context)
|
depreciation_lin_obj.create(cr, uid, vals, context=context)
|
||||||
|
|
||||||
# Considering Depr. Period as months
|
# Considering Depr. Period as months
|
||||||
depreciation_date = (datetime(year, month, day) + relativedelta(months=+asset.method_period))
|
|
||||||
day = depreciation_date.day
|
day = depreciation_date.day
|
||||||
month = depreciation_date.month
|
month = depreciation_date.month
|
||||||
year = depreciation_date.year
|
year = depreciation_date.year
|
||||||
|
depreciation_date = (datetime(year, month, day) + relativedelta(months=+asset.method_period))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def validate(self, cr, uid, ids, context={}):
|
def validate(self, cr, uid, ids, context={}):
|
||||||
|
@ -248,6 +251,12 @@ class account_asset_asset(osv.osv):
|
||||||
'prorata': category_obj.prorata,
|
'prorata': category_obj.prorata,
|
||||||
}
|
}
|
||||||
return res
|
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):
|
def copy(self, cr, uid, id, default=None, context=None):
|
||||||
if default is None:
|
if default is None:
|
||||||
|
|
|
@ -85,10 +85,10 @@
|
||||||
type="action"
|
type="action"
|
||||||
colspan="2"/>
|
colspan="2"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="method"/>
|
<field name="method" on_change="onchange_method_time(method)"/>
|
||||||
<field name="method_progress_factor" attrs="{'invisible':[('method','=','linear')]}"/>
|
<field name="method_progress_factor" attrs="{'invisible':[('method','=','linear')]}"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="method_time"/>
|
<field name="method_time" on_change="onchange_method_time(method_time)"/>
|
||||||
<field name="method_period"/>
|
<field name="method_period"/>
|
||||||
<field name="method_delay" attrs="{'invisible': [('method_time','=','end')]}"/>
|
<field name="method_delay" attrs="{'invisible': [('method_time','=','end')]}"/>
|
||||||
<field name="prorata" colspan="1" attrs="{'invisible': ['|',('method_time','=','end'),('method','!=','linear')]}"/>
|
<field name="prorata" colspan="1" attrs="{'invisible': ['|',('method_time','=','end'),('method','!=','linear')]}"/>
|
||||||
|
|
Loading…
Reference in New Issue