From ce0af9fc2a9b42a269d4066c8899a883d510a254 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:22:51 +0100 Subject: [PATCH 1/6] [FIX] cleanup trailing whitespace bzr revid: xmo@openerp.com-20101108142251-yye0ycby12o6sakf --- addons/account/installer.py | 4 +- addons/crm/wizard/crm_lead_to_opportunity.py | 126 +++++++++---------- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/addons/account/installer.py b/addons/account/installer.py index a9c459cec86..125bd2951e7 100644 --- a/addons/account/installer.py +++ b/addons/account/installer.py @@ -59,8 +59,8 @@ class account_installer(osv.osv_memory): "country."), 'date_start': fields.date('Start Date', required=True), 'date_stop': fields.date('End Date', required=True), - 'period': fields.selection([('month', 'Monthly'), ('3months','3 Monthly')], 'Periods', required=True), - 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Your Bank and Cash Accounts'), + 'period': fields.selection([('month', 'Monthly'), ('3months', '3 Monthly')], 'Periods', required=True), + 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Your Bank and Cash Accounts',required=True), 'sale_tax': fields.float('Sale Tax(%)'), 'purchase_tax': fields.float('Purchase Tax(%)'), 'company_id': fields.many2one('res.company', 'Company'), diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index ccf85a36422..c84c7f3ba11 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -26,7 +26,7 @@ from tools.translate import _ class crm_lead2opportunity(osv.osv_memory): _name = 'crm.lead2opportunity' _description = 'Lead To Opportunity' - + def action_cancel(self, cr, uid, ids, context=None): """ Closes Lead To Opportunity form @@ -38,7 +38,7 @@ class crm_lead2opportunity(osv.osv_memory): """ return {'type': 'ir.actions.act_window_close'} - + def action_apply(self, cr, uid, ids, context=None): """ This converts lead to opportunity and opens Opportunity view @@ -71,11 +71,11 @@ class crm_lead2opportunity(osv.osv_memory): for this in self.browse(cr, uid, ids, context=context): vals ={ - 'planned_revenue': this.planned_revenue, + 'planned_revenue': this.planned_revenue, 'probability': this.probability, - 'name': this.name, - 'partner_id': this.partner_id.id, - 'user_id': (this.partner_id.user_id and this.partner_id.user_id.id) or (lead.user_id and lead.user_id.id), + 'name': this.name, + 'partner_id': this.partner_id.id, + 'user_id': (this.partner_id.user_id and this.partner_id.user_id.id) or (lead.user_id and lead.user_id.id), 'type': 'opportunity' } lead_obj.write(cr, uid, lead.id, vals, context=context) @@ -86,26 +86,26 @@ class crm_lead2opportunity(osv.osv_memory): message = _('Lead ') + " '" + lead.name + "' "+ _("is converted to Opportunity.") self.log(cr, uid, lead.id, message) value = { - 'name': _('Opportunity'), - 'view_type': 'form', - 'view_mode': 'form,tree', - 'res_model': 'crm.lead', - 'domain': [('type', '=', 'opportunity')], - 'res_id': int(lead.id), - 'view_id': False, - 'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')], - 'type': 'ir.actions.act_window', + 'name': _('Opportunity'), + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.lead', + 'domain': [('type', '=', 'opportunity')], + 'res_id': int(lead.id), + 'view_id': False, + 'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')], + 'type': 'ir.actions.act_window', 'search_view_id': res['res_id'] } return value _columns = { - 'name' : fields.char('Opportunity', size=64, required=True, select=1), - 'probability': fields.float('Success Rate (%)'), - 'planned_revenue': fields.float('Expected Revenue'), - 'partner_id': fields.many2one('res.partner', 'Partner'), + 'name' : fields.char('Opportunity', size=64, required=True, select=1), + 'probability': fields.float('Success Rate (%)'), + 'planned_revenue': fields.float('Expected Revenue'), + 'partner_id': fields.many2one('res.partner', 'Partner'), } - + def view_init(self, cr, uid, fields, context=None): """ This function checks for precondition before wizard executes @@ -154,8 +154,8 @@ class crm_lead2opportunity_partner(osv.osv_memory): _inherit = 'crm.lead2partner' _columns = { - 'partner_id': fields.many2one('res.partner', 'Partner'), - 'action': fields.selection([('exist', 'Link to an existing partner'), ('create', 'Create a new partner'), ('no','Do not create a partner')], 'Action'), + 'partner_id': fields.many2one('res.partner', 'Partner'), + 'action': fields.selection([('exist', 'Link to an existing partner'), ('create', 'Create a new partner'), ('no','Do not create a partner')], 'Action'), } def make_partner(self, cr, uid, ids, context=None): @@ -171,7 +171,7 @@ class crm_lead2opportunity_partner(osv.osv_memory): """ if not context: context = {} - + partner_ids = self._create_partner(cr, uid, ids, context) value = {} data_obj = self.pool.get('ir.model.data') @@ -179,18 +179,18 @@ class crm_lead2opportunity_partner(osv.osv_memory): view_id = False if data_id: view_id = data_obj.browse(cr, uid, data_id, context=context).res_id - + context.update({'partner_id': partner_ids}) - value = { - 'name': _('Create Opportunity'), - 'view_type': 'form', - 'view_mode': 'form,tree', - 'res_model': 'crm.lead2opportunity.action', - 'view_id': False, - 'context': context, - 'views': [(view_id, 'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', + value = { + 'name': _('Create Opportunity'), + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.lead2opportunity.action', + 'view_id': False, + 'context': context, + 'views': [(view_id, 'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', } return value @@ -213,19 +213,19 @@ class crm_lead2opportunity_partner(osv.osv_memory): view_id = data_obj.browse(cr, uid, data_id, context=context).res_id context.update({'partner_id': False}) - 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', + 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', } return value - + def view_init(self, cr, uid, fields, context=None): """ @@ -278,30 +278,30 @@ class crm_lead2opportunity_action(osv.osv_memory): if data_id: view_id = data_obj.browse(cr, uid, data_id, context=context).res_id 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', + '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', } elif this.name == 'merge': data_id = data_obj._get_id(cr, uid, 'crm', 'merge_opportunity_form') if data_id: view_id = data_obj.browse(cr, uid, data_id, context=context).res_id value = { - 'name': _('Merge with Existing Opportunity'), - 'view_type': 'form', - 'view_mode': 'form,tree', - 'res_model': 'crm.merge.opportunity', - 'view_id': False, - 'context': context, - 'views': [(view_id, 'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', + 'name': _('Merge with Existing Opportunity'), + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.merge.opportunity', + 'view_id': False, + 'context': context, + 'views': [(view_id, 'form')], + 'type': 'ir.actions.act_window', + 'target': 'new', } return value From a814d8917596532c2e835f7752876b074eef0758 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:25:00 +0100 Subject: [PATCH 2/6] [IMP] crm: cleanup doc of crm_lead2opportunity.action_apply, remove unneeded temp variable bzr revid: xmo@openerp.com-20101108142500-zulaa5xpd7rvad3c --- addons/crm/wizard/crm_lead_to_opportunity.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index c84c7f3ba11..706ac30249f 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -42,15 +42,11 @@ class crm_lead2opportunity(osv.osv_memory): def action_apply(self, cr, uid, ids, context=None): """ This converts lead to opportunity and opens Opportunity view - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param ids: List of Lead to Opportunity IDs - @param context: A standard dictionary for contextual values + @param ids: ids of the leads to convert to opportunities - @return : Dictionary value for created Opportunity form + @return : View dictionary opening the Opportunity form view """ - record_id = context and context.get('active_id', False) or False + record_id = context and context.get('active_id') or False if not record_id: return {} @@ -85,7 +81,7 @@ class crm_lead2opportunity(osv.osv_memory): self.pool.get('mailgate.message').write(cr, uid, msg_ids, {'partner_id': lead.partner_id.id}, context=context) message = _('Lead ') + " '" + lead.name + "' "+ _("is converted to Opportunity.") self.log(cr, uid, lead.id, message) - value = { + return { 'name': _('Opportunity'), 'view_type': 'form', 'view_mode': 'form,tree', @@ -97,7 +93,6 @@ class crm_lead2opportunity(osv.osv_memory): 'type': 'ir.actions.act_window', 'search_view_id': res['res_id'] } - return value _columns = { 'name' : fields.char('Opportunity', size=64, required=True, select=1), From b0baf241a81728450bec0b37b3dd55c993915e6a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:31:16 +0100 Subject: [PATCH 3/6] [IMP] crm: use clearer names in crm_lead2opportunity.action_apply bzr revid: xmo@openerp.com-20101108143116-s38iw3o71yqvjt8n --- addons/crm/wizard/crm_lead_to_opportunity.py | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 706ac30249f..31c97c585d2 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -55,13 +55,18 @@ class crm_lead2opportunity(osv.osv_memory): # Get Opportunity views result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter') - res = data_obj.read(cr, uid, result, ['res_id']) - id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor') - id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor') - if id2: - id2 = data_obj.browse(cr, uid, id2, context=context).res_id - if id3: - id3 = data_obj.browse(cr, uid, id3, context=context).res_id + opportunity_view_search = data_obj.browse( + cr, uid, result, context=context) + opportunity_view_form = data_obj._get_id( + cr, uid, 'crm', 'crm_case_form_view_oppor') + opportunity_view_tree = data_obj._get_id( + cr, uid, 'crm', 'crm_case_tree_view_oppor') + if opportunity_view_form: + opportunity_view_form = data_obj.browse( + cr, uid, opportunity_view_form, context=context).res_id + if opportunity_view_tree: + opportunity_view_tree = data_obj.browse( + cr, uid, opportunity_view_tree, context=context).res_id lead = lead_obj.browse(cr, uid, record_id, context=context) @@ -81,6 +86,7 @@ class crm_lead2opportunity(osv.osv_memory): self.pool.get('mailgate.message').write(cr, uid, msg_ids, {'partner_id': lead.partner_id.id}, context=context) message = _('Lead ') + " '" + lead.name + "' "+ _("is converted to Opportunity.") self.log(cr, uid, lead.id, message) + return { 'name': _('Opportunity'), 'view_type': 'form', @@ -89,9 +95,11 @@ class crm_lead2opportunity(osv.osv_memory): 'domain': [('type', '=', 'opportunity')], 'res_id': int(lead.id), 'view_id': False, - 'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')], + 'views': [(opportunity_view_form, 'form'), + (opportunity_view_tree, 'tree'), + (False, 'calendar'), (False, 'graph')], 'type': 'ir.actions.act_window', - 'search_view_id': res['res_id'] + 'search_view_id': opportunity_view_search.res_id } _columns = { From e1bffa3cb8200394b685ead63dfc701eb50c2ae3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:38:21 +0100 Subject: [PATCH 4/6] [IMP] crm: better use of browse in crm_lead2opportunity.action_apply bzr revid: xmo@openerp.com-20101108143821-oy8f8ffg81m53f59 --- addons/crm/wizard/crm_lead_to_opportunity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 31c97c585d2..f3f7a4abb04 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -79,7 +79,7 @@ class crm_lead2opportunity(osv.osv_memory): 'user_id': (this.partner_id.user_id and this.partner_id.user_id.id) or (lead.user_id and lead.user_id.id), 'type': 'opportunity' } - lead_obj.write(cr, uid, lead.id, vals, context=context) + lead.write(vals, context=context) lead_obj.history(cr, uid, [lead], _('Opportunity'), details='Converted to Opportunity', context=context) if lead.partner_id: msg_ids = [ x.id for x in lead.message_ids] From 23f885ffc5c3bab65bfbcca3bb09792d3fcac367 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:41:20 +0100 Subject: [PATCH 5/6] [IMP] crm: further renamings for clarity in crm_lead2opportunity.action_apply, make management of opportunity view objects more uniform bzr revid: xmo@openerp.com-20101108144120-69qy918gw0zoywcz --- addons/crm/wizard/crm_lead_to_opportunity.py | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index f3f7a4abb04..f7e46efb75e 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -50,25 +50,25 @@ class crm_lead2opportunity(osv.osv_memory): if not record_id: return {} - lead_obj = self.pool.get('crm.lead') - data_obj = self.pool.get('ir.model.data') + leads = self.pool.get('crm.lead') + models_data = self.pool.get('ir.model.data') # Get Opportunity views - result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter') - opportunity_view_search = data_obj.browse( - cr, uid, result, context=context) - opportunity_view_form = data_obj._get_id( + result = models_data._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter') + opportunity_view_search = models_data.browse( + cr, uid, result, context=context).res_id + opportunity_view_form = models_data._get_id( cr, uid, 'crm', 'crm_case_form_view_oppor') - opportunity_view_tree = data_obj._get_id( + opportunity_view_tree = models_data._get_id( cr, uid, 'crm', 'crm_case_tree_view_oppor') if opportunity_view_form: - opportunity_view_form = data_obj.browse( + opportunity_view_form = models_data.browse( cr, uid, opportunity_view_form, context=context).res_id if opportunity_view_tree: - opportunity_view_tree = data_obj.browse( + opportunity_view_tree = models_data.browse( cr, uid, opportunity_view_tree, context=context).res_id - lead = lead_obj.browse(cr, uid, record_id, context=context) + lead = leads.browse(cr, uid, record_id, context=context) for this in self.browse(cr, uid, ids, context=context): vals ={ @@ -80,7 +80,7 @@ class crm_lead2opportunity(osv.osv_memory): 'type': 'opportunity' } lead.write(vals, context=context) - lead_obj.history(cr, uid, [lead], _('Opportunity'), details='Converted to Opportunity', context=context) + leads.history(cr, uid, [lead], _('Opportunity'), details='Converted to Opportunity', context=context) if lead.partner_id: msg_ids = [ x.id for x in lead.message_ids] self.pool.get('mailgate.message').write(cr, uid, msg_ids, {'partner_id': lead.partner_id.id}, context=context) @@ -99,7 +99,7 @@ class crm_lead2opportunity(osv.osv_memory): (opportunity_view_tree, 'tree'), (False, 'calendar'), (False, 'graph')], 'type': 'ir.actions.act_window', - 'search_view_id': opportunity_view_search.res_id + 'search_view_id': opportunity_view_search } _columns = { From 3f7d53142571ab445265947e89348b87077c94b8 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Nov 2010 15:45:27 +0100 Subject: [PATCH 6/6] [IMP] crm: wording of log item, management of formatting bzr revid: xmo@openerp.com-20101108144527-4auv4hjn87djjik2 --- addons/crm/wizard/crm_lead_to_opportunity.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index f7e46efb75e..4043adcfb37 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -54,7 +54,8 @@ class crm_lead2opportunity(osv.osv_memory): models_data = self.pool.get('ir.model.data') # Get Opportunity views - result = models_data._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter') + result = models_data._get_id( + cr, uid, 'crm', 'view_crm_case_opportunities_filter') opportunity_view_search = models_data.browse( cr, uid, result, context=context).res_id opportunity_view_form = models_data._get_id( @@ -83,9 +84,11 @@ class crm_lead2opportunity(osv.osv_memory): leads.history(cr, uid, [lead], _('Opportunity'), details='Converted to Opportunity', context=context) if lead.partner_id: msg_ids = [ x.id for x in lead.message_ids] - self.pool.get('mailgate.message').write(cr, uid, msg_ids, {'partner_id': lead.partner_id.id}, context=context) - message = _('Lead ') + " '" + lead.name + "' "+ _("is converted to Opportunity.") - self.log(cr, uid, lead.id, message) + self.pool.get('mailgate.message').write(cr, uid, msg_ids, { + 'partner_id': lead.partner_id.id + }, context=context) + self.log(cr, uid, lead.id, + _("Lead '%s' has been converted to an opportunity.") % lead.name) return { 'name': _('Opportunity'),