- hello world
+
+
+
Playground
+
+
+
Total increments:
+
+
-
+
diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py
index 98cb8c1302b..1b4283d4753 100644
--- a/estate/models/estate_property.py
+++ b/estate/models/estate_property.py
@@ -6,6 +6,15 @@ class Estate_property(models.Model):
_name = "estate.property"
_description = "APP super mega trop bien"
_order = "id desc"
+ _check_expected_price = models.Constraint(
+ "CHECK(expected_price > 0)",
+ message="The expected price must be strictly positive",
+ )
+
+ _check_selling_price = models.Constraint(
+ "CHECK(selling_price >= 0)",
+ message="The selling price cannot be negative",
+ )
name = fields.Char(required=True)
description = fields.Text()
@@ -39,21 +48,24 @@ class Estate_property(models.Model):
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
- total_area = fields.Integer(compute="_compute_area")
+ total_area = fields.Integer(compute="_compute_total_area")
best_price = fields.Float(compute="_compute_best_price")
- _check_expected_price = models.Constraint(
- "CHECK(expected_price > 0)",
- message="The expected price must be strictly positive",
- )
-
- _check_selling_price = models.Constraint(
- "CHECK(selling_price >= 0)",
- message="The selling price cannot be negative",
- )
+ @api.depends("offer_ids", "offer_ids.state")
+ def _compute_state(self):
+ for record in self:
+ if record.state in ["sold", "cancelled"]:
+ return
+ if record.offer_ids:
+ for offer in record.offer_ids:
+ if offer.state == "accepted":
+ record.state = "offer_accepted"
+ return
+ else:
+ record.state = "new"
@api.depends("living_area", "garden_area")
- def _compute_area(self):
+ def _compute_total_area(self):
for record in self:
record.total_area = record.living_area + record.garden_area
@@ -69,47 +81,42 @@ def _compute_best_price(self):
def _onchange_garden(self):
for record in self:
if record.garden:
- record.garden_area = 10
- record.garden_orientation = "north"
+ record.write({
+ "garden_area": 10,
+ "garden_orientation": "north",
+ })
else:
- record.garden_area = 0
- record.garden_orientation = False
+ record.write({
+ "garden_area": 0,
+ "garden_orientation": False,
+ })
- @api.depends("offer_ids", "offer_ids.state")
- def _compute_state(self):
+ @api.constrains("selling_price", "expected_price")
+ def _check_enough_selling_price(self):
for record in self:
- if record.state in ["sold", "cancelled"]:
- return
- if record.offer_ids:
- for offer in record.offer_ids:
- if offer.state == "accepted":
- record.state = "offer_accepted"
- break
- else:
- record.state = "new"
+ if record.selling_price and record.selling_price < record.expected_price * 0.9:
+ raise ValidationError("The selling price cannot be less than 90% of the expected price.")
+
+ @api.ondelete(at_uninstall=False)
+ def _ondelete_cancel_new(self):
+ for record in self:
+ if record.state not in ["new", "cancelled"]:
+ raise UserError("You can only delete offers that are new or cancelled.")
def action_sold(self):
for record in self:
if record.state != "cancelled" and record.state != "sold":
- record.state = "sold"
+ record.write({
+ "state": "sold",
+ })
else:
raise UserError("A property that is cancelled or already sold cannot be sold.")
def action_cancel(self):
for record in self:
if record.state != "sold" and record.state != "cancelled":
- record.state = "cancelled"
+ record.write({
+ "state": "cancelled",
+ })
else:
raise UserError("A property that is sold or already cancelled cannot be cancelled.")
-
- @api.constrains("selling_price", "expected_price")
- def _check_enough_selling_price(self):
- for record in self:
- if record.selling_price and record.selling_price < record.expected_price * 0.9:
- raise ValidationError("The selling price cannot be less than 90% of the expected price.")
-
- @api.ondelete(at_uninstall=False)
- def _ondelete_cancel_new(self):
- for record in self:
- if record.state not in ["new", "cancelled"]:
- raise UserError("You can only delete offers that are new or cancelled.")
diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py
index e156550797b..e7f02b70a25 100644
--- a/estate/models/estate_property_offer.py
+++ b/estate/models/estate_property_offer.py
@@ -27,13 +27,8 @@ class Estate_property_offer(models.Model):
@api.depends("validaty", "create_date")
def _compute_date_deadline(self):
for record in self:
- date = record.create_date
- if not date:
- date = fields.Date.today()
- if record.validaty:
- record.date_deadline = fields.Date.add(date, days=record.validaty)
- else:
- record.date_deadline = False
+ date = record.create_date.date() if record.create_date else fields.Date.today()
+ record.date_deadline = fields.Date.add(date, days=record.validaty)
def _inverse_date_deadline(self):
for record in self:
@@ -41,27 +36,30 @@ def _inverse_date_deadline(self):
create_date = fields.Date.to_date(record.create_date)
record.validaty = (record.date_deadline - create_date).days
else:
- record.validaty = 0
+ record.validaty = 7
def accept_offer(self):
for record in self:
if record.state == "accepted" or record.state == "refused":
raise UserError("This offer has already been accepted or refused.")
- for offer in record.property_id.offer_ids:
- if offer.state == "accepted":
- raise UserError("Another offer has already been accepted for this property.")
+ if "accepted" in record.mapped("property_id.offer_ids.state"):
+ raise UserError("Another offer has already been accepted for this property.")
if record.property_id.garden_orientation == "south" and record.price <= record.property_id.expected_price:
raise UserError("The price must be more than the expected price for properties with a south-facing garden.")
- record.state = "accepted"
- record.property_id.selling_price = record.price
- record.property_id.buyer_id = record.partner_id
+ record.write({
+ "state": "accepted",
+ "property_id": {
+ "selling_price": record.price,
+ "buyer_id": record.partner_id.id,
+ },
+ })
return True
def refuse_offer(self):
for record in self:
if record.state != "new":
raise UserError("This offer has already been accepted or refused.")
- record.state = "refused"
+ record.write({"state": "refused"})
return True
@api.model_create_multi
diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py
index 18f3a50c3e1..576617cccff 100644
--- a/estate/tests/__init__.py
+++ b/estate/tests/__init__.py
@@ -1 +1 @@
-from . import test_estate_property
\ No newline at end of file
+from . import test_estate_property
diff --git a/estate/tests/test_estate_property.py b/estate/tests/test_estate_property.py
index 7202f8b67a0..e17942089b1 100644
--- a/estate/tests/test_estate_property.py
+++ b/estate/tests/test_estate_property.py
@@ -34,6 +34,8 @@ def test_accept_offer_south_facing_garden(self):
price.
'''
self.estate.expected_price = 500000
+ self.estate.garden = True
+ self.estate.garden_orientation = 'south'
self.estate.offer_ids = [Command.create({
'price': 475000.0,
'partner_id': self.test_partner.id,