'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
'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'
}
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):
-
!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"