|
| 1 | +from odoo.tests.common import TransactionCase |
| 2 | +from odoo.tests import tagged, Form |
| 3 | +from odoo.exceptions import UserError |
| 4 | + |
| 5 | + |
| 6 | +@tagged("post_install", "-at_install") |
| 7 | +class TestEstateProperty(TransactionCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.property_type = cls.env["estate.property.type"].create( |
| 12 | + {"name": "House Test Type"} |
| 13 | + ) |
| 14 | + |
| 15 | + cls.properties = cls.env["estate.property"].create( |
| 16 | + [ |
| 17 | + { |
| 18 | + "name": "Sale Test Property", |
| 19 | + "description": "Test Description", |
| 20 | + "expected_price": 100000, |
| 21 | + "living_area": 50, |
| 22 | + "property_type_id": cls.property_type.id, |
| 23 | + }, |
| 24 | + { |
| 25 | + "name": "Garden Test Property", |
| 26 | + "description": "Test Description Garden", |
| 27 | + "expected_price": 200000, |
| 28 | + "living_area": 100, |
| 29 | + "property_type_id": cls.property_type.id, |
| 30 | + }, |
| 31 | + ] |
| 32 | + ) |
| 33 | + |
| 34 | + cls.offers = cls.env["estate.property.offer"].create( |
| 35 | + [ |
| 36 | + { |
| 37 | + "partner_id": cls.env.ref("base.res_partner_2").id, |
| 38 | + "price": 110000, |
| 39 | + "property_id": cls.properties[0].id, |
| 40 | + "validity": 7, |
| 41 | + }, |
| 42 | + { |
| 43 | + "partner_id": cls.env.ref("base.res_partner_12").id, |
| 44 | + "price": 130000, |
| 45 | + "property_id": cls.properties[0].id, |
| 46 | + "validity": 7, |
| 47 | + }, |
| 48 | + { |
| 49 | + "partner_id": cls.env.ref("base.res_partner_2").id, |
| 50 | + "price": 150000, |
| 51 | + "property_id": cls.properties[0].id, |
| 52 | + "validity": 7, |
| 53 | + }, |
| 54 | + ] |
| 55 | + ) |
| 56 | + |
| 57 | + def test_sell_property_without_accepted_offer(self): |
| 58 | + with self.assertRaises(UserError): |
| 59 | + self.properties[0].action_sell_property() |
| 60 | + |
| 61 | + def test_sold_property_cannot_create_offer(self): |
| 62 | + self.properties[0].write({"state": "offer_accepted"}) |
| 63 | + self.properties[0].action_sell_property() |
| 64 | + with self.assertRaises(UserError): |
| 65 | + self.env["estate.property.offer"].create( |
| 66 | + [ |
| 67 | + { |
| 68 | + "partner_id": self.env.ref("base.res_partner_2").id, |
| 69 | + "price": 110000, |
| 70 | + "property_id": self.properties[0].id, |
| 71 | + "validity": 7, |
| 72 | + }, |
| 73 | + ] |
| 74 | + ) |
| 75 | + |
| 76 | + def test_garden_toggle(self): |
| 77 | + with Form(self.properties[1]) as form: |
| 78 | + form.garden = True |
| 79 | + self.assertEqual(form.garden_area, 10, "Garden area should be reset to 10") |
| 80 | + self.assertEqual( |
| 81 | + form.garden_orientation, |
| 82 | + "north", |
| 83 | + "Garden orientation should be reset to north", |
| 84 | + ) |
| 85 | + form.garden = False |
| 86 | + self.assertEqual(form.garden_area, 0, "Garden area should be reset to 0") |
| 87 | + self.assertEqual( |
| 88 | + form.garden_orientation, |
| 89 | + False, |
| 90 | + "Garden orientation should be reset to False", |
| 91 | + ) |
0 commit comments