| 1 | from odoo.addons.crm.tests.common import TestCrmCommon |
| 2 | from odoo.tests import tagged, users |
| 3 | |
| 4 | |
| 5 | @tagged('res_partner', 'post_install', '-at_install') |
| 6 | class TestResPartner(TestCrmCommon): |
| 7 | |
| 8 | @classmethod |
| 9 | def setUpClass(cls): |
| 10 | super().setUpClass() |
| 11 | cls.contact_1_1, cls.contact_1_2 = cls.env['res.partner'].create([ |
| 12 | { |
| 13 | 'name': 'Philip J Fry Bouffe-tĂȘte', |
| 14 | 'email': '[email protected]', |
| 15 | 'function': 'Bouffe-TĂȘte', |
| 16 | 'lang': cls.lang_en.code, |
| 17 | 'phone': False, |
| 18 | 'parent_id': cls.contact_1.id, |
| 19 | 'is_company': False, |
| 20 | 'street': 'Same as Fry', |
| 21 | 'city': 'New York', |
| 22 | 'country_id': cls.env.ref('base.us').id, |
| 23 | 'zip': '54321', |
| 24 | }, { |
| 25 | 'name': 'Philip J Fry Banjo', |
| 26 | 'email': '[email protected]', |
| 27 | 'function': 'Being a banjo', |
| 28 | 'lang': cls.lang_en.code, |
| 29 | 'phone': False, |
| 30 | 'parent_id': cls.contact_1.id, |
| 31 | 'is_company': False, |
| 32 | 'street': 'Same as Fry', |
| 33 | 'city': 'New York', |
| 34 | 'country_id': cls.env.ref('base.us').id, |
| 35 | 'zip': '54321', |
| 36 | } |
| 37 | ]) |
| 38 | |
| 39 | cls.test_product = cls.env['product.template'].create({ |
| 40 | 'list_price': 100.0, |
| 41 | 'name': 'Test product1', |
| 42 | }) |
| 43 | cls.test_pricelist = cls.env['product.pricelist'].create({ |
| 44 | 'currency_id': cls.env.ref('base.USD').id, |
| 45 | 'name': 'My', |
| 46 | }) |
| 47 | |
| 48 | cls.test_leads = cls.env['crm.lead'].create([ |
| 49 | { |
| 50 | 'name': 'CompanyLead', |
| 51 | 'type': 'lead', |
| 52 | 'partner_id': cls.contact_company_1.id, |
| 53 | }, { |
| 54 | 'name': 'ChildLead', |
| 55 | 'type': 'lead', |
| 56 | 'partner_id': cls.contact_1.id, |
| 57 | }, { |
| 58 | 'name': 'GrandChildLead', |
| 59 | 'type': 'lead', |
| 60 | 'partner_id': cls.contact_1_1.id, |
| 61 | }, { |
| 62 | 'name': 'GrandChildOpp', |
| 63 | 'type': 'opportunity', |
| 64 | 'partner_id': cls.contact_1_1.id, |
| 65 | }, { |
| 66 | 'name': 'Nobody', |
| 67 | 'type': 'opportunity', |
| 68 | }, |
| 69 | ]) |
| 70 | |
| 71 | cls.test_so = cls.env['sale.order'].create([ |
| 72 | { |
| 73 | 'partner_id': cls.contact_company_1.id, |
| 74 | 'pricelist_id': cls.test_pricelist.id, |
| 75 | 'order_line': [ |
| 76 | (0, 0, { |
| 77 | 'product_id': cls.test_product.product_variant_id.id, |
| 78 | }) |
| 79 | ], |
| 80 | }, { |
| 81 | 'partner_id': cls.contact_1.id, |
| 82 | 'pricelist_id': cls.test_pricelist.id, |
| 83 | 'order_line': [ |
| 84 | (0, 0, { |
| 85 | 'product_id': cls.test_product.product_variant_id.id, |
| 86 | }) |
| 87 | ], |
| 88 | }, |
| 89 | ]) |
| 90 | |
| 91 | @users('user_sales_manager') |
| 92 | def test_application_stat_info(self): |
| 93 | ( |
| 94 | contact_company_1, contact_1, contact_1_1, contact_1_2 |
| 95 | ) = ( |
| 96 | self.contact_company_1 + self.contact_1 + self.contact_1_1 + self.contact_1_2 |
| 97 | ).with_env(self.env) |
| 98 | self.assertEqual(contact_company_1.opportunity_count, 4, 'Should contain own + children leads') |
| 99 | self.assertEqual(contact_1.opportunity_count, 3, 'Should contain own + child leads') |
| 100 | self.assertEqual(contact_1_1.opportunity_count, 2, 'Should contain own, aka 2') |
| 101 | self.assertEqual(contact_1_2.opportunity_count, 0, 'Should contain own, aka none') |
| 102 | |
| 103 | for partner, expected in zip( |
| 104 | (contact_company_1, contact_1, contact_1_1, contact_1_2), |
| 105 | ( |
| 106 | [{'iconClass': 'fa-star', 'label': 'Opportunities', 'value': 4, 'tagClass': 'o_tag_color_8'}, |
| 107 | {'iconClass': 'fa-usd', 'label': 'Sale Orders', 'value': 2, 'tagClass': 'o_tag_color_2'}], |
| 108 | [{'iconClass': 'fa-star', 'label': 'Opportunities', 'value': 3, 'tagClass': 'o_tag_color_8'}, |
| 109 | {'iconClass': 'fa-usd', 'label': 'Sale Orders', 'value': 1, 'tagClass': 'o_tag_color_2'}], |
| 110 | [{'iconClass': 'fa-star', 'label': 'Opportunities', 'value': 2, 'tagClass': 'o_tag_color_8'}], |
| 111 | False, |
| 112 | ), |
| 113 | strict=True, |
| 114 | ): |
| 115 | with self.subTest(pname=partner.name): |
| 116 | self.assertEqual(partner.application_statistics, expected) |