|
| 1 | +from odoo.tests.common import TransactionCase |
| 2 | +from odoo.exceptions import UserError |
| 3 | +from odoo.tests import tagged, Form |
| 4 | + |
| 5 | + |
| 6 | +ADMINISTRATOR_ID = 3 |
| 7 | + |
| 8 | + |
| 9 | +@tagged("post_install", "-at_install") |
| 10 | +class EstateTestCase(TransactionCase): |
| 11 | + |
| 12 | + @classmethod |
| 13 | + def setUpClass(cls): |
| 14 | + super(EstateTestCase, cls).setUpClass() |
| 15 | + cls.new_property = cls.env["estate.property"].create([{ |
| 16 | + "name": "New Property", |
| 17 | + "state": "new", |
| 18 | + "expected_price": 1000.0 |
| 19 | + }]) |
| 20 | + cls.received_property = cls.env["estate.property"].create([{ |
| 21 | + "name": "Received offer Property", |
| 22 | + "state": "received", |
| 23 | + "expected_price": 2000.0 |
| 24 | + }]) |
| 25 | + cls.accepted_property = cls.env["estate.property"].create([{ |
| 26 | + "name": "Accepeted offer Property", |
| 27 | + "state": "accepted", |
| 28 | + "expected_price": 3000.0 |
| 29 | + }]) |
| 30 | + cls.create_sold_property() |
| 31 | + cls.cancelled_property = cls.env["estate.property"].create([{ |
| 32 | + "name": "Cancelled Property", |
| 33 | + "state": "cancelled", |
| 34 | + "expected_price": 5000.0 |
| 35 | + }]) |
| 36 | + cls.env["estate.property.offer"].create([ |
| 37 | + { |
| 38 | + "partner_id": ADMINISTRATOR_ID, |
| 39 | + "property_id": cls.accepted_property.id, |
| 40 | + "status": "accepted", |
| 41 | + "price": 3000.0 |
| 42 | + }, |
| 43 | + { |
| 44 | + "partner_id": ADMINISTRATOR_ID, |
| 45 | + "property_id": cls.received_property.id, |
| 46 | + "status": "refused", |
| 47 | + "price": 1999.0 |
| 48 | + }, |
| 49 | + { |
| 50 | + "partner_id": ADMINISTRATOR_ID, |
| 51 | + "property_id": cls.received_property.id, |
| 52 | + "price": 2000.0 |
| 53 | + } |
| 54 | + ]) |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def create_sold_property(cls): |
| 58 | + cls.sold_property = cls.env["estate.property"].create([{ |
| 59 | + "name": "Sold Property", |
| 60 | + "state": "new", |
| 61 | + "expected_price": 4000.0 |
| 62 | + }]) |
| 63 | + cls.env["estate.property.offer"].create([{ |
| 64 | + "partner_id": ADMINISTRATOR_ID, |
| 65 | + "property_id": cls.sold_property.id, |
| 66 | + "status": "accepted", |
| 67 | + "price": 4000.0 |
| 68 | + }]) |
| 69 | + cls.sold_property.state = "sold" |
| 70 | + |
| 71 | + |
| 72 | + def test_offer_for_sold_property(self): |
| 73 | + offer_for_sold_property = { |
| 74 | + "partner_id": ADMINISTRATOR_ID, |
| 75 | + "property_id": self.sold_property.id |
| 76 | + } |
| 77 | + correct_offers = [ |
| 78 | + {"partner_id": ADMINISTRATOR_ID, "property_id": self.new_property.id, "price": 1000}, |
| 79 | + {"partner_id": ADMINISTRATOR_ID, "property_id": self.received_property.id, "price": 2000}, |
| 80 | + {"partner_id": ADMINISTRATOR_ID, "property_id": self.accepted_property.id, "price": 3000}, |
| 81 | + {"partner_id": ADMINISTRATOR_ID, "property_id": self.cancelled_property.id, "price": 5000}, |
| 82 | + ] |
| 83 | + with self.assertRaises(UserError, msg="Creating an offer for a sold property should raise a UserError but it did not."): |
| 84 | + self.env["estate.property.offer"].create([offer_for_sold_property]) |
| 85 | + for offer in correct_offers: |
| 86 | + try: |
| 87 | + self.env["estate.property.offer"].create([offer]) |
| 88 | + except UserError: |
| 89 | + self.fail() |
| 90 | + |
| 91 | + def test_sell_property_with_no_accepted_offer(self): |
| 92 | + non_sellable_properties = [ |
| 93 | + self.new_property, |
| 94 | + self.received_property |
| 95 | + ] |
| 96 | + for property in non_sellable_properties: |
| 97 | + with self.assertRaises(UserError): |
| 98 | + property.action_mark_as_sold() |
| 99 | + self.accepted_property.action_mark_as_sold() |
| 100 | + |
| 101 | + def test_sold_state_correctly_set(self): |
| 102 | + self.accepted_property.mark_as_sold() |
| 103 | + self.assertEqual(self.accepted_property.state, "sold", "When a property is sold, its state should be set to 'sold'.") |
| 104 | + |
| 105 | + def test_garden_area_orientation_reset(self): |
| 106 | + property_form = Form(self.env["estate.property"]) |
| 107 | + self.assertFalse(property_form.garden) |
| 108 | + self.assertEqual(property_form.garden_area, 0) |
| 109 | + self.assertFalse(property_form.garden_orientation) |
| 110 | + property_form.garden = True |
| 111 | + self.assertTrue(property_form.garden) |
| 112 | + self.assertEqual(property_form.garden_area, 10) |
| 113 | + self.assertEqual(property_form.garden_orientation, "north") |
| 114 | + property_form.garden = False |
| 115 | + self.assertFalse(property_form.garden) |
| 116 | + self.assertEqual(property_form.garden_area, 0) |
| 117 | + self.assertFalse(property_form.garden_orientation) |
0 commit comments