'Tests for Test Lead2opportunity Assign Salesmen'

def test_lead2opportunity_assign_salesmen(self):

    CrmLead2OpportunityPartnerMass = self.env['crm.lead2opportunity.partner.mass']
    LeadSaleman = self.env['crm.lead'].sudo(self.crm_salesman.id)
    default_stage_id = self.ref('crm.stage_lead1')
    test_res_user_01 = self.env['res.users'].create({'name': 'Test    user    A', 'login': 'tua@example.com', 'new_password': 'tua'})
    test_res_user_02 = self.env['res.users'].create({'name': 'Test    user    B', 'login': 'tub@example.com', 'new_password': 'tub'})
    test_res_user_03 = self.env['res.users'].create({'name': 'Test    user    C', 'login': 'tuc@example.com', 'new_password': 'tuc'})
    test_res_user_04 = self.env['res.users'].create({'name': 'Test    user    D', 'login': 'tud@example.com', 'new_password': 'tud'})
    test_crm_lead_01 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    1', 'email_from': 'Raoul    Grosbedon    <raoul@grosbedon.fr>', 'stage_id': default_stage_id})
    test_crm_lead_02 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    2', 'email_from': 'Raoul    Grosbedon    <raoul@grosbedon.fr>', 'stage_id': default_stage_id})
    test_crm_lead_03 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    3', 'email_from': 'Raoul    Grosbedon    <raoul@grosbedon.fr>', 'stage_id': default_stage_id})
    test_crm_lead_04 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    4', 'email_from': 'Fabrice    Lepoilu', 'stage_id': default_stage_id})
    test_crm_lead_05 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    5', 'email_from': 'Fabrice    Lepoilu', 'stage_id': default_stage_id})
    test_crm_lead_06 = LeadSaleman.create({'type': 'lead', 'name': 'Test    lead    6', 'email_from': 'Agrolait    SuperSeed    SA', 'stage_id': default_stage_id})
    lead_ids = [test_crm_lead_01.id, test_crm_lead_02.id, test_crm_lead_03.id, test_crm_lead_04.id, test_crm_lead_05.id, test_crm_lead_06.id]
    salesmen_ids = [test_res_user_01.id, test_res_user_02.id, test_res_user_03.id, test_res_user_04.id]
    additionnal_context = {'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': test_crm_lead_01.id}
    mass = CrmLead2OpportunityPartnerMass.sudo(self.crm_salesman.id).with_context(**additionnal_context).create({'user_ids': [(6, 0, salesmen_ids)], 'team_id': self.env.ref('sales_team.team_sales_department').id, 'deduplicate': False, 'force_assignation': True})
    mass.sudo(self.crm_salesman.id).mass_convert()
    opps = self.env['crm.lead'].sudo(self.crm_salesman.id).browse(lead_ids)
    i = 0
    for opp in opps:
        self.assertEqual(opp.type, 'opportunity', 'Type    mismatch:    this    should    be    an    opp,    not    a    lead')
        self.assertEqual(opp.user_id.id, salesmen_ids[i], ('Salesman    mismatch:    expected    salesman    %r,    got    %r' % (salesmen_ids[i], opp.user_id.id)))
        i = ((i + 1) if (i < (len(salesmen_ids) - 1)) else 0)
