|
| 1 | +from odoo.tests.common import TransactionCase |
| 2 | +from odoo.exceptions import UserError |
| 3 | +from odoo.tests import tagged |
| 4 | + |
| 5 | + |
| 6 | +@tagged('post_install', '-at_install') |
| 7 | +class EstateTestCase(TransactionCase): |
| 8 | + |
| 9 | + @classmethod |
| 10 | + def setUpClass(cls): |
| 11 | + super().setUpClass() |
| 12 | + |
| 13 | + cls.properties = cls.env['estate.property'].create([{ |
| 14 | + 'name': 'property 1', |
| 15 | + 'expected_price': 100, |
| 16 | + }]) |
| 17 | + |
| 18 | + cls.partner = cls.env['res.partner'].create([{ |
| 19 | + 'name': 'myCompany', |
| 20 | + }]) |
| 21 | + |
| 22 | + def test_sell_no_offer(self): |
| 23 | + Offer = self.env['estate.property.offer'].create([{ |
| 24 | + 'price': 92, |
| 25 | + 'property_id': self.properties.id, |
| 26 | + 'partner_id': self.partner.id, |
| 27 | + }]) |
| 28 | + |
| 29 | + self.properties.offer_ids = [Offer.id] |
| 30 | + |
| 31 | + with self.assertRaises(UserError): |
| 32 | + self.properties.action_sold() |
| 33 | + |
| 34 | + self.assertRecordValues(self.properties, [ |
| 35 | + {'state': 'Offer Received'}, |
| 36 | + ]) |
| 37 | + |
| 38 | + def test_offer_sold_property(self): |
| 39 | + Offer = self.env['estate.property.offer'].create([{ |
| 40 | + 'price': 93, |
| 41 | + 'property_id': self.properties.id, |
| 42 | + 'partner_id': self.partner.id, |
| 43 | + }]) |
| 44 | + |
| 45 | + self.properties.offer_ids = [Offer.id] |
| 46 | + Offer.action_accept() |
| 47 | + self.properties.action_sold() |
| 48 | + |
| 49 | + with self.assertRaises(UserError): |
| 50 | + self.env['estate.property.offer'].create([{ |
| 51 | + 'price': 94, |
| 52 | + 'property_id': self.properties.id, |
| 53 | + 'partner_id': self.partner.id, |
| 54 | + }]) |
| 55 | + |
| 56 | + self.assertEqual(len(self.properties.offer_ids), 1) |
0 commit comments