2 from osv import fields, osv
3 from tools.translate import _
4 from mail.mail_message import truncate_text
6 AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
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"
14 'body': fields.text('Note Body', required=True),
15 'state': fields.selection(AVAILABLE_STATES, string='Set New State To',
23 def action_add(self, cr, uid, ids, context=None):
27 if not context.get('active_model'):
28 raise osv.except_osv(_('Error'), _('Can not add note!'))
30 model = context.get('active_model')
31 case_pool = self.pool.get(model)
33 for obj in self.browse(cr, uid, ids, context=context):
34 case_list = case_pool.browse(cr, uid, context['active_ids'],
37 case_pool.message_append(cr, uid, [case], truncate_text(obj.body),
39 if obj.state == 'unchanged':
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])
49 return {'type': 'ir.actions.act_window_close'}