Skip to content

Commit 4d76898

Browse files
committed
[IMP] Real Estate: Added some constraints to the price
1 parent 03a702a commit 4d76898

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

estate/models/estate_property.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _compute_property_livable(self):
9292
def _compute_best_offer(self):
9393
for property in self:
9494
property.best_offer = max([0, *property.offer_ids.mapped("translated_price")])
95-
95+
9696
def action_set_as_cancelled(self):
9797
for property in self:
9898
if property.stage in ["sold", "cancelled"]:
@@ -126,3 +126,13 @@ def action_set_as_sold(self):
126126
'CHECK(total_area >= 0)',
127127
'The total area can\'t be negative.',
128128
)
129+
130+
_check_expected_price = models.Constraint(
131+
'CHECK(expecting_price > 0)',
132+
'The expected price has to be stricly positive'
133+
)
134+
135+
_check_selling_price = models.Constraint(
136+
'CHECK(selling_price >= 0)',
137+
'The selling price has to be stricly positive'
138+
)

estate/models/estate_property_offer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class PropertyOffer(models.Model):
1010
property_id = fields.Many2one("estate.property", string="Property", required=True)
1111
partner_id = fields.Many2one("res.partner", string="Partner", index=True, required=True)
1212

13-
1413
# Beginning of the deadline part
1514
def _current_date(self):
1615
return fields.Date.today()
@@ -35,7 +34,6 @@ def _inverse_validity(self):
3534

3635
# End of the deadline part
3736

38-
3937
# Beginning of the currency part
4038
currency_id = fields.Many2one("res.currency", "Currency")
4139
property_currency_id = fields.Many2one("res.currency", "Partner Currency", compute="_compute_property_currency_id")
@@ -63,7 +61,6 @@ def _compute_property_currency_id(self):
6361

6462
# End of the currency part
6563

66-
6764
# Beginning of the state / validation part
6865
status = fields.Selection([
6966
("accepted", "Accepted"),
@@ -82,8 +79,12 @@ def action_confirm(self):
8279
def action_refuse(self):
8380
for offer in self:
8481
offer.status = "refused"
85-
86-
# End of the state / validation part
8782

83+
# End of the state / validation part
8884

8985
sequence = fields.Integer("Sequence", default=0)
86+
87+
_check_price = models.Constraint(
88+
'CHECK(price > 0)',
89+
'The price has to be stricly positive'
90+
)

estate/models/estate_tag.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ def _default_color(self):
3838
color = fields.Integer(
3939
string='Color Index', default=lambda self: self._default_color(),
4040
help='Tag color. No color means no display in kanban or front-end, to distinguish internal tags from public categorization tags.')
41+
42+
_unique_name = models.Constraint(
43+
'UNIQUE(name)',
44+
'The tag name has to be unique',
45+
)

0 commit comments

Comments
 (0)