[MERGE] From Christophe Chauvet (Sylëam)
[odoo/odoo.git] / addons / account_analytic_plans / wizard / create_model.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22 import wizard
23 import time
24 import netsvc
25 import pooler
26 from tools.translate import _
27
28 info = '''<?xml version="1.0"?>
29 <form string="Distribution Model Saved">
30     <label string="This distribution model has been saved.\nYou will be able to reuse it later."/>
31 </form>'''
32
33
34 def activate(self, cr, uid, data, context):
35     plan_obj = pooler.get_pool(cr.dbname).get('account.analytic.plan.instance')
36     if data['id']:
37         plan = plan_obj.browse(cr, uid, data['id'], context)
38         if (not plan.name) or (not plan.code):
39             raise wizard.except_wizard(_('Error'), _('Please put a name and a code before saving the model !'))
40         pids  =  pooler.get_pool(cr.dbname).get('account.analytic.plan').search(cr, uid, [], context=context)
41         if (not pids):
42             raise wizard.except_wizard(_('Error'), _('No analytic plan defined !'))
43         plan_obj.write(cr,uid,[data['id']],{'plan_id':pids[0]})
44         return 'info'
45     else:
46         return 'endit'
47
48 def _do_nothing(self, cr, uid, data, context):
49     return 1
50
51 class create_model(wizard.interface):
52
53     states = {
54         'init': {
55             'actions': [],
56             'result': {'type':'choice','next_state':activate}
57         },
58         'info': {
59             'actions': [],
60             'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
61         },
62         'endit': {
63             'actions': [],
64             'result': {'type':'action','action':_do_nothing , 'state':'end'} #FIXME: check
65         },
66     }
67 create_model('create.model')
68
69
70 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
71