2 from osv import fields, osv
3 from tools.translate import _
6 AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
9 class crm_add_note(osv.osv_memory):
10 """Adds a new note to the case."""
11 _name = 'crm.add.note'
12 _description = "Add Internal Note"
15 'body': fields.text('Note Body', required=True),
16 'state': fields.selection(AVAILABLE_STATES, string='Set New State To',
18 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'),
21 def action_add(self, cr, uid, ids, context=None):
25 if not context.get('active_model'):
26 raise osv.except_osv(_('Error'), _('Can not add note!'))
28 model = context.get('active_model')
29 case_pool = self.pool.get(model)
31 for obj in self.browse(cr, uid, ids, context=context):
32 case_list = case_pool.browse(cr, uid, context['active_ids'],
35 user_obj = self.pool.get('res.users')
36 user_name = user_obj.browse(cr, uid, [uid], context=context)[0].name
38 (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
40 case_pool.history(cr, uid, [case], self.pool.get('mailgate.message').truncate_data(cr, uid, obj.body, context=context), history=False,
41 details=obj.body, email_from=user_name, attach=attach)
43 if obj.state == 'unchanged':
45 elif obj.state == 'done':
46 case_pool.case_close(cr, uid, [case.id])
47 elif obj.state == 'draft':
48 case_pool.case_reset(cr, uid, [case.id])
49 elif obj.state in ['cancel', 'open', 'pending']:
50 act = 'case_' + obj.state
51 getattr(case_pool, act)(cr, uid, [case.id])
53 return {'type': 'ir.actions.act_window_close'}
55 def default_get(self, cr, uid, fields, context=None):
57 This function gets default values
59 return {'state': u'unchanged'}