|
1 | 1 | from dateutil.relativedelta import relativedelta |
2 | 2 | from datetime import date |
| 3 | + |
3 | 4 | from odoo import models, fields, api |
4 | | -from odoo.exceptions import UserError,ValidationError |
5 | | -from odoo.tools.float_utils import float_compare, float_is_zero |
| 5 | +from odoo.exceptions import UserError, ValidationError |
| 6 | +from odoo.tools.float_utils import float_compare |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class EstateProperty(models.Model): |
9 | 10 | _name = "estate.property" |
10 | 11 | _description = "Real Estate Property" |
| 12 | + _order = "id desc" |
11 | 13 |
|
12 | 14 | name = fields.Char(required=True) |
13 | 15 | description = fields.Text() |
14 | 16 | postcode = fields.Char() |
15 | 17 | date_availability = fields.Date( |
16 | | - default=lambda sself: date.today() + relativedelta(months=3), |
| 18 | + default=lambda self: date.today() + relativedelta(months=3), |
17 | 19 | copy=False |
18 | 20 | ) |
19 | | - expected_price = fields.Float(string="Expected Price", required=True) |
| 21 | + expected_price = fields.Float(required=True) |
20 | 22 | selling_price = fields.Float( |
21 | 23 | readonly=True, |
22 | 24 | copy=False |
@@ -101,28 +103,27 @@ def _onchange_garden(self): |
101 | 103 | self.garden_area = 0 |
102 | 104 | self.garden_orientation = None |
103 | 105 |
|
104 | | - def action_cancel(self): |
105 | | - for rec in self: |
106 | | - if rec.state == "sold": |
107 | | - raise UserError("Sold properties cannot be cancelled.") |
108 | | - else: |
109 | | - rec.state = "cancelled" |
| 106 | + def action_cancel_property(self): |
| 107 | + if self.filtered(lambda rec: rec.state == "sold"): |
| 108 | + raise exceptions.UserError(_("Sold properties cannot be cancelled.")) |
| 109 | + self.write({"state": "cancelled"}) |
110 | 110 | return True |
111 | 111 |
|
112 | 112 | def action_set_sold(self): |
113 | 113 | for rec in self: |
114 | 114 | if rec.state == "cancelled": |
115 | | - raise UserError("Canceled properties cannot be sold.") |
| 115 | + raise exceptions.UserError(_("Canceled properties cannot be sold.")) |
116 | 116 | else: |
117 | 117 | rec.state = "sold" |
118 | 118 | return True |
| 119 | + |
119 | 120 | @api.constrains("selling_price", "expected_price") |
120 | 121 | def _check_selling_price(self): |
121 | | - for rec in self: |
| 122 | + for rec in self: |
122 | 123 | if rec.selling_price == 0: |
123 | 124 | return False |
124 | 125 | if float_compare(rec.selling_price, rec.expected_price * 0.9, precision_digits=2) < 0: |
125 | | - raise ValidationError( |
| 126 | + raise exceptions.ValidationError(_( |
126 | 127 | "The selling price must be at least 90% of the expected price!\n" |
127 | 128 | "You must reduce the expected price if you want to accept this offer." |
128 | | - ) |
| 129 | + )) |
0 commit comments