[FIX] CRM: phone call ==> Set To TOdo from cancel state
[odoo/odoo.git] / addons / crm / crm_phonecall.py
index 2443bd7..4246fa4 100644 (file)
@@ -35,7 +35,7 @@ class crm_phonecall(crm_base, osv.osv):
     _columns = {
         # From crm.case
         'id': fields.integer('ID', readonly=True),
-        'name': fields.char('Call Summary', size=64),
+        'name': fields.char('Call Summary', size=64, required=True),
         'active': fields.boolean('Active', required=False),
         'date_action_last': fields.datetime('Last Action', readonly=1),
         'date_action_next': fields.datetime('Next Action', readonly=1),
@@ -118,7 +118,7 @@ class crm_phonecall(crm_base, osv.osv):
         """Resets case as Todo
         """
         res = super(crm_phonecall, self).case_reset(cr, uid, ids, args, 'crm.phonecall')
-        self.write(cr, uid, ids, {'duration': 0.0})
+        self.write(cr, uid, ids, {'duration': 0.0, 'state':'open'})
         return res
 
 
@@ -148,7 +148,7 @@ class crm_phonecall(crm_base, osv.osv):
             vals = {
                     'name' : call_summary,
                     'user_id' : user_id or False,
-                    'categ_id' : categ_id.id or False,
+                    'categ_id' : categ_id or False,
                     'description' : call.description or False,
                     'date' : schedule_time,
                     'section_id' : section_id or False,
@@ -197,7 +197,6 @@ class crm_phonecall(crm_base, osv.osv):
             context = {}
         partner_ids = {}
         for call in self.browse(cr, uid, ids, context=context):
-            partner_id = call.partner_id and call.partner_id.id or False
             if action == 'create':
                if not partner_id:
                    partner_id = self._call_create_partner(cr, uid, call, context=context)
@@ -210,25 +209,18 @@ class crm_phonecall(crm_base, osv.osv):
     def redirect_phonecall_view(self, cr, uid, phonecall_id, context=None):
         model_data = self.pool.get('ir.model.data')
         # Select the view
-        id2 = model_data._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view')
-        id3 = model_data._get_id(cr, uid, 'crm', 'crm_case_phone_form_view')
-        if id2:
-            id2 = model_data.browse(cr, uid, id2, context=context).res_id
-        if id3:
-            id3 = model_data.browse(cr, uid, id3, context=context).res_id
-
-        result = model_data._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
-        res = model_data.read(cr, uid, result, ['res_id'])
-
+        tree_view = model_data.get_object_reference(cr, uid, 'crm', 'crm_case_phone_tree_view')
+        form_view = model_data.get_object_reference(cr, uid, 'crm', 'crm_case_phone_form_view')
+        search_view = model_data.get_object_reference(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
         value = {
                 'name': _('Phone Call'),
                 'view_type': 'form',
                 'view_mode': 'tree,form',
                 'res_model': 'crm.phonecall',
                 'res_id' : int(phonecall_id),
-                'views': [(id3, 'form'), (id2, 'tree'), (False, 'calendar')],
+                'views': [(form_view and form_view[1] or False, 'form'), (tree_view and tree_view[1] or False, 'tree'), (False, 'calendar')],
                 'type': 'ir.actions.act_window',
-                'search_view_id': res['res_id'],
+                'search_view_id': search_view and search_view[1] or False,
         }
         return value
 
@@ -256,7 +248,6 @@ class crm_phonecall(crm_base, osv.osv):
                             'mobile': default_contact and default_contact.mobile,
                             'section_id': call.section_id and call.section_id.id or False,
                             'description': call.description or False,
-                            'phonecall_id': call.id,
                             'priority': call.priority,
                             'type': 'opportunity', 
                             'phone': call.partner_phone or False,