From bab789e7a0f3154126c4660813f451887de02548 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 11:20:42 +0200 Subject: [PATCH] [REF] crm_phonecall: refactored case management (directly in write + clickable statusbar widget) + deleted some tests not applicable anymore bzr revid: tde@openerp.com-20130813092042-1r0yfqdacv894v21 --- addons/crm/crm_lead.py | 4 ++-- addons/crm/crm_phonecall.py | 38 +++++++++++++++++------------------ addons/crm/crm_phonecall_view.xml | 8 +------- addons/crm/test/phonecalls.yml | 40 ------------------------------------- 4 files changed, 21 insertions(+), 69 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 65d096c..3fe9e13 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 2a5c718..58819f7 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,27 +90,24 @@ 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) - return True + 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 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 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 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 ad8ac50..b06075b 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 51a933f..b1ea184 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" -- 1.7.10.4