From 2948a44a53755ba00f916863ce00c9e42d04bfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 10:44:47 +0200 Subject: [PATCH] [REF] crm_phonecall: removed inheritance towards base_state + some cleaning due to refactoring + changelog in crm/doc bzr revid: tde@openerp.com-20130813084447-tb2j9uir3vzy0ddw --- addons/crm/crm_phonecall.py | 64 +++++++++++++++++-------------- addons/crm/crm_phonecall_view.xml | 3 +- addons/crm/doc/changelog.rst | 1 + 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py index 0d7004e005b..2a5c7181ca6 100644 --- a/addons/crm/crm_phonecall.py +++ b/addons/crm/crm_phonecall.py @@ -19,21 +19,19 @@ # ############################################################################## -from openerp.addons.base_status.base_state import base_state import crm from datetime import datetime from openerp.osv import fields, osv from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.tools.translate import _ -class crm_phonecall(base_state, osv.osv): +class crm_phonecall(osv.osv): """ Model for CRM phonecalls """ _name = "crm.phonecall" _description = "Phonecall" _order = "id desc" _inherit = ['mail.thread'] _columns = { - # base_state required fields 'date_action_last': fields.datetime('Last Action', readonly=1), 'date_action_next': fields.datetime('Next Action', readonly=1), 'create_date': fields.datetime('Creation Date' , readonly=True), @@ -43,16 +41,14 @@ class crm_phonecall(base_state, osv.osv): 'partner_id': fields.many2one('res.partner', 'Contact'), 'company_id': fields.many2one('res.company', 'Company'), 'description': fields.text('Description'), - 'state': fields.selection([ ('draft', 'Draft'), - ('open', 'Confirmed'), - ('pending', 'Not Held'), - ('cancel', 'Cancelled'), - ('done', 'Held'),], - string='Status', size=16, readonly=True, track_visibility='onchange', - help='The status is set to \'Todo\', when a case is created.\ - If the case is in progress the status is set to \'Open\'.\ - When the call is over, the status is set to \'Held\'.\ - If the call needs to be done then the status is set to \'Not Held\'.'), + 'state': fields.selection( + [('open', 'Confirmed'), + ('cancel', 'Cancelled'), + ('done', 'Held') + ], string='Status', readonly=True, track_visibility='onchange', + help='The status is set to Confirmed, when a case is created.\n' + 'When the call is over, the status is set to Held.\n' + 'If the callis not applicable anymore, the status can be set to Cancelled.'), 'email_from': fields.char('Email', size=128, help="These people will receive email."), 'date_open': fields.datetime('Opened', readonly=True), # phonecall fields @@ -71,7 +67,7 @@ class crm_phonecall(base_state, osv.osv): } def _get_default_state(self, cr, uid, context=None): - if context and context.get('default_state', False): + if context and context.get('default_state'): return context.get('default_state') return 'open' @@ -79,29 +75,41 @@ class crm_phonecall(base_state, osv.osv): 'date': fields.datetime.now, 'priority': crm.AVAILABLE_PRIORITIES[2][0], 'state': _get_default_state, - 'user_id': lambda self,cr,uid,ctx: uid, + 'user_id': lambda self, cr, uid, ctx: uid, 'active': 1 } + def on_change_partner_id(self, cr, uid, ids, partner_id, context=None): + values = {} + if partner_id: + partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context) + values = { + 'partner_phone': partner.phone, + 'partner_mobile': partner.mobile, + } + return {'value': values} + def case_close(self, cr, uid, ids, context=None): - """ Overrides close for crm_case for setting duration """ - res = True for phone in self.browse(cr, uid, ids, context=context): - phone_id = phone.id - data = {} - if phone.duration <=0: + 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) - res = super(crm_phonecall, self).case_close(cr, uid, [phone_id], context=context) - self.write(cr, uid, [phone_id], data, context=context) - return res + self.write(cr, uid, [phone.id], data, context=context) + return True def case_reset(self, cr, uid, ids, context=None): - """Resets case as Todo - """ - res = super(crm_phonecall, self).case_reset(cr, uid, ids, context) - self.write(cr, uid, ids, {'duration': 0.0, 'state':'open'}, context=context) - return res + 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 6c1b31180be..ad8ac50a15c 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -105,8 +105,7 @@ - - + diff --git a/addons/crm/doc/changelog.rst b/addons/crm/doc/changelog.rst index e9bd1980956..5312329f4f5 100644 --- a/addons/crm/doc/changelog.rst +++ b/addons/crm/doc/changelog.rst @@ -8,6 +8,7 @@ Changelog - Stage/state update + - ``crm.phonecall``: removed inheritance towards ``base_state``. - ``crm.lead``: removed ``state`` field. Added ``date_last_stage_update`` field holding last stage_id modification. Updated reports. - ``crm.case.stage``: removed ``state`` field.