5a750c94b72708a685d4cfdb2640d5a59e2696e8
[odoo/odoo.git] / addons / crm / test / lead2opportunity_assign_salesmen.yml
1 -
2   During a lead to opp conversion, salesmen should be assigned to leads following the round-robin method.  Start by creating 4 salesmen (A to D) and 6 leads (1 to 6).
3 -
4   !record {model: res.users, id: test_res_user_01}:
5     name: 'Test user A'
6     login: 'tua'
7     new_password: 'tua'
8 -
9   !record {model: res.users, id: test_res_user_02}:
10     name: 'Test user B'
11     login: 'tub'
12     new_password: 'tub'
13 -
14   !record {model: res.users, id: test_res_user_03}:
15     name: 'Test user C'
16     login: 'tuc'
17     new_password: 'tuc'
18 -
19   !record {model: res.users, id: test_res_user_04}:
20     name: 'Test user D'
21     login: 'tud'
22     new_password: 'tud'
23 -
24   Salesman also creates lead so giving access rights of salesman.
25 -
26   !context
27     uid: 'crm_res_users_salesman'
28 -
29   !record {model: crm.lead, id: test_crm_lead_01}:
30     type: 'lead'
31     name: 'Test lead 1'
32     email_from: 'Raoul Grosbedon <raoul@grosbedon.fr>'
33     stage_id: stage_lead1
34 -
35   !record {model: crm.lead, id: test_crm_lead_02}:
36     type: 'lead'
37     name: 'Test lead 2'
38     email_from: 'Raoul Grosbedon <raoul@grosbedon.fr>'
39     stage_id: stage_lead1
40 -
41   !record {model: crm.lead, id: test_crm_lead_03}:
42     type: 'lead'
43     name: 'Test lead 3'
44     email_from: 'Raoul Grosbedon <raoul@grosbedon.fr>'
45     stage_id: stage_lead1
46 -
47   !record {model: crm.lead, id: test_crm_lead_04}:
48     type: 'lead'
49     name: 'Test lead 4'
50     contact_name: 'Fabrice Lepoilu'
51     stage_id: stage_lead1
52 -
53   !record {model: crm.lead, id: test_crm_lead_05}:
54     type: 'lead'
55     name: 'Test lead 5'
56     contact_name: 'Fabrice Lepoilu'
57     stage_id: stage_lead1
58 -
59   !record {model: crm.lead, id: test_crm_lead_06}:
60     type: 'lead'
61     name: 'Test lead 6'
62     partner_name: 'Agrolait SuperSeed SA'
63     stage_id: stage_lead1
64 -
65   Salesman create a mass convert wizard and convert all the leads.
66 -
67   !python {model: crm.lead2opportunity.partner.mass}: |
68     context.update({'active_model': 'crm.lead', 'active_ids': [ref("test_crm_lead_01"), ref("test_crm_lead_02"), ref("test_crm_lead_03"), ref("test_crm_lead_04"), ref("test_crm_lead_05"), ref("test_crm_lead_06")], 'active_id': ref("test_crm_lead_01")})
69     id = self.create(cr, uid, {'user_ids': [(6, 0, [ref('test_res_user_01'), ref('test_res_user_02'), ref('test_res_user_03'), ref('test_res_user_04')])], 'section_id': ref('crm.section_sales_department')}, context=context)
70     self.mass_convert(cr, uid, [id], context=context)
71 -
72   The leads should now be opps with a salesman and a salesteam.  Also, salesmen should have been assigned following a round-robin method.
73 -
74   !python {model: crm.lead}: |
75     opps = self.browse(cr, uid, [ref("test_crm_lead_01"), ref("test_crm_lead_02"), ref("test_crm_lead_03"), ref("test_crm_lead_04"), ref("test_crm_lead_05"), ref("test_crm_lead_06")], context)
76     salesmen_ids = [ref('test_res_user_01'), ref('test_res_user_02'), ref('test_res_user_03'), ref('test_res_user_04')]
77     i = 0
78     for opp in opps:
79       assert opp.type == 'opportunity', 'Type mismatch: this should be an opp, not a lead'
80       assert opp.user_id.id == salesmen_ids[i], 'Salesman mismatch: expected salesman %r, got %r' % (salesmen_ids[i], opp.user_id.id)
81       i = i+1 if (i < len(salesmen_ids) - 1) else 0