2 from osv import fields, osv
3 from tools.translate import _
6 AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
8 class crm_add_note_email_attachment(osv.osv_memory):
9 _name = 'crm.add.note.email.attachment'
12 'binary' : fields.binary('Attachment', required=True),
13 'name' : fields.char('Name', size=128, required=True),
14 'wizard_id' : fields.many2one('crm.add.note', 'Wizard', required=True),
17 crm_add_note_email_attachment()
19 class crm_add_note(osv.osv_memory):
20 """Adds a new note to the case."""
21 _name = 'crm.add.note'
22 _description = "Add Internal Note"
25 'body': fields.text('Note Body', required=True),
26 'state': fields.selection(AVAILABLE_STATES, string='Set New State To',
28 'attachment_ids' : fields.one2many('crm.add.note.email.attachment', 'wizard_id'),
31 def action_add(self, cr, uid, ids, context=None):
35 if not context.get('active_model'):
36 raise osv.except_osv(_('Error'), _('Can not add note!'))
38 model = context.get('active_model')
39 case_pool = self.pool.get(model)
41 for obj in self.browse(cr, uid, ids, context=context):
42 case_list = case_pool.browse(cr, uid, context['active_ids'],
45 user_obj = self.pool.get('res.users')
46 user_name = user_obj.browse(cr, uid, [uid], context=context)[0].name
48 (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
50 case_pool.history(cr, uid, [case], self.pool.get('email.message').truncate_data(cr, uid, obj.body, context=context), history=False,
51 details=obj.body, email_from=user_name, attach=attach)
53 if obj.state == 'unchanged':
55 elif obj.state == 'done':
56 case_pool.case_close(cr, uid, [case.id])
57 elif obj.state == 'draft':
58 case_pool.case_reset(cr, uid, [case.id])
59 elif obj.state in ['cancel', 'open', 'pending']:
60 act = 'case_' + obj.state
61 getattr(case_pool, act)(cr, uid, [case.id])
63 return {'type': 'ir.actions.act_window_close'}
65 def default_get(self, cr, uid, fields, context=None):
67 This function gets default values
69 return {'state': u'unchanged'}