Skip to content

Commit 3cd43d1

Browse files
[FIX] estate: prevent accepting multiple offers
Previously, it was possible to accept multiple offers for the same property. This commit adds a validation check in the `accept_offer` method. Now, if a user attempts to accept an offer for a property that already has an accepted offer, a UserError is raised to block the action.
1 parent 7b44b2e commit 3cd43d1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

estate/models/estate_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _onchange_garden(self):
8989

9090

9191
@api.constrains("selling_price", "expected_price")
92-
def _check_selling_price_gt_90(self):
92+
def _check_selling_price_vs_expected_price(self):
9393
for record in self:
9494
if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) < 0:
9595
raise UserError("The selling price cannot be less than 90% of the expected price.")

estate/models/estate_property_offer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import models, fields, api
2+
from odoo.exceptions import UserError
23

34
class EstatePropertyOffer(models.Model):
45
_name = 'estate.property.offer'
@@ -31,11 +32,21 @@ def _inverse_date_deadline(self):
3132

3233
def accept_offer(self):
3334
for offer in self:
35+
# Check no other offer has been accepted for the same property
36+
if offer.property_id.offer_ids.filtered(lambda o: o.status == 'accepted'):
37+
raise UserError('Another offer has already been accepted for this property.')
38+
39+
# Accept the offer
3440
offer.status = 'accepted'
3541
offer.property_id.selling_price = offer.price
3642
offer.property_id.state = 'offer_accepted'
3743
offer.property_id.buyer_id = offer.partner_id
3844

45+
# Refuse all other offers for the same property
46+
other_offers = offer.property_id.offer_ids.filtered(lambda o: o.id != offer.id and o.status != 'refused')
47+
for other_offer in other_offers:
48+
other_offer.status = 'refused'
49+
3950
def refuse_offer(self):
4051
for offer in self:
4152
offer.status = 'refused'

0 commit comments

Comments
 (0)