[FIX] In the case where the user has no signature, we set up a default value to avoid...
[odoo/odoo.git] / addons / crm / wizard / crm_add_note.py
1 from .. import crm
2 from osv import fields, osv
3 from tools.translate import _
4 from mail.mail_message import truncate_text
5
6 AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
7
8 class crm_add_note(osv.osv_memory):
9     """Adds a new note to the case."""
10     _name = 'crm.add.note'
11     _description = "Add Internal Note"
12
13     _columns = {
14         'body': fields.text('Note Body', required=True),
15         'state': fields.selection(AVAILABLE_STATES, string='Set New State To',
16                                   required=True),
17     }
18
19     _defaults = {
20         'state': 'unchanged'
21     }
22
23     def action_add(self, cr, uid, ids, context=None):
24         if context is None:
25             context = {}
26
27         if not context.get('active_model'):
28             raise osv.except_osv(_('Error'), _('Can not add note!'))
29
30         model = context.get('active_model')
31         case_pool = self.pool.get(model)
32
33         for obj in self.browse(cr, uid, ids, context=context):
34             case_list = case_pool.browse(cr, uid, context['active_ids'],
35                                          context=context)
36             case = case_list[0]
37             case_pool.message_append(cr, uid, [case], truncate_text(obj.body),
38                                      body_text=obj.body)
39             if obj.state == 'unchanged':
40                 pass
41             elif obj.state == 'done':
42                 case_pool.case_close(cr, uid, [case.id])
43             elif obj.state == 'draft':
44                 case_pool.case_reset(cr, uid, [case.id])
45             elif obj.state in ['cancel', 'open', 'pending']:
46                 act = 'case_' + obj.state
47                 getattr(case_pool, act)(cr, uid, [case.id])
48
49         return {'type': 'ir.actions.act_window_close'}
50
51 crm_add_note()
52
53 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: