Skip to content

Commit d7fcbf0

Browse files
committed
[CLN] estate: Chapter 15
1 parent 020f915 commit d7fcbf0

14 files changed

+54
-113
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'views/estate_property_type_views.xml',
1111
'views/estate_property_tag_views.xml',
1212
'views/estate_res_user_views.xml',
13-
'views/estate_menus.xml',
13+
'views/estate_menu_views.xml',
1414
],
1515
'application': True,
1616
'author': 'Odoo S.A.',

estate/models/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from . import estate_properties
2-
from . import estate_property_offers
3-
from . import estate_property_tags
4-
from . import estate_property_types
1+
from . import estate_property
2+
from . import estate_property_offer
3+
from . import estate_property_tag
4+
from . import estate_property_type
55
from . import res_user

estate/models/estate_properties.py renamed to estate/models/estate_property.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import api, fields, models
1+
from odoo import api, fields, models, _
22
from odoo.exceptions import UserError, ValidationError
33
from odoo.tools import float_compare
44

@@ -10,21 +10,13 @@ class PropertyModel(models.Model):
1010
_name = "estate.property"
1111
_description = "Estate Property model"
1212
_order = "id desc"
13-
_check_positive_expected_price = models.Constraint(
14-
"CHECK(expected_price >= 0)",
15-
"The expected price must be positive."
16-
)
17-
_check_positive_selling_price = models.Constraint(
18-
"CHECK(selling_price >= 0)",
19-
"The selling price must be positive"
20-
)
2113

2214
name = fields.Char("Title", required=True)
2315
description = fields.Text()
2416
postcode = fields.Char()
2517
date_availability = fields.Date(default=fields.Date.add(fields.Date.today(), months=3), copy=False)
2618
expected_price = fields.Float(required=True)
27-
best_offer = fields.Float(compute="_get_highest_price")
19+
best_offer = fields.Float(compute="_compute_highest_price")
2820
selling_price = fields.Float(readonly=True, copy=False)
2921
bedrooms = fields.Integer(default=2)
3022
living_area = fields.Integer("Living Area (sqm)")
@@ -56,13 +48,22 @@ class PropertyModel(models.Model):
5648
tag_ids = fields.Many2many("estate.property.tag")
5749
offer_ids = fields.One2many("estate.property.offer", "property_id")
5850

51+
_check_positive_expected_price = models.Constraint(
52+
"CHECK(expected_price >= 0)",
53+
"The expected price must be positive."
54+
)
55+
_check_positive_selling_price = models.Constraint(
56+
"CHECK(selling_price >= 0)",
57+
"The selling price must be positive"
58+
)
59+
5960
@api.depends("living_area", "garden_area")
6061
def _compute_total_area(self):
6162
for record in self:
6263
record.total_living_area = record.living_area + record.garden_area
6364

6465
@api.depends("offer_ids")
65-
def _get_highest_price(self):
66+
def _compute_highest_price(self):
6667
for record in self:
6768
record.best_offer = max(record.offer_ids.mapped("price")) if record.offer_ids else 0
6869

@@ -75,27 +76,27 @@ def _onchange_garden(self):
7576
self.garden_area = 0
7677
self.garden_orientation = None
7778

78-
def mark_as_sold(self):
79+
@api.constrains("selling_price", "expected_price")
80+
def _check_selling_price(self):
81+
for record in self:
82+
if record.selling_price and float_compare(record.selling_price, record.expected_price * .9, 0) == -1:
83+
raise ValidationError("The selling price cannot be lower than 90% of the expected price.")
84+
85+
@api.ondelete(at_uninstall=False)
86+
def _unlink_if_new_or_cancelled(self):
87+
if any(record.state not in ('new', 'cancelled') for record in self):
88+
raise UserError(_("Only 'New' and 'Cancelled' properties can be deleted."))
89+
90+
def action_mark_as_sold(self):
7991
self.ensure_one()
8092
if self.state == "cancelled":
8193
raise UserError("A cancelled property cannot be set as sold.")
8294
self.state = "sold"
8395
return True
8496

85-
def mark_as_cancelled(self):
97+
def action_mark_as_cancelled(self):
8698
self.ensure_one()
8799
if self.state == "sold":
88-
raise UserError("A sold property cannot be set as cancelled.")
100+
raise UserError(_("A sold property cannot be set as cancelled."))
89101
self.state = "cancelled"
90102
return True
91-
92-
@api.constrains("selling_price", "expected_price")
93-
def _check_selling_price(self):
94-
for record in self:
95-
if record.selling_price and float_compare(record.selling_price, record.expected_price * .9, 0) == -1:
96-
raise ValidationError(r"The selling price cannot be lower than 90% of the expected price.")
97-
98-
@api.ondelete(at_uninstall=False)
99-
def _unlink_if_new_or_cancelled(self):
100-
if any(record.state not in ('new', 'cancelled') for record in self):
101-
raise UserError("Only 'New' and 'Cancelled' properties can be deleted.")

estate/models/estate_property_offers.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

estate/models/estate_property_tags.py renamed to estate/models/estate_property_tag.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ class PropertyTagModel(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag model"
77
_order = "name"
8+
9+
name = fields.Char(required=True)
10+
color = fields.Integer()
11+
812
_check_tag_uniqueness = models.Constraint(
913
"UNIQUE(name)",
1014
"Each tag should have a unique name."
1115
)
12-
13-
name = fields.Char(required=True)
14-
color = fields.Integer()

estate/models/estate_property_types.py renamed to estate/models/estate_property_type.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ class PropertyTypeModel(models.Model):
55
_name = "estate.property.type"
66
_description = "Estate Property Type model"
77
_order = "sequence"
8-
_check_type_uniqueness = models.Constraint(
9-
"UNIQUE(name)",
10-
"Each type should have a unique name."
11-
)
128

139
name = fields.Char(required=True)
1410
property_ids = fields.One2many("estate.property", "property_type_id")
1511
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
1612
offer_count = fields.Integer("Offer Count", compute="_compute_offer_count")
1713
sequence = fields.Integer("Sequence")
1814

15+
_check_type_uniqueness = models.Constraint(
16+
"UNIQUE(name)",
17+
"Each type should have a unique name."
18+
)
19+
1920
@api.depends("offer_ids")
2021
def _compute_offer_count(self):
2122
for record in self:

estate/models/res_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ class ResUser(models.Model):
55
_inherit = "res.users"
66

77
property_ids = fields.One2many(
8-
"estate.property", "salesperson_id", domain="['|', ('state', '=', 'new'), ('state', '=', 'received')]"
8+
"estate.property", "salesperson_id", domain=['|', ('state', '=', 'new'), ('state', '=', 'received')]
99
)
File renamed without changes.

estate/views/estate_property_offer_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<field name="domain">[('property_type_id', '=', active_id)]</field>
77
</record>
88

9-
<record id="estate_property_offer_list_view" model="ir.ui.view">
9+
<record id="estate_property_offer_view_list" model="ir.ui.view">
1010
<field name="name">estate.property.offer.list</field>
1111
<field name="model">estate.property.offer</field>
1212
<field name="arch" type="xml">
@@ -25,7 +25,7 @@
2525
</field>
2626
</record>
2727

28-
<record id="estate_property_offer_form_view" model="ir.ui.view">
28+
<record id="estate_property_offer_view_form" model="ir.ui.view">
2929
<field name="name">estate.property.offer.form</field>
3030
<field name="model">estate.property.offer</field>
3131
<field name="arch" type="xml">

estate/views/estate_property_tag_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<field name="view_mode">list,form</field>
66
</record>
77

8-
<record id="estate_property_tag_list_view" model="ir.ui.view">
8+
<record id="estate_property_tag_view_list" model="ir.ui.view">
99
<field name="name">estate.property.tag.list</field>
1010
<field name="model">estate.property.tag</field>
1111
<field name="arch" type="xml">

0 commit comments

Comments
 (0)