diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 65d096c6a51..3fe9e131678 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -830,9 +830,9 @@ class crm_lead(format_address, osv.osv): 'priority': lead.priority, } new_id = phonecall.create(cr, uid, vals, context=context) - phonecall.case_open(cr, uid, [new_id], context=context) + phonecall.write(cr, uid, [new_id], {'state': 'open'}, context=context) if action == 'log': - phonecall.case_close(cr, uid, [new_id], context=context) + phonecall.write(cr, uid, [new_id], {'state': 'done'}, context=context) phonecall_dict[lead.id] = new_id self.schedule_phonecall_send_note(cr, uid, [lead.id], new_id, action, context=context) return phonecall_dict diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py index 2a5c7181ca6..58819f7a275 100644 --- a/addons/crm/crm_phonecall.py +++ b/addons/crm/crm_phonecall.py @@ -44,6 +44,7 @@ class crm_phonecall(osv.osv): 'state': fields.selection( [('open', 'Confirmed'), ('cancel', 'Cancelled'), + ('pending', 'Pending'), ('done', 'Held') ], string='Status', readonly=True, track_visibility='onchange', help='The status is set to Confirmed, when a case is created.\n' @@ -89,28 +90,25 @@ class crm_phonecall(osv.osv): } return {'value': values} - def case_close(self, cr, uid, ids, context=None): - for phone in self.browse(cr, uid, ids, context=context): - data = { - 'state': 'done', - 'date_closed': fields.datetime.now(), - } - if phone.duration <= 0: - duration = datetime.now() - datetime.strptime(phone.date, DEFAULT_SERVER_DATETIME_FORMAT) - data['duration'] = duration.seconds/float(60) - self.write(cr, uid, [phone.id], data, context=context) + def write(self, cr, uid, ids, values, context=None): + """ Override to add case management: open/close dates """ + if values.get('state'): + if values.get('state') == 'done': + values['date_closed'] = fields.datetime.now() + self.compute_duration(cr, uid, ids, context=context) + elif values.get('state') == 'open': + values['date_open'] = fields.datetime.now() + values['duration'] = 0.0 + return super(crm_phonecall, self).write(cr, uid, ids, values, context=context) + + def compute_duration(self, cr, uid, ids, context=None): + for phonecall in self.browse(cr, uid, ids, context=context): + if phonecall.duration <= 0: + duration = datetime.now() - datetime.strptime(phonecall.date, DEFAULT_SERVER_DATETIME_FORMAT) + values = {'duration': duration.seconds/float(60)} + self.write(cr, uid, [phonecall.id], values, context=context) return True - def case_reset(self, cr, uid, ids, context=None): - data = { - 'state': 'open', - 'duration': 0.0, - } - return self.write(cr, uid, ids, data, context=context) - - def case_cancel(self, cr, uid, ids, context=None): - return self.write(cr, uid, ids, {'state': 'cancel'}, context=context) - def schedule_another_phonecall(self, cr, uid, ids, schedule_time, call_summary, \ user_id=False, section_id=False, categ_id=False, action='schedule', context=None): """ diff --git a/addons/crm/crm_phonecall_view.xml b/addons/crm/crm_phonecall_view.xml index ad8ac50a15c..b06075b2dcf 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -69,13 +69,7 @@
-
diff --git a/addons/crm/test/phonecalls.yml b/addons/crm/test/phonecalls.yml index 51a933f3223..b1ea184f59b 100644 --- a/addons/crm/test/phonecalls.yml +++ b/addons/crm/test/phonecalls.yml @@ -10,43 +10,3 @@ - !python {model: crm.phonecall}: | self.action_make_meeting(cr, uid, [ref("crm.crm_phonecall_6")]) -- - I set the phone call to not held. -- - !python {model: crm.phonecall}: | - self.case_pending(cr, uid, [ref("crm.crm_phonecall_6")]) -- - I check that the phone call is in 'Not Held' state. -- - !assert {model: crm.phonecall, id: crm.crm_phonecall_6, string: Phone call held.}: - - state == "pending" -- - I cancel the phone call. -- - !python {model: crm.phonecall}: | - self.case_cancel(cr, uid, [ref("crm.crm_phonecall_6")]) -- - I check that the phone call is in 'Cancelled' state. -- - !assert {model: crm.phonecall, id: crm.crm_phonecall_6, string: Phone call is not cancelled.}: - - state == "cancel" -- - I reset the phone call. -- - !python {model: crm.phonecall}: | - self.case_reset(cr, uid, [ref("crm.crm_phonecall_6")]) -- - I check that the phone call is reset. -- - !assert {model: crm.phonecall, id: crm.crm_phonecall_6, string: Phone call is not reset.}: - - state == "open" -- - I set phone call to held (done). -- - !python {model: crm.phonecall}: | - self.case_close(cr, uid, [ref("crm.crm_phonecall_6")]) -- - I check that the phone call is in 'Held' state. -- - !assert {model: crm.phonecall, id: crm.crm_phonecall_6, string: Phone call is not held.}: - - state == "done"