added from extra-addons
[odoo/odoo.git] / addons / sale_crm / wizard / makecase.py
1 # -*- encoding: utf-8 -*-
2 '''Make case wizard'''
3 ##############################################################################
4 #
5 # Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30 import wizard
31 import pooler
32
33 def _get_default(obj, cursor, uid, data, context=None):
34     '''Get default value'''
35     return {'user': uid}
36
37 def _make_case(obj, cursor, uid, data, context=None):
38     '''Create case'''
39     pool = pooler.get_pool(cursor.dbname)
40     case_obj = pool.get('crm.case')
41     mod_obj = pool.get('ir.model.data')
42     act_obj = pool.get('ir.actions.act_window')
43
44     new_id = []
45
46     for partner_id in data['ids']:
47         new_id.append(case_obj.create(cursor, uid, {
48             'name': data['form']['name'],
49             'section_id': data['form']['section'],
50             'partner_id': partner_id,
51             'description': data['form']['description'],
52             }))
53
54     result = mod_obj._get_id(cursor, uid, 'crm', 'crm_case_categ0-act')
55     res_id = mod_obj.read(cursor, uid, [result], ['res_id'])[0]['res_id']
56     result = act_obj.read(cursor, uid, [res_id])[0]
57     result['domain'] = str([('id', 'in', new_id)])
58     return result
59
60
61 class MakeCase(wizard.interface):
62     '''Wizard that create case on partner'''
63
64     case_form = """<?xml version="1.0"?>
65 <form string="Make Case">
66     <field name="name"/>
67     <field name="section"/>
68     <field name="user"/>
69     <field name="description" colspan="4"/>
70 </form>"""
71
72     case_fields = {
73         'name': {'string': 'Case Description', 'type': 'char', 'size': 64,
74             'required': True},
75         'section': {'string': 'Case Section', 'type': 'many2one',
76             'relation': 'crm.case.section', 'required': True},
77         'user': {'string': 'User Responsible', 'type': 'many2one',
78             'relation': 'res.users'},
79         'description': {'string': 'Your action', 'type': 'text'},
80     }
81
82     states = {
83         'init': {
84             'actions': [_get_default],
85             'result': {'type': 'form', 'arch': case_form, 'fields': case_fields,
86                 'state': [
87                     ('end', 'Cancel'),
88                     ('create', 'Create')
89                 ]
90             }
91         },
92         'create': {
93             'actions': [],
94             'result': {'type': 'action', 'action': _make_case, 'state': 'end'}
95         }
96     }
97
98 MakeCase('sale_crm.make_case')
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
100