|
| 1 | +from odoo.exceptions import UserError |
| 2 | +from odoo.tests import Form, tagged |
| 3 | +from odoo.tests.common import TransactionCase |
| 4 | + |
| 5 | + |
| 6 | +@tagged('post_install', '-at_install') |
| 7 | +class EstateTestCase(TransactionCase): |
| 8 | + |
| 9 | + @classmethod |
| 10 | + def setUpClass(cls): |
| 11 | + super().setUpClass() |
| 12 | + cls.partner = cls.env['res.partner'].create({ |
| 13 | + 'name': 'Test Partner', |
| 14 | + }) |
| 15 | + cls.properties = cls.env['estate.property'].create([ |
| 16 | + { |
| 17 | + 'name': 'Property 1', |
| 18 | + 'expected_price': 100, |
| 19 | + }, |
| 20 | + { |
| 21 | + 'name': 'Property 2', |
| 22 | + 'expected_price': 200, |
| 23 | + 'state': 'sold', |
| 24 | + }, |
| 25 | + { |
| 26 | + 'name': 'Property 3', |
| 27 | + 'expected_price': 300, |
| 28 | + 'state': 'sold', |
| 29 | + }, |
| 30 | + ]) |
| 31 | + |
| 32 | + cls.offer_partner = cls.env['res.partner'].create({ |
| 33 | + 'name': 'Test Partner', |
| 34 | + }) |
| 35 | + |
| 36 | + def test_cannot_create_offer_on_sold_property(self): |
| 37 | + """Test that we cannot create an offer on a sold property.""" |
| 38 | + self.properties[0].write({'state': 'sold'}) |
| 39 | + |
| 40 | + with self.assertRaises(UserError): |
| 41 | + self.env['estate.property.offer'].create([{ |
| 42 | + 'price': 300, |
| 43 | + 'partner_id': self.offer_partner.id, |
| 44 | + 'property_id': self.properties[0].id, |
| 45 | + }]) |
| 46 | + |
| 47 | + def test_cannot_sold_a_property_without_accepted_offer(self): |
| 48 | + """Test that we cannot sold a property without an accepted offer.""" |
| 49 | + |
| 50 | + # Add an offer but not accept it |
| 51 | + with self.assertRaises(UserError): |
| 52 | + self.env['estate.property.offer'].create([{ |
| 53 | + 'price': 300, |
| 54 | + 'partner_id': self.offer_partner.id, |
| 55 | + 'property_id': self.properties[1].id, |
| 56 | + }]) |
| 57 | + # Sold without any offer |
| 58 | + with self.assertRaises(UserError): |
| 59 | + self.properties[2].action_sold() |
| 60 | + |
| 61 | + def test_rest_garden_fields(self): |
| 62 | + """Test that the garden fields are reset when the garden field is set to False.""" |
| 63 | + property_record = self.properties[0] |
| 64 | + |
| 65 | + with Form(property_record) as property_form: |
| 66 | + property_form.garden = True |
| 67 | + self.assertEqual(property_record.garden_area, 10) |
| 68 | + self.assertEqual(property_record.garden_orientation, 'north') |
| 69 | + |
| 70 | + with Form(property_record) as property_form: |
| 71 | + property_form.garden = False |
| 72 | + self.assertEqual(property_record.garden_area, 0) |
| 73 | + self.assertFalse(property_record.garden_orientation) |
0 commit comments