Skip to content

Commit

Permalink
Asset Management:
Browse files Browse the repository at this point in the history
- first version of 'rate' depreciation method
- enabled method 'number' and 'end'
  • Loading branch information
mwithi committed Aug 1, 2016
1 parent 5f43749 commit 5a0a74b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
60 changes: 41 additions & 19 deletions account_asset_management/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def _get_method(self, cr, uid, context=None):
def _get_method_time(self, cr, uid, context=None):
return [
('year', _('Number of Years')),
# ('number', _('Number of Depreciations')),
# ('end', _('Ending Date'))
('number', _('Number of Depreciations')),
('rate', _('Rate of Depreciation')),
('end', _('Ending Date'))
]

def _get_company(self, cr, uid, context=None):
Expand Down Expand Up @@ -111,6 +112,9 @@ def _get_company(self, cr, uid, context=None):
'method_number': fields.integer(
'Number of Years',
help="The number of years needed to depreciate your asset"),
'method_rate': fields.float(
'Rate of Depreciation',
help="The rate of depreciation per (fiscal) year"),
'method_period': fields.selection([
('month', 'Month'),
('quarter', 'Quarter'),
Expand All @@ -125,10 +129,11 @@ def _get_company(self, cr, uid, context=None):
"number of depreciation lines.\n"
" * Number of Years: Specify the number of years "
"for the depreciation.\n"
# " * Number of Depreciations: Fix the number of "
# "depreciation lines and the time between 2 depreciations.\n"
# " * Ending Date: Choose the time between 2 depreciations "
# "and the date the depreciations won't go beyond."
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n"
" * Ending Date: Choose the time between 2 depreciations "
"and the date the depreciations won't go beyond."
" * Rate: Choose the rate of depreciation per year."
),
'prorata': fields.boolean(
'Prorata Temporis',
Expand Down Expand Up @@ -391,10 +396,14 @@ def _get_depreciation_stop_date(self, cr, uid, asset,
elif asset.method_time == 'end':
depreciation_stop_date = datetime.strptime(
asset.method_end, '%Y-%m-%d')
elif asset.method_time == 'rate':
months = int(fy_duration_months // asset.method_rate)
depreciation_stop_date = depreciation_start_date + \
relativedelta(months=months, days=-1)
return depreciation_stop_date

def _compute_year_amount(self, cr, uid, asset, amount_to_depr,
residual_amount, context=None):
residual_amount, fy_duration_days, context=None):
"""
Localization: override this method to change the degressive-linear
calculation logic according to local legislation.
Expand All @@ -412,7 +421,9 @@ def _compute_year_amount(self, cr, uid, asset, amount_to_depr,
duration = \
(datetime.strptime(asset.method_end, '%Y-%m-%d') -
datetime.strptime(asset.date_start, '%Y-%m-%d')).days + 1
divisor = duration / 365.0
divisor = duration / fy_duration_days
elif asset.method_time == 'rate':
divisor = 1 / asset.method_rate
year_amount_linear = amount_to_depr / divisor
if asset.method == 'linear':
return year_amount_linear
Expand All @@ -435,7 +446,7 @@ def _compute_depreciation_table(self, cr, uid, asset, context=None):
context = {}

table = []
if not asset.method_number:
if asset.method_time in ('year','number') and not asset.method_number:
return table

context['company_id'] = asset.company_id.id
Expand Down Expand Up @@ -465,6 +476,7 @@ def _compute_depreciation_table(self, cr, uid, asset, context=None):
fy_date_start = datetime.strptime(fy.date_start, '%Y-%m-%d')
fy_date_stop = datetime.strptime(fy.date_stop, '%Y-%m-%d')
fy_duration_months = self._get_fy_duration(cr, uid, fy_id, option='months')
fy_duration_days = self._get_fy_duration(cr, uid, fy_id, option='days')
except:
# The following logic is used when no fiscalyear
# is defined for the asset start date:
Expand All @@ -491,6 +503,7 @@ def _compute_depreciation_table(self, cr, uid, asset, context=None):
while asset_date_start < fy_date_start:
fy_date_start = fy_date_start - relativedelta(years=1)
fy_duration_months = self._get_fy_duration(cr, uid, first_fy['id'], option='months')
fy_duration_days = self._get_fy_duration(cr, uid, first_fy['id'], option='days')
fy_date_stop = fy_date_start + relativedelta(months=fy_duration_months)
fy_id = False
fy = dummy_fy(
Expand Down Expand Up @@ -538,7 +551,7 @@ def _compute_depreciation_table(self, cr, uid, asset, context=None):
for i, entry in enumerate(table):
year_amount = self._compute_year_amount(
cr, uid, asset, amount_to_depr,
fy_residual_amount, context=context)
fy_residual_amount, fy_duration_days, context=context)
if asset.method_period == 'year':
period_amount = year_amount
elif asset.method_period == 'quarter':
Expand Down Expand Up @@ -958,9 +971,9 @@ def onchange_purchase_salvage_value(
if not context:
context = {}
val = {}
if date_purchase:
date_start = date_purchase
val['date_start'] = date_start
# if date_purchase and not date_start:
# date_start = date_purchase
# val['date_start'] = date_start
purchase_value = purchase_value or 0.0
salvage_value = salvage_value or 0.0
if purchase_value or salvage_value:
Expand Down Expand Up @@ -1149,6 +1162,10 @@ def _get_company(self, cr, uid, context=None):
'Number of Years (fiscal)', readonly=True,
states={'draft': [('readonly', False)]},
help="The number of years (fiscal) needed to depreciate your asset"),
'method_rate': fields.float(
'Rate of Depreciation', readonly=True,
states={'draft': [('readonly', False)]},
help="The rate of depreciation per (fiscal) year"),
'method_period': fields.selection([
('month', 'Month'),
('quarter', 'Quarter'),
Expand All @@ -1171,10 +1188,11 @@ def _get_company(self, cr, uid, context=None):
"number of depreciation lines.\n"
" * Number of Years: Specify the number of years "
"for the depreciation.\n"
# " * Number of Depreciations: Fix the number of "
# "depreciation lines and the time between 2 depreciations.\n"
# " * Ending Date: Choose the time between 2 depreciations "
# "and the date the depreciations won't go beyond."
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n"
" * Ending Date: Choose the time between 2 depreciations "
"and the date the depreciations won't go beyond."
" * Rate: Choose the rate of depreciation per year."
),
'prorata': fields.boolean(
'Prorata Temporis', readonly=True,
Expand Down Expand Up @@ -1840,12 +1858,16 @@ class account_asset_history(orm.Model):
'account.asset.asset', 'Asset', required=True, ondelete='cascade'),
'method_time': fields.selection([
('year', 'Number of Years'),
# ('number','Number of Depreciations'),
# ('end','Ending Date'),
('number','Number of Depreciations'),
('end','Ending Date'),
('rate','Rate of Depreciation')
], 'Time Method', required=True),
'method_number': fields.integer(
'Number of Years',
help="The number of years needed to depreciate your asset"),
'method_rate': fields.float(
'Rate of Depreciation',
help="The rate of depreciation per (fiscal) year"),
'method_period': fields.selection([
('month', 'Month'),
('quarter', 'Quarter'),
Expand Down
15 changes: 8 additions & 7 deletions account_asset_management/account_asset_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
</group>
<group string="Depreciation Dates">
<field name="method_time" on_change="onchange_method_time(method_time)"/>
<field name="method_number" attrs="{'invisible':[('method_time','=','end')], 'required':[('method_time','in',['number','year'])]}"/>
<field name="method_number" attrs="{'invisible':[('method_time','in',['end','rate'])], 'required':[('method_time','in',['number','year'])]}"/>
<field name="method_rate" digits="(14, 4)" attrs="{'invisible':[('method_time','!=','rate')], 'required':[('method_time','=','rate')]}"/>
<field name="method_period"/>
</group>
<group string="Depreciation Method">
Expand Down Expand Up @@ -83,9 +84,9 @@
<button name="remove" string="Remove" type="object" groups="account.group_account_manager"
attrs="{'invisible':['|',('type','=','view'),'|',('method_time', '!=', 'year'),('state', 'not in', ['open', 'close'])]}"
help="Asset removal."/>
<button name="revaluate" string="Revaluate" type="object" groups="account.group_account_manager"
<button name="revaluate" string="Value Adjustement" type="object" groups="account.group_account_manager"
attrs="{'invisible':['|',('type','=','view'),'|',('method_time', '!=', 'year'),('state', '!=', 'open')]}"
help="Asset revaluation"/>
help="Increases or Decreases of value caused by revaluations, additions or others..."/>
<field name="state" widget="statusbar" statusbar_visible="draft,open,close,removed"/>
</header>
<sheet>
Expand Down Expand Up @@ -115,8 +116,7 @@
<group colspan="4" col="4">
<group>
<field name="date_purchase"
attrs="{'readonly':[('state','!=','draft')]}"
on_change="onchange_purchase_salvage_value(purchase_value, salvage_value, date_start, date_purchase)"/>
attrs="{'readonly':[('state','!=','draft')]}" />
<field name="purchase_value" widget="monetary" options="{'currency_field': 'currency_id'}"
attrs="{'readonly':['|',('move_line_check','=',True),('state','!=','draft')]}"
on_change="onchange_purchase_salvage_value(purchase_value, salvage_value, date_start, date_purchase)"/>
Expand Down Expand Up @@ -145,9 +145,10 @@
<field name="method_time" on_change="onchange_method_time(method_time)" class="oe_inline"/>
<button name="%(action_asset_modify)d" states="open" string="Change Duration" type="action" icon="terp-stock_effects-object-colorize" class="oe_inline" colspan="1"/>
</div>
<field name="method_number" attrs="{'invisible':[('method_time','=','end')], 'required':[('method_time','in',['number','year'])]}"/>
<field name="method_number" attrs="{'invisible':[('method_time','in',['end','rate'])], 'required':[('method_time','in',['number','year'])]}"/>
<field name="method_rate" digits="(14, 4)" attrs="{'invisible':[('method_time','!=','rate')], 'required':[('method_time','=','rate')]}"/>
<field name="method_period"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','in',['number','year'])]}"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','in',['number','year','rate'])]}"/>
</group>
<group>
<separator string="Depreciation Method" colspan="2"/>
Expand Down

0 comments on commit 5a0a74b

Please sign in to comment.