Skip to content

Commit 9dd3005

Browse files
committed
[FIX] estate: modernize usage of translation "_"
- It's recommended to call the translate "_" method on the environment. - The global "_" has some issues and might become deprecated at some point in the future.
1 parent d623609 commit 9dd3005

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

estate/models/estate_property.py

Lines changed: 5 additions & 5 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,7 +69,7 @@ def _onchange_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-
raise UserError(_("Cannot delete properties unless they are new or cancelled."))
72+
raise UserError(self.env._("Cannot delete properties unless they are new or cancelled."))
7373

7474
# Public methods
7575
def action_set_sold(self) -> bool:
@@ -78,7 +78,7 @@ def action_set_sold(self) -> bool:
7878
continue
7979

8080
if record.state == "cancelled":
81-
raise UserError(_("Cancelled properties cannot be sold."))
81+
raise UserError(record.env._("Cancelled properties cannot be sold."))
8282

8383
record.state = "sold"
8484
return True
@@ -89,7 +89,7 @@ def action_set_cancelled(self) -> bool:
8989
continue
9090

9191
if record.state == "sold":
92-
raise UserError(_("Sold properties cannot be cancelled."))
92+
raise UserError(record.env._("Sold properties cannot be cancelled."))
9393

9494
record.state = "cancelled"
9595
return True
@@ -110,4 +110,4 @@ def _restrict_selling_price(self) -> None:
110110
for record in self:
111111
# Selling price is zero when no offer has been accepted
112112
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:
113-
raise ValidationError(_("A property's selling price cannot be lower than 90 percent of its expected price."))
113+
raise ValidationError(record.env._("A property's selling price cannot be lower than 90 percent of its expected price."))

estate/models/estate_property_offer.py

Lines changed: 3 additions & 3 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
from odoo.tools.float_utils import float_compare
77

@@ -44,7 +44,7 @@ def create(self, vals):
4444
estate_property = self.env["estate.property"].browse(val["property_id"])
4545
best_price = estate_property.best_price or 0.0
4646
if float_compare(val["price"], best_price, precision_digits=2) < 0:
47-
raise UserError(_("A new offer must match or exceed the price of the current best offer."))
47+
raise UserError(self.env._("A new offer must match or exceed the price of the current best offer."))
4848
estate_property.state = "offer_received"
4949
return super().create(vals)
5050

@@ -53,7 +53,7 @@ def action_accept(self) -> bool:
5353
# TODO double check validation
5454
for record in self:
5555
if record.property_id.offer_ids.filtered(lambda r: r.status == "accepted"):
56-
raise UserError(_("Cannot accept this offer because another offer has already been accepted for the property."))
56+
raise UserError(record.env._("Cannot accept this offer because another offer has already been accepted for the property."))
5757

5858
record.status = "accepted"
5959
record.property_id.selling_price = record.price

0 commit comments

Comments
 (0)