2011-06-24 13:01:31 +00:00
|
|
|
# -*- 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
|
2011-06-27 12:22:39 +00:00
|
|
|
from lxml import etree
|
2011-06-27 08:51:42 +00:00
|
|
|
|
2011-06-27 10:51:05 +00:00
|
|
|
from osv import osv, fields
|
2011-06-24 13:01:31 +00:00
|
|
|
|
|
|
|
class asset_modify(osv.osv_memory):
|
|
|
|
_name = 'asset.modify'
|
|
|
|
_description = 'Modify Asset'
|
|
|
|
|
|
|
|
_columns = {
|
2011-06-24 13:08:21 +00:00
|
|
|
'name': fields.char('Reason', size=64, required=True),
|
2011-07-01 08:05:12 +00:00
|
|
|
'method_delay': fields.integer('Number of Depreciations'),
|
2011-06-27 10:51:05 +00:00
|
|
|
'method_period': fields.integer('Period Length'),
|
2011-06-24 13:08:21 +00:00
|
|
|
'method_end': fields.date('Ending date'),
|
|
|
|
'note': fields.text('Notes'),
|
2011-06-24 13:01:31 +00:00
|
|
|
}
|
2011-06-27 12:22:39 +00:00
|
|
|
|
|
|
|
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 = {}
|
2011-07-01 08:05:12 +00:00
|
|
|
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)
|
2011-06-27 12:22:39 +00:00
|
|
|
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
|
|
|
|
|
2011-06-24 13:01:31 +00:00
|
|
|
def default_get(self, cr, uid, fields, context=None):
|
2011-06-24 13:08:21 +00:00
|
|
|
""" 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.
|
|
|
|
"""
|
2011-07-01 08:05:12 +00:00
|
|
|
if not context:
|
|
|
|
context = {}
|
2011-06-24 13:01:31 +00:00
|
|
|
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):
|
2011-06-24 13:08:21 +00:00
|
|
|
""" 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.
|
|
|
|
"""
|
2011-07-01 08:05:12 +00:00
|
|
|
if not context:
|
|
|
|
context = {}
|
2011-06-24 13:01:31 +00:00
|
|
|
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)
|
2011-06-27 08:51:42 +00:00
|
|
|
history_vals = {
|
2011-06-24 13:01:31 +00:00
|
|
|
'asset_id': asset_id,
|
2011-07-01 08:05:12 +00:00
|
|
|
'name': data.name,
|
2011-06-24 13:01:31 +00:00
|
|
|
'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,
|
2011-06-27 08:51:42 +00:00
|
|
|
}
|
|
|
|
history_obj.create(cr, uid, history_vals, context=context)
|
|
|
|
asset_vals = {
|
2011-06-24 13:01:31 +00:00
|
|
|
'method_delay': data.method_delay,
|
|
|
|
'method_period': data.method_period,
|
|
|
|
'method_end': data.method_end,
|
2011-06-27 08:51:42 +00:00
|
|
|
}
|
|
|
|
asset_obj.write(cr, uid, [asset_id], asset_vals, context=context)
|
2011-06-24 13:01:31 +00:00
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
|
|
|
|
|
|
asset_modify()
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|