added from extra-addons
[odoo/odoo.git] / addons / account_analytic_plans / wizard / create_model.py
1 # -*- encoding: utf-8 -*-
2 import wizard
3 import time
4 import netsvc
5 import pooler
6
7 info = '''<?xml version="1.0"?>
8 <form string="Distribution Model Saved">
9     <label string="This distribution model has been saved.\nYou will be able to reuse it later."/>
10 </form>'''
11
12 def activate(self, cr, uid, data, context):
13     plan_obj = pooler.get_pool(cr.dbname).get('account.analytic.plan.instance')
14     if data['id']:
15         plan = plan_obj.browse(cr, uid, data['id'], context)
16         if (not plan.name) or (not plan.code):
17             raise wizard.except_wizard('Error', 'Please put a name and a code before saving the model !')
18         pids  =  pooler.get_pool(cr.dbname).get('account.analytic.plan').search(cr, uid, [], context=context)
19         if (not pids):
20             raise wizard.except_wizard('Error', 'No analytic plan defined !')
21         plan_obj.write(cr,uid,[data['id']],{'plan_id':pids[0]})
22         return 'info'
23     else:
24         return 'endit'
25
26
27 class create_model(wizard.interface):
28
29     states = {
30         'init': {
31             'actions': [],
32             'result': {'type':'choice','next_state':activate}
33         },
34         'info': {
35             'actions': [],
36             'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
37         },
38         'endit': {
39             'actions': [],
40             'result': {'type':'form', 'arch':'', 'fields':{}, 'state':'end'}
41         },
42     }
43 create_model('create.model')
44
45
46 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
47