|
| 1 | +from unittest.mock import MagicMock, patch |
| 2 | + |
| 3 | +from odoo import fields |
| 4 | +from odoo.tests.common import TransactionCase |
| 5 | + |
| 6 | + |
| 7 | +class PMTTest(TransactionCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.area_1 = cls.env["spp.area"].create( |
| 12 | + { |
| 13 | + "draft_name": "Area 1", |
| 14 | + } |
| 15 | + ) |
| 16 | + cls.registrant_1 = cls.env["res.partner"].create( |
| 17 | + { |
| 18 | + "family_name": "Butay", |
| 19 | + "given_name": "Red", |
| 20 | + "name": "Red Butay", |
| 21 | + "is_group": False, |
| 22 | + "is_registrant": True, |
| 23 | + "area_id": cls.area_1.id, |
| 24 | + } |
| 25 | + ) |
| 26 | + cls.group_1 = cls.env["res.partner"].create( |
| 27 | + { |
| 28 | + "name": "Group 1", |
| 29 | + "is_group": True, |
| 30 | + "is_registrant": True, |
| 31 | + "area_id": cls.area_1.id, |
| 32 | + } |
| 33 | + ) |
| 34 | + cls.group_membership_1 = cls.env["g2p.group.membership"].create( |
| 35 | + { |
| 36 | + "group": cls.group_1.id, |
| 37 | + "individual": cls.registrant_1.id, |
| 38 | + "start_date": fields.Datetime.now(), |
| 39 | + } |
| 40 | + ) |
| 41 | + |
| 42 | + def test_compute_area(self): |
| 43 | + self.registrant_1._compute_area() |
| 44 | + self.assertFalse(self.registrant_1.area_calc.id) |
| 45 | + |
| 46 | + self.group_1._compute_area() |
| 47 | + self.assertEqual(self.group_1.area_calc.id, self.area_1.id) |
| 48 | + |
| 49 | + def test_compute_score(self): |
| 50 | + self.group_1.compute_score("z_ind_grp_pmt_score") |
| 51 | + self.assertEqual(self.group_1.z_ind_grp_pmt_score, 0) |
| 52 | + |
| 53 | + @patch("odoo.addons.base.models.ir_model.IrModelFields.search") |
| 54 | + def test_compute_score_with_weight(self, mock_search): |
| 55 | + area_id = self.env["spp.fields.area"].create( |
| 56 | + { |
| 57 | + "name": self.area_1.id, |
| 58 | + "weight": 1.0, |
| 59 | + } |
| 60 | + ) |
| 61 | + self.registrant_1.z_ind_grp_num_individuals = 1 |
| 62 | + |
| 63 | + mock_fields = MagicMock() |
| 64 | + mock_fields.name = "z_ind_grp_num_individuals" |
| 65 | + mock_fields.with_weight = True |
| 66 | + mock_fields.target_type = "indv" |
| 67 | + mock_fields.area_ids = area_id |
| 68 | + mock_search.return_value = [mock_fields] |
| 69 | + |
| 70 | + self.group_1.compute_score("z_ind_grp_pmt_score") |
| 71 | + self.assertEqual(self.group_1.z_ind_grp_pmt_score, 1) |
0 commit comments