[ADD] added account_asset
[odoo/odoo.git] / addons / account_asset / wizard / wizard_asset_modify.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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
22 import wizard
23 import pooler
24
25 asset_end_arch = '''<?xml version="1.0"?>
26 <form string="Modify asset">
27     <separator string="Asset properties to modify" colspan="4"/>
28     <field name="name" colspan="4"/>
29     <field name="method_delay"/>
30     <field name="method_period"/>
31     <separator string="Notes" colspan="4"/>
32     <field name="note" nolabel="1" colspan="4"/>
33 </form>'''
34
35 asset_end_fields = {
36     'name': {'string':'Reason', 'type':'char', 'size':64, 'required':True},
37     'method_delay': {'string':'Number of interval', 'type':'float'},
38     'method_period': {'string':'Period per interval', 'type':'float'},
39     'note': {'string':'Notes', 'type':'text'},
40 }
41
42 def _asset_default(self, cr, uid, data, context={}):
43     pool = pooler.get_pool(cr.dbname)
44     prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
45     return {
46         'name': prop.name,
47         'method_delay': prop.method_delay,
48         'method_period': prop.method_period
49     }
50
51 def _asset_modif(self, cr, uid, data, context={}):
52     pool = pooler.get_pool(cr.dbname)
53     prop = pool.get('account.asset.property').browse(cr, uid, data['id'], context)
54     pool.get('account.asset.property.history').create(cr, uid, {
55         'asset_property_id': data['id'],
56         'name': prop.name,
57         'method_delay': prop.method_delay,
58         'method_period': prop.method_period,
59         'note': data['form']['note'],
60     }, context)
61     pool.get('account.asset.property').write(cr, uid, [data['id']], {
62         'name': data['form']['name'],
63         'method_delay': data['form']['method_delay'],
64         'method_period': data['form']['method_period'],
65     }, context)
66     return {}
67
68
69 class wizard_asset_modify(wizard.interface):
70     states = {
71         'init': {
72             'actions': [_asset_default],
73             'result': {'type':'form', 'arch':asset_end_arch, 'fields':asset_end_fields, 'state':[
74                 ('end','Cancel'),
75                 ('asset_modify','Modify asset')
76             ]}
77         },
78         'asset_modify': {
79             'actions': [_asset_modif],
80             'result': {'type' : 'state', 'state': 'end'}
81         }
82     }
83 wizard_asset_modify('account.asset.modify')
84
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
87