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 1/6] [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. From 35749e33b3e5982928e25fc12787c6071dc426f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 11:20:15 +0200 Subject: [PATCH 2/6] [REF] crm_helpdesk: removed inheritance to base_state + some refactoring (clickable statusbar widget, case management directly in write) bzr revid: tde@openerp.com-20130813092015-mj33hgokdh87zoqs --- addons/crm_helpdesk/crm_helpdesk.py | 50 ++++++++++++++++++----- addons/crm_helpdesk/crm_helpdesk_view.xml | 18 ++------ 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/addons/crm_helpdesk/crm_helpdesk.py b/addons/crm_helpdesk/crm_helpdesk.py index deab9f19a20..03e6a243851 100644 --- a/addons/crm_helpdesk/crm_helpdesk.py +++ b/addons/crm_helpdesk/crm_helpdesk.py @@ -19,23 +19,14 @@ # ############################################################################## -from openerp.addons.base_status.base_state import base_state from openerp.addons.crm import crm from openerp.osv import fields, osv from openerp import tools from openerp.tools.translate import _ from openerp.tools import html2plaintext -AVAILABLE_STATES = [ - ('draft', 'New'), - ('cancel', 'Cancelled'), - ('open', 'In Progress'), - ('pending', 'Pending'), - ('done', 'Closed') -] - -class crm_helpdesk(base_state, osv.osv): +class crm_helpdesk(osv.osv): """ Helpdesk Cases """ _name = "crm.helpdesk" @@ -73,7 +64,12 @@ class crm_helpdesk(base_state, osv.osv): domain="['|',('section_id','=',False),('section_id','=',section_id),\ ('object_id.model', '=', 'crm.helpdesk')]"), 'duration': fields.float('Duration', states={'done': [('readonly', True)]}), - 'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True, + 'state': fields.selection( + [('draft', 'New'), + ('open', 'In Progress'), + ('pending', 'Pending'), + ('done', 'Closed'), + ('cancel', 'Cancelled')], 'Status', size=16, readonly=True, track_visibility='onchange', help='The status is set to \'Draft\', when a case is created.\ \nIf the case is in progress the status is set to \'Open\'.\ \nWhen the case is over, the status is set to \'Done\'.\ @@ -89,6 +85,38 @@ class crm_helpdesk(base_state, osv.osv): 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], } + 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 = { + 'email_from': partner.email, + } + return {'value': values} + + 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') in ['draft', 'open'] and not values.get('date_open'): + values['date_open'] = fields.datetime.now() + elif values.get('state') == 'close' and not values.get('date_closed'): + values['date_closed'] = fields.datetime.now() + return super(crm_helpdesk, self).write(cr, uid, ids, values, context=context) + + def case_escalate(self, cr, uid, ids, context=None): + """ Escalates case to parent level """ + data = {'active': True} + for case in self.browse(cr, uid, ids, context=context): + if case.section_id and case.section_id.parent_id: + parent_id = case.section_id.parent_id + data['section_id'] = parent_id.id + if parent_id.change_responsible and parent_id.user_id: + data['user_id'] = parent_id.user_id.id + else: + raise osv.except_osv(_('Error!'), _('You can not escalate, you are already at the top level regarding your sales-team category.')) + self.write(cr, uid, [case.id], data, context=context) + return True + # ------------------------------------------------------- # Mail gateway # ------------------------------------------------------- diff --git a/addons/crm_helpdesk/crm_helpdesk_view.xml b/addons/crm_helpdesk/crm_helpdesk_view.xml index f97fe654166..fe98c2e6e9e 100644 --- a/addons/crm_helpdesk/crm_helpdesk_view.xml +++ b/addons/crm_helpdesk/crm_helpdesk_view.xml @@ -29,21 +29,10 @@
-
@@ -58,8 +47,7 @@ + on_change="on_change_partner_id(partner_id)"/> From bab789e7a0f3154126c4660813f451887de02548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 11:20:42 +0200 Subject: [PATCH 3/6] [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 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" From 689b0b67ec4ba56bfc366daa7eb405376275c80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 11:47:19 +0200 Subject: [PATCH 4/6] [REF] base_calendar: removed inheritance to base_state + small refactoring (state management in write) bzr revid: tde@openerp.com-20130813094719-iyx2flyruw7q0q8i --- addons/base_calendar/crm_meeting.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/base_calendar/crm_meeting.py b/addons/base_calendar/crm_meeting.py index 1051a7a894c..66823e0b8f4 100644 --- a/addons/base_calendar/crm_meeting.py +++ b/addons/base_calendar/crm_meeting.py @@ -25,7 +25,6 @@ from openerp.osv import fields, osv from openerp.tools import DEFAULT_SERVER_DATE_FORMAT from openerp.tools.translate import _ from base_calendar import get_real_ids, base_calendar_id2real_id -from openerp.addons.base_status.base_state import base_state # # crm.meeting is defined here so that it may be used by modules other than crm, # without forcing the installation of crm. @@ -38,14 +37,13 @@ class crm_meeting_type(osv.Model): 'name': fields.char('Name', size=64, required=True, translate=True), } -class crm_meeting(base_state, osv.Model): +class crm_meeting(osv.Model): """ Model for CRM meetings """ _name = 'crm.meeting' _description = "Meeting" _order = "id desc" _inherit = ["calendar.event", "mail.thread", "ir.needaction_mixin"] _columns = { - # base_state required fields 'create_date': fields.datetime('Creation Date', readonly=True), 'write_date': fields.datetime('Write Date', readonly=True), 'date_open': fields.datetime('Confirmed', readonly=True), @@ -79,6 +77,12 @@ class crm_meeting(base_state, osv.Model): default['attendee_ids'] = False return super(crm_meeting, self).copy(cr, uid, id, default, context) + def write(self, cr, uid, ids, values, context=None): + """ Override to add case management: open/close dates """ + if values.get('state')and values.get('state') == 'open': + values['date_open'] = fields.datetime.now() + return super(crm_meeting, self).write(cr, uid, ids, values, context=context) + def onchange_partner_ids(self, cr, uid, ids, value, context=None): """ The basic purpose of this method is to check that destination partners effectively have email addresses. Otherwise a warning is thrown. From 9194308cd40a3791684155a611ee7f9fd4b94bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Aug 2013 11:47:47 +0200 Subject: [PATCH 5/6] [FIX] hr_recruitment, project_issue, crm_phonecall: fixes related to the removal of base_state/base_stage and all case_ methods bzr revid: tde@openerp.com-20130813094747-dm06sx2glgdgal9m --- addons/crm/crm_phonecall.py | 11 +++++------ addons/crm/crm_phonecall_view.xml | 8 -------- addons/crm/test/lead2opportunity2win.yml | 2 +- .../wizard/hr_recruitment_create_partner_job.py | 2 -- addons/project_issue/project_issue.py | 1 - 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py index 58819f7a275..cfe824fea32 100644 --- a/addons/crm/crm_phonecall.py +++ b/addons/crm/crm_phonecall.py @@ -141,7 +141,7 @@ class crm_phonecall(osv.osv): } new_id = self.create(cr, uid, vals, context=context) if action == 'log': - self.case_close(cr, uid, [new_id]) + self.write(cr, uid, [new_id], {'state': 'done'}, context=context) phonecall_dict[call.id] = new_id return phonecall_dict @@ -249,12 +249,11 @@ class crm_phonecall(osv.osv): 'email_from': default_contact and default_contact.email, }) vals = { - 'partner_id': partner_id, - 'opportunity_id' : opportunity_id, + 'partner_id': partner_id, + 'opportunity_id': opportunity_id, + 'state': 'done', } - self.write(cr, uid, [call.id], vals) - self.case_close(cr, uid, [call.id]) - opportunity.case_open(cr, uid, [opportunity_id]) + self.write(cr, uid, [call.id], vals, context=context) opportunity_dict[call.id] = opportunity_id return opportunity_dict diff --git a/addons/crm/crm_phonecall_view.xml b/addons/crm/crm_phonecall_view.xml index b06075b2dcf..e9acef597e5 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -50,14 +50,6 @@ -