diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 75eaf753009..8a8b596ffbb 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -600,7 +600,6 @@ class crm_lead(base_stage, format_address, osv.osv): first_opportunity = opportunities_list[0] tail_opportunities = opportunities_list[1:] - # Define fields to merge and process to the merge fields_to_merge = ['partner_id', 'title', 'name', 'categ_ids', 'channel_id', 'city', 'company_id', 'contact_name', 'country_id', 'type_id', 'user_id', 'section_id', 'state_id', 'description', 'email', 'fax', 'mobile', 'partner_name', 'phone', 'probability', 'planned_revenue', 'street', 'street2', 'zip', 'create_date', 'date_action_last', 'date_action_next', 'email_from', 'email_cc', 'partner_name'] diff --git a/addons/crm/test/process/merge_opportunity.yml b/addons/crm/test/process/merge_opportunity.yml index 13843c054c1..30778c8c866 100644 --- a/addons/crm/test/process/merge_opportunity.yml +++ b/addons/crm/test/process/merge_opportunity.yml @@ -1,100 +1,113 @@ + - - I create two leads (with the same partner). + I want to see how are processed leads and opps fields when they get merged. I start by creating two leads and an opp. - !record {model: crm.lead, id: test_crm_lead_01}: type: 'lead' name: 'Test lead 1' partner_id: base.res_partner_1 stage_id: stage_lead1 + description: This is the description of the test lead 1. - !record {model: crm.lead, id: test_crm_lead_02}: type: 'lead' name: 'Test lead 2' - partner_id: base.res_partner_1 + partner_id: base.res_partner_3 stage_id: stage_lead1 -- - !python {model: crm.lead}: | - lead_ids = [ref('test_crm_lead_01'), ref('test_crm_lead_02')] - context.update({'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}) -- - I create a merge wizard and merge the leads together. -- - !record {model: crm.merge.opportunity, id: merge_opp_wizard_01}: -- - !python {model: crm.merge.opportunity}: | - self.action_merge(cr, uid, [ref("merge_opp_wizard_01")], context=context) -- - I check for the resulting merged lead (based on name and partner). -- - !python {model: crm.lead}: | - merge_id = self.search(cr, uid, [('name', '=', 'Test lead 1'), ('partner_id','=', ref("base.res_partner_1"))]) - assert merge_id, 'Fail to create merge opportunity wizard' - merge_result = self.browse(cr, uid, merge_id)[0] - assert merge_result.partner_id.id == ref("base.res_partner_1"), 'Partner mismatch' - assert merge_result.type == 'lead', 'Type mismatch: when leads get merged together, the result should be a new lead (instead of %s)' % merge_result.type -- - I create two opportunities (with the same partner). + description: This is the description of the test lead 2. - !record {model: crm.lead, id: test_crm_opp_01}: type: 'opportunity' name: 'Test opportunity 1' partner_id: base.res_partner_5 stage_id: stage_lead1 + description: This is the description of the test opp 1. +- + !python {model: crm.lead}: | + lead_ids = [ref('test_crm_lead_01'), ref('test_crm_lead_02'), ref('test_crm_opp_01')] + context.update({'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}) +- + I create a merge wizard and merge the leads and opp together in the first item of the list. +- + !record {model: crm.merge.opportunity, id: merge_opp_wizard_01}: +- + !python {model: crm.merge.opportunity}: | + self.action_merge(cr, uid, [ref("merge_opp_wizard_01")], context=context) +- + I check for the resulting merged opp (based on name and partner). +- + !python {model: crm.lead}: | + merge_id = self.search(cr, uid, [('name', '=', 'Test lead 1'), ('partner_id','=', ref("base.res_partner_1"))]) + assert merge_id, 'Fail to create merge opportunity wizard' + merge_result = self.browse(cr, uid, merge_id)[0] + assert merge_result.partner_id.id == ref("base.res_partner_1"), 'Partner mismatch: when merging leads/opps with different m2o values, the first not null value prevails (the other are dropped)' + assert merge_result.description == 'This is the description of the test lead 1., This is the description of the test lead 2., This is the description of the test opp 1.', 'Description mismatch: when merging leads/opps with different text values, these values should get concatenated and separeted with ", "' + assert merge_result.type == 'opportunity', 'Type mismatch: when at least one opp in involved in the merge, the result should be a new opp (instead of %s)' % merge_result.type +- + The other (tailing) leads/opps shouldn't exist anymore. +- + !python {model: crm.lead}: | + tailing_lead = self.search(cr, uid, [('id', '=', ref('test_crm_lead_02'))]) + assert not tailing_lead, 'This tailing lead (id %s) should not exist anymore' % ref('test_crm_lead_02') + + tailing_opp = self.search(cr, uid, [('id', '=', ref('test_crm_opp_01'))]) + assert not tailing_opp, 'This tailing opp (id %s) should not exist anymore' % ref('test_crm_opp_01') +- + I want to test leads merge. I start by creating two leads (with the same partner). +- + !record {model: crm.lead, id: test_crm_lead_03}: + type: 'lead' + name: 'Test lead 3' + partner_id: base.res_partner_1 + stage_id: stage_lead1 +- + !record {model: crm.lead, id: test_crm_lead_04}: + type: 'lead' + name: 'Test lead 4' + partner_id: base.res_partner_1 + stage_id: stage_lead1 +- + !python {model: crm.lead}: | + lead_ids = [ref('test_crm_lead_03'), ref('test_crm_lead_04')] + context.update({'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}) +- + I create a merge wizard and merge the leads together. +- + !record {model: crm.merge.opportunity, id: merge_opp_wizard_02}: +- + !python {model: crm.merge.opportunity}: | + self.action_merge(cr, uid, [ref("merge_opp_wizard_02")], context=context) +- + I check for the resulting merged lead (based on name and partner). +- + !python {model: crm.lead}: | + merge_id = self.search(cr, uid, [('name', '=', 'Test lead 3'), ('partner_id','=', ref("base.res_partner_1"))]) + assert merge_id, 'Fail to create merge opportunity wizard' + merge_result = self.browse(cr, uid, merge_id)[0] + assert merge_result.partner_id.id == ref("base.res_partner_1"), 'Partner mismatch' + assert merge_result.type == 'lead', 'Type mismatch: when leads get merged together, the result should be a new lead (instead of %s)' % merge_result.type + tailing_lead = self.search(cr, uid, [('id', '=', ref('test_crm_lead_04'))]) + assert not tailing_lead, 'This tailing lead (id %s) should not exist anymore' % ref('test_crm_lead_04') +- + I want to test opps merge. I start by creating two opportunities (with the same partner). - !record {model: crm.lead, id: test_crm_opp_02}: type: 'opportunity' name: 'Test opportunity 2' partner_id: base.res_partner_5 stage_id: stage_lead1 -- - !python {model: crm.lead}: | - opp_ids = [ref('test_crm_opp_01'), ref('test_crm_opp_02')] - context.update({'active_model': 'crm.lead', 'active_ids': opp_ids, 'active_id': opp_ids[0]}) -- - I create a merge wizard and merge the opps together. -- - !record {model: crm.merge.opportunity, id: merge_opp_wizard_02}: -- - !python {model: crm.merge.opportunity}: | - self.action_merge(cr, uid, [ref("merge_opp_wizard_02")], context=context) -- - I check for the resulting merged opp (based on name and partner). -- - !python {model: crm.lead}: | - merge_id = self.search(cr, uid, [('name', '=', 'Test opportunity 1'), ('partner_id','=', ref("base.res_partner_5"))]) - assert merge_id, 'Fail to create merge opportunity wizard' - merge_result = self.browse(cr, uid, merge_id)[0] - assert merge_result.partner_id.id == ref("base.res_partner_5"), 'Partner mismatch' - assert merge_result.type == 'opportunity', 'Type mismatch: when opps get merged together, the result should be a new opp (instead of %s)' % merge_result.type -- - I create two leads and one opportunity (with different data). -- - !record {model: crm.lead, id: test_crm_lead_03}: - type: 'lead' - name: 'Test lead 3' - partner_id: base.res_partner_1 - stage_id: stage_lead1 - description: This is the description of the test lead 3. -- - !record {model: crm.lead, id: test_crm_lead_04}: - type: 'lead' - name: 'Test lead 4' - partner_id: base.res_partner_3 - stage_id: stage_lead1 - description: This is the description of the test lead 4. - !record {model: crm.lead, id: test_crm_opp_03}: type: 'opportunity' name: 'Test opportunity 3' partner_id: base.res_partner_5 stage_id: stage_lead1 - description: This is the description of the test opp 3. - !python {model: crm.lead}: | - lead_ids = [ref('test_crm_lead_03'), ref('test_crm_lead_04'), ref('test_crm_opp_03')] - context.update({'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}) + opp_ids = [ref('test_crm_opp_02'), ref('test_crm_opp_03')] + context.update({'active_model': 'crm.lead', 'active_ids': opp_ids, 'active_id': opp_ids[0]}) - - I create a merge wizard and merge the leads and opp together. + I create a merge wizard and merge the opps together. - !record {model: crm.merge.opportunity, id: merge_opp_wizard_03}: - @@ -104,9 +117,10 @@ I check for the resulting merged opp (based on name and partner). - !python {model: crm.lead}: | - merge_id = self.search(cr, uid, [('name', '=', 'Test lead 3'), ('partner_id','=', ref("base.res_partner_1"))]) + merge_id = self.search(cr, uid, [('name', '=', 'Test opportunity 2'), ('partner_id','=', ref("base.res_partner_5"))]) assert merge_id, 'Fail to create merge opportunity wizard' merge_result = self.browse(cr, uid, merge_id)[0] - assert merge_result.partner_id.id == ref("base.res_partner_1"), 'Partner mismatch: when merging leads/opps with different m2o values, the first not null value prevails (the other are dropped)' - assert merge_result.description == 'This is the description of the test lead 3., This is the description of the test lead 4., This is the description of the test opp 3.', 'Description mismatch: when merging leads/opps with different text values, these values should get concatenated and separeted with ", "' - assert merge_result.type == 'opportunity', 'Type mismatch: when at least one opp in involved in the merge, the result should be a new opp (instead of %s)' % merge_result.type \ No newline at end of file + assert merge_result.partner_id.id == ref("base.res_partner_5"), 'Partner mismatch' + assert merge_result.type == 'opportunity', 'Type mismatch: when opps get merged together, the result should be a new opp (instead of %s)' % merge_result.type + tailing_opp = self.search(cr, uid, [('id', '=', ref('test_crm_opp_03'))]) + assert not tailing_opp, 'This tailing opp (id %s) should not exist anymore' % ref('test_crm_opp_03') \ No newline at end of file