[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
This commit is contained in:
parent
35749e33b3
commit
bab789e7a0
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -69,13 +69,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Phone Call" version="7.0">
|
||||
<header>
|
||||
<button name="case_close" string="Call Done" type="object" class="oe_highlight"
|
||||
states="open,pending"/>
|
||||
<button name="case_reset" string="Reset to Todo" type="object"
|
||||
states="cancel"/>
|
||||
<button name="case_cancel" string="Cancel Call" type="object"
|
||||
states="draft,open,pending"/>
|
||||
<field name="state" widget="statusbar" nolabel="1" statusbar_visible="open,done"/>
|
||||
<field name="state" nolabel="1" widget="statusbar" clickable="True"/>
|
||||
</header>
|
||||
<sheet string="Phone Call">
|
||||
<div class="oe_right">
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue