fcca6181e555e9234a244785ca2962ea23d08db4
[odoo/odoo.git] / addons / account_asset / wizard / account_asset_change_duration.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21 import time
22 from osv import osv,fields
23
24 class asset_modify(osv.osv_memory):
25     _name = 'asset.modify'
26     _description = 'Modify Asset'
27
28     _columns = {
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'),
34     }
35     
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)
41         if 'name' in fields:
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})
49         return res
50     
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, {
58             'asset_id': asset_id,
59             'name': asset.name,
60             'method_delay': asset.method_delay,
61             'method_period': asset.method_period,
62             'method_end': asset.method_end,
63             'user_id': uid,
64             'date': time.strftime('%Y-%m-%d'),
65             'note': data.note,
66         }, context=context)
67         asset_obj.write(cr, uid, [asset_id], {
68             'name': data.name,
69             'method_delay': data.method_delay,
70             'method_period': data.method_period,
71             'method_end': data.method_end,
72         }, context=context)
73         return {'type': 'ir.actions.act_window_close'}
74
75 asset_modify()
76
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: