Skip to content

Commit 0fd1b1d

Browse files
committed
[FIX] estate: use translation method for error messages
1 parent 90be6c6 commit 0fd1b1d

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

estate/models/estate_property.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2-
from odoo import api, fields, models
2+
from odoo import api, fields, models, _
33
from odoo.exceptions import UserError, ValidationError
44
from odoo.tools.float_utils import float_compare, float_is_zero
55

@@ -69,32 +69,27 @@ def _compute_garden_defaults(self) -> None:
6969
@api.ondelete(at_uninstall=False)
7070
def _unlink_except_new_or_cancelled(self) -> None:
7171
if any(record.state not in {"new", "cancelled"} for record in self):
72-
error_msg = "Cannot delete properties unless they are new or cancelled."
73-
raise UserError(error_msg)
72+
raise UserError(_("Cannot delete properties unless they are new or cancelled."))
7473

7574
# Public methods
7675
def action_set_sold(self) -> bool:
7776
for record in self:
7877
if record.state == "sold":
79-
error_msg = "This property has already been sold."
80-
raise UserError(error_msg)
78+
raise UserError(_("This property has already been sold."))
8179

8280
if record.state == "cancelled":
83-
error_msg = "Cancelled properties cannot be sold."
84-
raise UserError(error_msg)
81+
raise UserError(_("Cancelled properties cannot be sold."))
8582

8683
record.state = "sold"
8784
return True
8885

8986
def action_set_cancelled(self) -> bool:
9087
for record in self:
9188
if record.state == "sold":
92-
error_msg = "Sold properties cannot be cancelled."
93-
raise UserError(error_msg)
89+
raise UserError(_("Sold properties cannot be cancelled."))
9490

9591
if record.state == "cancelled":
96-
error_msg = "This property has already been cancelled."
97-
raise UserError(error_msg)
92+
raise UserError(_("This property has already been cancelled."))
9893

9994
record.state = "cancelled"
10095
return True
@@ -115,5 +110,4 @@ def _restrict_selling_price(self) -> None:
115110
for record in self:
116111
# Selling price is zero when no offer has been accepted
117112
if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) < 0:
118-
error_msg = "A property's selling price cannot be lower that 90 percent of its expected price."
119-
raise ValidationError(error_msg)
113+
raise ValidationError(_("A property's selling price cannot be lower that 90 percent of its expected price."))

estate/models/estate_property_offer.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date
22

33
from dateutil.relativedelta import relativedelta
4-
from odoo import api, fields, models
4+
from odoo import api, fields, models, _
55
from odoo.exceptions import UserError
66

77

@@ -40,8 +40,7 @@ def create(self, vals):
4040
for val in vals:
4141
estate_property = self.env["estate.property"].browse(val["property_id"])
4242
if val["price"] < estate_property.best_price:
43-
error_msg = f"Cannot create an offer with an price that's lower than the current best offer: {estate_property.best_price}"
44-
raise UserError(error_msg)
43+
raise UserError(_("A new offer must match or exceed the price of the current best offer."))
4544
estate_property.state = "offer_received"
4645
return super().create(vals)
4746

@@ -50,12 +49,10 @@ def action_accept(self) -> bool:
5049
# TODO validation
5150
for record in self:
5251
if record.status == "accepted":
53-
error_msg = "This offer has already been accepted."
54-
raise UserError(error_msg)
52+
raise UserError(_("This offer has already been accepted."))
5553

5654
if record.property_id.offer_ids.filtered(lambda r: r.status == "accepted"):
57-
error_msg = "Cannot accept this offer because another offer has already been accepted for the property."
58-
raise UserError(error_msg)
55+
raise UserError(_("Cannot accept this offer because another offer has already been accepted for the property."))
5956

6057
record.status = "accepted"
6158
record.property_id.selling_price = record.price

0 commit comments

Comments
 (0)