[MERGE]: Merged with parent branch.

bzr revid: uco@tinyerp.com-20110704054438-xeht78x8pwdl2c9f
This commit is contained in:
Ujjvala Collins (OpenERP)
2011-07-04 11:14:38 +05:30
7 changed files with 367 additions and 176 deletions
+4 -5
View File
@@ -25,10 +25,8 @@
"depends" : ["account"],
"author" : "Tiny",
"description": """Financial and accounting asset management.
Allows to define
* Asset category.
* Assets.
*Asset usage period and property.
This Module manages the assets owned by a company or an individual. It will keep track of depreciation's occurred on
those assets. And it allows to create Move's of the depreciation lines.
""",
"website" : "http://www.openerp.com",
"category" : "Generic Modules/Accounting",
@@ -39,9 +37,10 @@
"update_xml" : [
"security/ir.model.access.csv",
"account_asset_wizard.xml",
"wizard/account_asset_change_duration_view.xml",
"account_asset_view.xml",
"account_asset_invoice_view.xml",
"account_asset_report_view.xml",
"account_asset_report_view.xml",
"report/account_asset_report_view.xml",
#modif
],
+93 -61
View File
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@@ -40,7 +40,7 @@ class account_asset_category(osv.osv):
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'method': fields.selection([('linear','Linear'),('progressif','Progressive')], 'Computation method', required=True),
'method_delay': fields.integer('Number of Depreciation'),
'method_delay': fields.integer('Number of Depreciations'),
'method_period': fields.integer('Period Length', help="State here the time between 2 depreciations, in months"),
'method_progress_factor': fields.float('Progressif Factor'),
'method_time': fields.selection([('delay','Delay'),('end','Ending Period')], 'Time Method', required=True),
@@ -107,8 +107,33 @@ class account_asset_asset(osv.osv):
GROUP BY a.id, a.purchase_date """, (tuple(ids),))
return dict(cr.fetchall())
def calculate_date(self, date, period):
return datetime(date.year, date.month, date.day) + relativedelta(months=+period)
def _compute_board_amount(self, cr, uid, asset, i, residual_amount, amount_to_depr, undone_dotation_number, posted_depreciation_line_ids, total_days, depreciation_date, context=None):
#by default amount = 0
amount = 0
if i == undone_dotation_number:
amount = residual_amount
else:
if asset.method == 'linear':
amount = amount_to_depr / (undone_dotation_number - len(posted_depreciation_line_ids))
if asset.prorata:
amount = amount_to_depr / asset.method_delay
days = total_days - float(depreciation_date.strftime('%j'))
if i == 1:
amount = (amount_to_depr / asset.method_delay) / total_days * days
elif i == undone_dotation_number:
amount = (amount_to_depr / asset.method_delay) / total_days * (total_days - days)
elif asset.method == 'degressive':
amount = residual_amount * asset.method_progress_factor
return amount
def _compute_board_undone_dotation_nb(self, cr, uid, asset, depreciation_date, total_days, context=None):
undone_dotation_number = asset.method_delay
if asset.method_time == 'end':
end_date = datetime.strptime(asset.method_end, '%Y-%m-%d')
undone_dotation_number = (end_date - depreciation_date).days / total_days
if asset.prorata or asset.method_time == 'end':
undone_dotation_number += 1
return undone_dotation_number
def compute_depreciation_board(self, cr, uid,ids, context=None):
depreciation_lin_obj = self.pool.get('account.asset.depreciation.line')
@@ -123,36 +148,15 @@ class account_asset_asset(osv.osv):
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')
total_days = (depreciation_date.year % 4) and 365 or 366
undone_dotation_number = asset.method_delay
# Considering Depr. Period as months
time_period = asset.method_period
if asset.method_time == 'end':
end_date = datetime.strptime(asset.method_end, '%Y-%m-%d')
if time_period != 12:
total_days = time_period * 30
undone_dotation_number = (end_date - depreciation_date).days / total_days
if asset.prorata or asset.method_time == 'end':
undone_dotation_number += 1
if posted_depreciation_line_ids:
add_months = time_period * len(posted_depreciation_line_ids)
depreciation_date = self.calculate_date(depreciation_date, add_months)
day = depreciation_date.day
month = depreciation_date.month
year = depreciation_date.year
total_days = (year % 4) and 365 or 366
undone_dotation_number = self._compute_board_undone_dotation_nb(cr, uid, asset, depreciation_date, total_days, context=context)
for x in range(len(posted_depreciation_line_ids), undone_dotation_number):
i = x + 1
if i == undone_dotation_number:
amount = residual_amount
else:
if asset.method == 'linear':
amount = amount_to_depr / (undone_dotation_number - len(posted_depreciation_line_ids))
if asset.prorata:
amount = amount_to_depr / asset.method_delay
if i == 1:
days = total_days - float(depreciation_date.strftime('%j'))
amount = (amount_to_depr / asset.method_delay) / total_days * days
elif i == undone_dotation_number:
amount = (amount_to_depr / asset.method_delay) / total_days * (total_days - days)
else:
amount = residual_amount * asset.method_progress_factor
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)
residual_amount -= amount
vals = {
'amount': amount,
@@ -164,7 +168,11 @@ class account_asset_asset(osv.osv):
'depreciation_date': depreciation_date.strftime('%Y-%m-%d'),
}
depreciation_lin_obj.create(cr, uid, vals, context=context)
depreciation_date = self.calculate_date(depreciation_date, time_period)
# 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
return True
def validate(self, cr, uid, ids, context={}):
@@ -172,6 +180,9 @@ class account_asset_asset(osv.osv):
'state':'open'
}, context)
def set_to_close(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'close'}, context=context)
def _amount_residual(self, cr, uid, ids, name, args, context=None):
cr.execute("""SELECT
l.asset_id as id, round(SUM(abs(l.debit-l.credit))) AS amount
@@ -189,33 +200,32 @@ class account_asset_asset(osv.osv):
_columns = {
'period_id': fields.many2one('account.period', 'First Period', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'account_move_line_ids': fields.one2many('account.move.line', 'asset_id', 'Entries', readonly=True, states={'draft':[('readonly',False)]}),
'name': fields.char('Asset', size=64, required=True, select=1),
'code': fields.char('Reference ', size=16, select=1),
'purchase_value': fields.float('Gross value ', required=True, size=16, select=1),
'currency_id': fields.many2one('res.currency','Currency',required=True,size=5,select=1),
'company_id': fields.many2one('res.company', 'Company', required=True),
'name': fields.char('Asset', size=64, required=True, select=1, readonly=False, states={'close':[('readonly',True)]}),
'code': fields.char('Reference ', size=16, select=1, readonly=False, states={'close':[('readonly',True)]}),
'purchase_value': fields.float('Gross value ', required=True, readonly=False, states={'close':[('readonly',True)]}),
'currency_id': fields.many2one('res.currency','Currency',required=True, readonly=False, states={'close':[('readonly',True)]}),
'company_id': fields.many2one('res.company', 'Company', required=True, readonly=False, states={'close':[('readonly',True)]}),
'note': fields.text('Note'),
'category_id': fields.many2one('account.asset.category', 'Asset category',required=True, change_default=True),
'category_id': fields.many2one('account.asset.category', 'Asset category',required=True, change_default=True, readonly=False, states={'close':[('readonly',True)]}),
'localisation': fields.char('Localisation', size=32, select=2),
'parent_id': fields.many2one('account.asset.asset', 'Parent Asset'),
'child_ids': fields.one2many('account.asset.asset', 'parent_id', 'Children Assets'),
'purchase_date': fields.date('Purchase Date', required=True),
'purchase_date': fields.date('Purchase Date', required=True, readonly=False, states={'close':[('readonly',True)]}),
'state': fields.selection([('draft','Draft'),('open','Running'),('close','Close')], 'State', required=True),
'active': fields.boolean('Active', select=2),
'partner_id': fields.many2one('res.partner', 'Partner'),
'method': fields.selection([('linear','Linear'),('progressif','Progressive')], 'Computation Method', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="Linear: Calculated on basis of Gross Value/During (interval) \
\nProgressive: Calculated on basis of Gross Value * Progressif Factor"),
'method_delay': fields.integer('Number of Depreciation', readonly=True, states={'draft':[('readonly',False)]}, help="Calculates Depreciation within specified interval"),
'partner_id': fields.many2one('res.partner', 'Partner', readonly=False, states={'close':[('readonly',True)]}),
'method': fields.selection([('linear','Linear'),('degressive','Degressive')], 'Computation Method', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="Linear: Calculated on basis of Gross Value/During (interval) \
\nDegressive: Calculated on basis of Gross Value * Degressive Factor"),
'method_delay': fields.integer('Number of Depreciations', readonly=True, states={'draft':[('readonly',False)]}, help="Calculates Depreciation within specified interval"),
'method_period': fields.integer('Period Length', readonly=True, states={'draft':[('readonly',False)]}, help="State here the time during 2 depreciations, in months"),
'method_end': fields.date('Ending date', readonly=True, states={'draft':[('readonly',False)]}),
'method_end': fields.date('Ending Date', readonly=True, states={'draft':[('readonly',False)]}),
'method_progress_factor': fields.float('Progressif Factor', readonly=True, states={'draft':[('readonly',False)]}),
'value_residual': fields.function(_amount_residual, method=True, digits_compute=dp.get_precision('Account'), string='Residual Value'),
'method_time': fields.selection([('delay','Delay'),('end','Ending Period')], 'Time Method', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="Delay: Allow users to enter number of periods to generate depreciation lines \n Ending Period: Calculates depreciation lines on the basis of Ending Period Date and Number of Depreciation"),
'prorata':fields.boolean('Prorata Temporis', Readonly="True", help='Indicates that the accounting entries for this asset have to be done from the purchase date instead of the first January'),
'prorata':fields.boolean('Prorata Temporis', readonly=True, states={'draft':[('readonly',False)]}, help='Indicates that the accounting entries for this asset have to be done from the purchase date instead of the first January'),
'history_ids': fields.one2many('account.asset.history', 'asset_id', 'History', readonly=True),
'depreciation_line_ids': fields.one2many('account.asset.depreciation.line', 'asset_id', 'Depreciation Lines'),
'salvage_value': fields.float('Salvage Value', digits_compute=dp.get_precision('Account'), help="It is the amount you plan to have that you cannot depreciate."),
'depreciation_line_ids': fields.one2many('account.asset.depreciation.line', 'asset_id', 'Depreciation Lines', readonly=True, states={'draft':[('readonly',False)]}),
'salvage_value': fields.float('Salvage Value', digits_compute=dp.get_precision('Account'), help="It is the amount you plan to have that you cannot depreciate.", readonly=False, states={'close':[('readonly',True)]}),
}
_defaults = {
'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'account.asset.code'),
@@ -231,6 +241,9 @@ class account_asset_asset(osv.osv):
'currency_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'account.asset.asset',context=context),
}
def _check_recursion(self, cr, uid, ids, context=None, parent=None):
return super(account_asset_asset, self)._check_recursion(cr, uid, ids, context=context, parent=parent)
def _check_prorata(self, cr, uid, ids, context=None):
for asset in self.browse(cr, uid, ids, context=context):
@@ -239,6 +252,7 @@ class account_asset_asset(osv.osv):
return True
_constraints = [
(_check_recursion, 'Error ! You can not create recursive assets.', ['parent_id']),
(_check_prorata, '\nProrata temporis can be applied only for computation method linear and time method delay.', ['prorata']),
]
@@ -353,6 +367,12 @@ class account_asset_asset(osv.osv):
if period and (period.date_start<=date_start):
result += self._compute_move(cr, uid, property, period, context)
return result
def create(self, cr, uid, vals, context=None):
asset_id = super(account_asset_asset, self).create(cr, uid, vals, context=context)
self.compute_depreciation_board(cr, uid, [asset_id], context=context)
return asset_id
account_asset_asset()
class account_asset_depreciation_line(osv.osv):
@@ -377,7 +397,8 @@ class account_asset_depreciation_line(osv.osv):
'move_check': fields.function(_get_move_check, method=True, type='boolean', string='Posted', store=True)
}
def create_move(self, cr, uid,ids, context=None):
def create_move(self, cr, uid, ids, context=None):
can_close = False
if context is None:
context = {}
asset_obj = self.pool.get('account.asset.asset')
@@ -386,6 +407,8 @@ class account_asset_depreciation_line(osv.osv):
move_line_obj = self.pool.get('account.move.line')
currency_obj = self.pool.get('res.currency')
for line in self.browse(cr, uid, ids, context=context):
if currency_obj.is_zero(cr, uid, line.asset_id.currency_id, line.remaining_value):
can_close = True
depreciation_date = line.asset_id.prorata and line.asset_id.purchase_date or time.strftime('%Y-%m-%d')
period_ids = period_obj.find(cr, uid, depreciation_date, context=context)
company_currency = line.asset_id.company_id.currency_id.id
@@ -401,30 +424,34 @@ class account_asset_depreciation_line(osv.osv):
'journal_id': line.asset_id.category_id.journal_id.id,
}
move_id = move_obj.create(cr, uid, move_vals, context=context)
asset_name = line.asset_id.name
reference = line.name
journal_id = line.asset_id.category_id.journal_id.id
partner_id = line.asset_id.partner_id.id
move_line_obj.create(cr, uid, {
'name': line.name,
'ref': line.name,
'name': asset_name,
'ref': reference,
'move_id': move_id,
'account_id': line.asset_id.category_id.account_depreciation_id.id,
'debit': 0.0,
'credit': amount,
'period_id': period_ids and period_ids[0] or False,
'journal_id': line.asset_id.category_id.journal_id.id,
'partner_id': line.asset_id.partner_id.id,
'journal_id': journal_id,
'partner_id': partner_id,
'currency_id': company_currency <> current_currency and current_currency or False,
'amount_currency': company_currency <> current_currency and - sign * line.amount or 0.0,
'date': depreciation_date,
})
move_line_obj.create(cr, uid, {
'name': line.name,
'ref': line.name,
'name': asset_name,
'ref': reference,
'move_id': move_id,
'account_id': line.asset_id.category_id.account_expense_depreciation_id.id,
'credit': 0.0,
'debit': amount,
'period_id': period_ids and period_ids[0] or False,
'journal_id': line.asset_id.category_id.journal_id.id,
'partner_id': line.asset_id.partner_id.id,
'journal_id': journal_id,
'partner_id': partner_id,
'currency_id': company_currency <> current_currency and current_currency or False,
'amount_currency': company_currency <> current_currency and sign * line.amount or 0.0,
'analytic_account_id': line.asset_id.category_id.account_analytic_id.id,
@@ -432,6 +459,8 @@ class account_asset_depreciation_line(osv.osv):
'asset_id': line.asset_id.id
})
self.write(cr, uid, line.id, {'move_id': move_id}, context=context)
if can_close:
asset_obj.write(cr, uid, [line.asset_id.id], {'state': 'close'}, context=context)
return True
account_asset_depreciation_line()
@@ -522,15 +551,18 @@ class account_asset_history(osv.osv):
'user_id': fields.many2one('res.users', 'User', required=True),
'date': fields.date('Date', required=True),
'asset_id': fields.many2one('account.asset.asset', 'Asset', required=True),
'method_delay': fields.integer('Number of interval'),
'method_period': fields.integer('Period per interval'),
'method_time': fields.selection([('delay','Delay'),('end','Ending Period')], 'Time Method', required=True, help="Delay: Allow users to enter number of periods to generate depreciation lines \n Ending Period: Calculates depreciation lines on the basis of Ending Period Date and Number of Depreciations"),
'method_delay': fields.integer('Number of Depreciations'),
'method_period': fields.integer('Period Length', help="Time in month between two depreciations"),
'method_end': fields.date('Ending date'),
'note': fields.text('Note'),
}
_order = 'date desc'
_defaults = {
'date': lambda *args: time.strftime('%Y-%m-%d'),
'user_id': lambda self,cr, uid,ctx: uid
'user_id': lambda self, cr, uid, ctx: uid
}
account_asset_history()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+92 -21
View File
@@ -20,7 +20,7 @@
<field name="method_time"/>
<field name="method_delay" attrs="{'invisible':[('method_time','=','end')]}"/>
<field name="method_period"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/>
</group>
<group colspan="2" col="2">
<separator string="Depreciation Method" colspan="2" />
@@ -47,14 +47,29 @@
<field name="arch" type="xml">
<tree string="Asset category">
<field name="name"/>
<field name="method_time"/>
<field name="method_delay"/>
<field name="method"/>
<field name="journal_id"/>
<field name="account_asset_id"/>
<field name="account_depreciation_id"/>
<field name="account_expense_depreciation_id"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_account_asset_category_search">
<field name="name">account.asset.category.search</field>
<field name="model">account.asset.category</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Search Asset Category">
<field name="name"/>
<field name="journal_id"/>
</search>
</field>
</record>
<record model="ir.ui.view" id="view_account_asset_asset_form">
<field name="name">account.asset.asset.form</field>
<field name="model">account.asset.asset</field>
@@ -74,21 +89,24 @@
<notebook colspan="4">
<page string="Depreciation">
<separator string="Other Information" colspan="4"/>
<field name="parent_id"/>
<field name="partner_id"/>
<field name="purchase_date"/>
<newline/>
<group colspan="2" col="2">
<separator string="Depreciation Dates" colspan="2" />
<button
name="%(wizard_asset_modify)d"
states="open"
string="Change duration"
type="action"
colspan="2"/>
<newline/>
<field name="method_time" on_change="onchange_method_time(method_time)"/>
<field name="method_delay" attrs="{'invisible':[('method_time','=','end')]}"/>
<field name="method_period"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/>
<field name="method_end" attrs="{'required': [('method_time','=','end')], 'invisible':[('method_time','=','delay')]}"/>
<newline/>
<button
name="%(action_asset_modify)d"
states="open"
string="Change Duration"
type="action"
icon="terp-stock_effects-object-colorize"
colspan="2"/>
</group>
<group colspan="2" col="2">
<separator string="Depreciation Method" colspan="2" />
@@ -97,6 +115,12 @@
<field name="prorata" attrs="{'invisible': ['|',('method_time','=','end'),('method','!=','linear')]}"/>
</group>
<newline/>
<separator string="" colspan="4" />
<field name="state" readonly="1" colspan="2"/>
<group colspan="2" col="2">
<button name="validate" states="draft" string="Confirm Asset" type="object" icon="terp-camera_test"/>
<button name="set_to_close" states="open" string="Set to Close" type="object" icon="gtk-close"/>
</group>
</page>
<page string="Depreciation board">
<field name="depreciation_line_ids" colspan="4" nolabel="1" mode="tree,graph" >
@@ -115,7 +139,7 @@
<field name="depreciated_value"/>
</graph>
</field>
<button type="object" name="compute_depreciation_board" string="Compute" icon="terp-stock_format-scientific" colspan="2"/>
<button type="object" name="compute_depreciation_board" string="Compute" icon="terp-stock_format-scientific" colspan="2" attrs="{'invisible':[('state','=','close')]}"/>
</page>
<page string="History">
<field name="account_move_line_ids" colspan="4" nolabel="1" readonly="1"/>
@@ -125,10 +149,6 @@
<field name="note" nolabel="1"/>
</page>
</notebook>
<field name="state" readonly="1"/>
<group colspan="2" col="2">
<button name="validate" states="draft" string="Confirm asset" type="object"/>
</group>
</form>
</field>
</record>
@@ -139,14 +159,20 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Asset history">
<group col="6" colspan="4">
<field name="name" select="1"/>
<field name="date" select="1"/>
<field name="user_id" select="1"/>
<field name="method_delay" select="2"/>
</group>
<group col="2" colspan="2">
<separator string="Depreciation Dates" colspan="2" />
<field name="method_time"/>
<field name="method_delay" attrs="{'invisible':[('method_time','=','end')]}"/>
<field name="method_period"/>
<field name="method_end"/>
<separator string="Notes" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
<field name="method_end" attrs="{'invisible':[('method_time','=','delay')]}"/>
</group>
<separator string="Notes" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
</form>
</field>
</record>
@@ -176,20 +202,63 @@
<field name="arch" type="xml">
<tree string="Assets">
<field name="name"/>
<field name="code"/>
<field name="category_id"/>
<field name="purchase_date"/>
<field name="partner_id"/>
<field name="purchase_value"/>
<field name="value_residual"/>
<field name="currency_id"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="state"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_account_asset_asset_hierarchy_tree">
<field name="name">account.asset.asset.hierarchy</field>
<field name="model">account.asset.asset</field>
<field name="type">tree</field>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<tree string="Assets">
<field name="name"/>
<field name="code"/>
<field name="category_id"/>
<field name="purchase_date"/>
<field name="purchase_value"/>
<field name="value_residual"/>
<field name="currency_id"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="view_account_asset_search" model="ir.ui.view">
<field name="name">account.asset.asset.search</field>
<field name="model">account.asset.asset</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Account Asset Analysis">
<group col="10" colspan="12">
<filter icon="terp-document-new" string="Draft" domain="[('state','=', 'draft')]" help="Assets in Draft State"/>
<filter icon="terp-camera_test" string="Running" domain="[('state','=', 'open')]" help="Assets in Running State"/>
<separator orientation="vertical"/>
<field name="name"/>
<field name="category_id"/>
<field name="purchase_date"/>
<field name="partner_id"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_account_asset_asset_tree">
<field name="name">Asset Hierarchy</field>
<field name="res_model">account.asset.asset</field>
<field name="view_type">tree</field>
<field name="domain">[('parent_id','=',False)]</field>
<field name="view_id" ref="view_account_asset_asset_tree"/>
<field name="view_id" ref="view_account_asset_asset_hierarchy_tree"/>
</record>
<menuitem id="menu_finance_assets" name="Assets" parent="account.menu_finance"/>
@@ -201,6 +270,8 @@
<field name="name">Assets</field>
<field name="res_model">account.asset.asset</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_account_asset_asset_tree"/>
<field name="search_view_id" ref="view_account_asset_search"/>
</record>
<menuitem
+2 -2
View File
@@ -18,9 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import account_asset_change_duration
import wizard_asset_compute
import wizard_asset_close
import wizard_asset_modify
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,131 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from lxml import etree
from osv import osv, fields
class asset_modify(osv.osv_memory):
_name = 'asset.modify'
_description = 'Modify Asset'
_columns = {
'name': fields.char('Reason', size=64, required=True),
'method_delay': fields.integer('Number of Depreciations'),
'method_period': fields.integer('Period Length'),
'method_end': fields.date('Ending date'),
'note': fields.text('Notes'),
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
""" Returns views and fields for current model.
@param cr: A database cursor
@param user: ID of the user currently logged in
@param view_id: list of fields, which required to read signatures
@param view_type: defines a view type. it can be one of (form, tree, graph, calender, gantt, search, mdx)
@param context: context arguments, like lang, time zone
@param toolbar: contains a list of reports, wizards, and links related to current model
@return: Returns a dictionary that contains definition for fields, views, and toolbars
"""
if not context:
context = {}
asset_obj = self.pool.get('account.asset.asset')
result = super(asset_modify, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
asset_id = context.get('active_id', False)
active_model = context.get('active_model', '')
if active_model == 'account.asset.asset' and asset_id:
asset = asset_obj.browse(cr, uid, asset_id, context=context)
doc = etree.XML(result['arch'])
if asset.method_time == 'delay':
node = doc.xpath("//field[@name='method_end']")[0]
node.set('invisible', '1')
elif asset.method_time == 'end':
node = doc.xpath("//field[@name='method_delay']")[0]
node.set('invisible', '1')
result['arch'] = etree.tostring(doc)
return result
def default_get(self, cr, uid, fields, context=None):
""" To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
if not context:
context = {}
asset_obj = self.pool.get('account.asset.asset')
res = super(asset_modify, self).default_get(cr, uid, fields, context=context)
asset_id = context.get('active_id', False)
asset = asset_obj.browse(cr, uid, asset_id, context=context)
if 'name' in fields:
res.update({'name': asset.name})
if 'method_delay' in fields and asset.method_time == 'delay':
res.update({'method_delay': asset.method_delay})
if 'method_period' in fields:
res.update({'method_period': asset.method_period})
if 'method_end' in fields and asset.method_time == 'end':
res.update({'method_end': asset.method_end})
return res
def modify(self, cr, uid, ids, context=None):
""" Modifies the duration of asset for calculating depreciation
and maintains the history of old values.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of Ids
@param context: A standard dictionary
@return: Close the wizard.
"""
if not context:
context = {}
asset_obj = self.pool.get('account.asset.asset')
history_obj = self.pool.get('account.asset.history')
asset_id = context.get('active_id', False)
asset = asset_obj.browse(cr, uid, asset_id, context=context)
data = self.browse(cr, uid, ids[0], context=context)
history_vals = {
'asset_id': asset_id,
'name': data.name,
'method_time': asset.method_time,
'method_delay': asset.method_delay,
'method_period': asset.method_period,
'method_end': asset.method_end,
'user_id': uid,
'date': time.strftime('%Y-%m-%d'),
'note': data.note,
}
history_obj.create(cr, uid, history_vals, context=context)
asset_vals = {
'method_delay': data.method_delay,
'method_period': data.method_period,
'method_end': data.method_end,
}
asset_obj.write(cr, uid, [asset_id], asset_vals, context=context)
return {'type': 'ir.actions.act_window_close'}
asset_modify()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="asset_modify_form">
<field name="name">wizard.asset.modify.form</field>
<field name="model">asset.modify</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Modify Asset">
<group colspan="4" col="4">
<separator string="Asset durations to modify" colspan="4"/>
<field name="name" colspan="4"/>
<group colspan="2" col="2">
<field name="method_delay"/>
<field name="method_end"/>
</group>
<field name="method_period"/>
<separator string="Notes" colspan="4"/>
<field name="note" nolabel="1" colspan="4"/>
</group>
<newline/>
<group colspan="4" col="4">
<separator string ="" colspan="4"/>
<newline/>
<group colspan="2" col="2"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="modify" string="Modify" type="object" icon="terp-camera_test"/>
</group>
</form>
</field>
</record>
<record id="action_asset_modify" model="ir.actions.act_window">
<field name="name">Modify Asset</field>
<field name="res_model">asset.modify</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="asset_modify_form"/>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -1,87 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import pooler
asset_end_arch = '''<?xml version="1.0"?>
<form string="Modify asset">
<separator string="Asset properties to modify" colspan="4"/>
<field name="name" colspan="4"/>
<field name="method_delay"/>
<field name="method_period"/>
<separator string="Notes" colspan="4"/>
<field name="note" nolabel="1" colspan="4"/>
</form>'''
asset_end_fields = {
'name': {'string':'Reason', 'type':'char', 'size':64, 'required':True},
'method_delay': {'string':'Number of interval', 'type':'float'},
'method_period': {'string':'Period per interval', 'type':'float'},
'note': {'string':'Notes', 'type':'text'},
}
def _asset_default(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
return {
'name': prop.name,
'method_delay': prop.method_delay,
'method_period': prop.method_period
}
def _asset_modif(self, cr, uid, data, context={}):
pool = pooler.get_pool(cr.dbname)
prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
pool.get('account.asset.property.history').create(cr, uid, {
'asset_property_id': data['id'],
'name': prop.name,
'method_delay': prop.method_delay,
'method_period': prop.method_period,
'note': data['form']['note'],
}, context)
pool.get('account.asset.property').write(cr, uid, [data['id']], {
'name': data['form']['name'],
'method_delay': data['form']['method_delay'],
'method_period': data['form']['method_period'],
}, context)
return {}
class wizard_asset_modify(wizard.interface):
states = {
'init': {
'actions': [_asset_default],
'result': {'type':'form', 'arch':asset_end_arch, 'fields':asset_end_fields, 'state':[
('end','Cancel'),
('asset_modify','Modify asset')
]}
},
'asset_modify': {
'actions': [_asset_modif],
'result': {'type' : 'state', 'state': 'end'}
}
}
wizard_asset_modify('account.asset.modify')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: