1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv,fields
24 class asset_modify(osv.osv_memory):
25 _name = 'asset.modify'
26 _description = 'Modify Asset'
29 'name': fields.char('Reason', size=64, required=True),
30 'method_delay': fields.float('Number of interval'),
31 'method_period': fields.float('Period per interval'),
32 'method_end': fields.date('Ending date'),
33 'note': fields.text('Notes'),
36 def default_get(self, cr, uid, fields, context=None):
37 asset_obj = self.pool.get('account.asset.asset')
38 res = super(asset_modify, self).default_get(cr, uid, fields, context=context)
39 asset_id = context.get('active_id', False)
40 asset = asset_obj.browse(cr, uid, asset_id, context=context)
42 res.update({'name': asset.name})
43 if 'method_delay' in fields and asset.method_time == 'delay':
44 res.update({'method_delay': asset.method_delay})
45 if 'method_period' in fields:
46 res.update({'method_period': asset.method_period})
47 if 'method_end' in fields and asset.method_time == 'end':
48 res.update({'method_end': asset.method_end})
51 def modify(self, cr, uid, ids, context=None):
52 asset_obj = self.pool.get('account.asset.asset')
53 history_obj = self.pool.get('account.asset.history')
54 asset_id = context.get('active_id', False)
55 asset = asset_obj.browse(cr, uid, asset_id, context=context)
56 data = self.browse(cr, uid, ids[0], context=context)
57 history_obj.create(cr, uid, {
60 'method_delay': asset.method_delay,
61 'method_period': asset.method_period,
62 'method_end': asset.method_end,
64 'date': time.strftime('%Y-%m-%d'),
67 asset_obj.write(cr, uid, [asset_id], {
69 'method_delay': data.method_delay,
70 'method_period': data.method_period,
71 'method_end': data.method_end,
73 return {'type': 'ir.actions.act_window_close'}
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: