From 70e4f3e6f48b8d691dbff01383ad75e48dc2887a Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Tue, 23 Mar 2010 19:42:01 +0530 Subject: [PATCH] [IMP]: crm: Implemented type=choice for lead to opportunity wizard, removed old wizard bzr revid: rpa@tinyerp.com-20100323141201-8ral0ueq1r8uzy69 --- addons/crm/crm_lead.py | 81 +++- addons/crm/crm_lead_view.xml | 6 +- addons/crm/wizard/crm_lead_to_opportunity.py | 380 +++++------------- .../wizard/crm_lead_to_opportunity_view.xml | 32 +- addons/crm/wizard/crm_lead_to_partner.py | 3 +- 5 files changed, 184 insertions(+), 318 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 00cebd4dcbf..49a8f47e0a2 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -23,9 +23,10 @@ from osv import fields, osv, orm from datetime import datetime, timedelta import crm import math +from tools.translate import _ class crm_lead(osv.osv): - """ CRm Lead Case """ + """ CRM Lead Case """ _name = "crm.lead" _description = "Leads Cases" @@ -67,8 +68,8 @@ class crm_lead(osv.osv): @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param ids: List of closeday’s IDs - @return: difference between current date and closed date @param context: A standard dictionary for contextual values + @return: difference between current date and closed date """ result = {} @@ -87,33 +88,77 @@ class crm_lead(osv.osv): 'categ_id': fields.many2one('crm.case.categ', 'Lead Source', \ domain="[('section_id','=',section_id),\ - ('object_id.model', '=', 'crm.opportunity')]"), - 'type_id': fields.many2one('crm.case.resource.type', 'Lead Type',\ + ('object_id.model', '=', 'crm.opportunity')]"), + 'type_id': fields.many2one('crm.case.resource.type', 'Lead Type', \ domain="[('section_id','=',section_id),\ - ('object_id.model', '=', 'crm.lead')]"), - 'partner_name': fields.char("Contact Name", size=64), + ('object_id.model', '=', 'crm.lead')]"), + 'partner_name': fields.char("Contact Name", size=64), - 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), - 'date_closed': fields.datetime('Closed', readonly=True), - 'stage_id': fields.many2one('crm.case.stage', 'Stage',\ + 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), + 'date_closed': fields.datetime('Closed', readonly=True), + 'stage_id': fields.many2one('crm.case.stage', 'Stage', \ domain="[('section_id','=',section_id),\ - ('object_id.model', '=', 'crm.lead')]"), - 'opportunity_id': fields.many2one('crm.opportunity', 'Opportunity'), + ('object_id.model', '=', 'crm.lead')]"), + 'opportunity_id': fields.many2one('crm.opportunity', 'Opportunity'), - 'user_id': fields.many2one('res.users', 'Salesman'), - 'referred': fields.char('Referred By', size=32), + 'user_id': fields.many2one('res.users', 'Salesman'), + 'referred': fields.char('Referred By', size=32), 'day_open': fields.function(_compute_openday, string='Days to Open', \ - method=True, type="integer", store=True), + method=True, type="integer", store=True), 'day_close': fields.function(_compute_closeday, string='Days to Close', \ - method=True, type="integer", store=True), - 'function_name' : fields.char('Function', size=64), + method=True, type="integer", store=True), + 'function_name' : fields.char('Function', size=64), } _defaults = { 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c), - 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], + 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], } + + def convert_opportunity(self, cr, uid, ids, context=None): + """ Precomputation for converting lead to opportunity + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks, + @param ids: List of closeday’s IDs + @param context: A standard dictionary for contextual values + @return: Value of action in dict + """ + if not context: + context = {} + context.update({'active_ids': ids}) + + data_obj = self.pool.get('ir.model.data') + data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_create') + value = {} + + view_id = False + if data_id: + view_id = data_obj.browse(cr, uid, data_id, context=context).res_id + for case in self.browse(cr, uid, ids): + context.update({'opportunity_id': case.id}) + context.update({'active_id': case.id}) + if not case.partner_id: + data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_partner') + view_id = False + if data_id: + view_id = data_obj.browse(cr, uid, data_id, context=context).res_id + break + + value = { + 'name': _('Create Opportunity'), + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.lead2opportunity', + 'view_id': False, + 'context': context, + 'views': [(view_id, 'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', + 'destroy': False + } + return value + crm_lead() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index dc379ddacfb..3f9c9c6c376 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -42,11 +42,11 @@