Skip to content

Commit 4a0880f

Browse files
committed
[IMP] estate, awesome_owl: mark property as sold only if accepted offers exist, remove unnecessary comments and fix linting.
- Added logic to check if any offers are present before marking the property as sold. - Added logic to check if one of the offers is accepted before marking property as sold - Removed unnecessary comments from files. - Fixed linting issues from `utils.js`
1 parent 9cb4c74 commit 4a0880f

File tree

5 files changed

+9
-34
lines changed

5 files changed

+9
-34
lines changed

awesome_owl/static/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export const useAutoFocus = () => {
55
onMounted(() => {
66
inputRef.el?.focus();
77
})
8-
}
8+
}

estate/models/estate_property.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class EstateProperty(models.Model):
11-
# === Private attributes ===
1211
_name = 'estate.property'
1312
_description = 'Estate Test'
1413
_order = 'id desc'
@@ -19,9 +18,6 @@ class EstateProperty(models.Model):
1918
('check_selling_price_positive', 'CHECK(selling_price > 0)', 'Selling price must be strictly positive.'),
2019
]
2120

22-
# ---------------------
23-
# Fields declaration
24-
# ---------------------
2521
name = fields.Char(string='Name', required=True)
2622
description = fields.Char()
2723
postcode = fields.Char()
@@ -35,8 +31,6 @@ class EstateProperty(models.Model):
3531
garden = fields.Boolean()
3632
garden_area = fields.Integer()
3733
active = fields.Boolean(default=True)
38-
39-
# Selection fields
4034
garden_orientation = fields.Selection(
4135
[
4236
('north', 'North'),
@@ -59,19 +53,11 @@ class EstateProperty(models.Model):
5953
copy=False,
6054
default='new'
6155
)
62-
63-
# Many2one fields
6456
property_type_id = fields.Many2one('estate.property.type', string='Property Type')
6557
salesman_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user)
6658
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False)
67-
68-
# Many2many fields
6959
tag_ids = fields.Many2many('estate.property.tag', string='Tags')
70-
71-
# One2many fields
7260
offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers')
73-
74-
# Computed fields
7561
total_area = fields.Integer(string='Total Area', compute='_compute_total_area')
7662
best_price = fields.Float(string='Best Offer', compute='_compute_best_price')
7763

@@ -129,8 +115,15 @@ def _unlink_except_new_or_cancelled(self):
129115
# ----------------------
130116
def action_mark_sold(self):
131117
for record in self:
118+
if not record.offer_ids:
119+
raise UserError("You can mark this property as sold because there are no offers.")
132120
if record.state == 'cancelled':
133121
raise UserError('Cancelled properties cannot be marked as sold.')
122+
123+
accepted_offer = record.offer_ids.filtered(lambda o: o.status == 'accepted')
124+
if not accepted_offer:
125+
raise UserError("You must accept an offer before marking the property as sold.")
126+
134127
record.state = 'sold'
135128
return True
136129

estate/models/estate_property_offer.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class EstatePropertyOffer(models.Model):
11-
# === Private attributes ===
1211
_name = 'estate.property.offer'
1312
_description = 'Offers for all the property listings.'
1413
_order = 'price desc'
@@ -18,13 +17,8 @@ class EstatePropertyOffer(models.Model):
1817
('check_price_positive', 'CHECK(price > 0)', 'Offer price must be strictly positive.'),
1918
]
2019

21-
# ------------------------
22-
# Fields declaration
23-
# -------------------------
2420
price = fields.Float(string='Price')
2521
validity = fields.Integer(default=7)
26-
27-
# Selection fields
2822
status = fields.Selection(
2923
[
3024
('accepted', 'Accepted'),
@@ -33,11 +27,7 @@ class EstatePropertyOffer(models.Model):
3327
string='Status',
3428
copy=False
3529
)
36-
37-
# Computed fields
3830
date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', store=True)
39-
40-
# Many2one fields
4131
partner_id = fields.Many2one('res.partner', required=True)
4232
property_id = fields.Many2one('estate.property', string='Property Name', required=True)
4333
property_type_id = fields.Many2one(related='property_id.property_type_id', store=True)

estate/models/estate_property_tag.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from odoo import fields, models
33

44

5-
class EstatePropertyType(models.Model):
6-
# === Private attributes ===
5+
class EstatePropertyTag(models.Model):
76
_name = 'estate.property.tag'
87
_description = 'Property tags to represent the property.'
98
_order = 'name'
@@ -13,6 +12,5 @@ class EstatePropertyType(models.Model):
1312
('unique_tag_name', 'UNIQUE(name)', 'Tag name must be unique.'),
1413
]
1514

16-
# === Fields declaration ===
1715
name = fields.Char('Property Tag', required=True)
1816
color = fields.Integer(string="Color")

estate/models/estate_property_type.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
class EstatePropertyType(models.Model):
6-
# === Private attributes ===
76
_name = 'estate.property.type'
87
_description = 'Property types for available in the business.'
98
_order = 'sequence, name'
@@ -13,15 +12,10 @@ class EstatePropertyType(models.Model):
1312
('unique_type_name', 'UNIQUE(name)', 'Type name must be unique.')
1413
]
1514

16-
# === Fields declaration ===
1715
name = fields.Char(required=True)
1816
sequence = fields.Integer('Sequence', default=10)
19-
20-
# One2many fields
2117
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
2218
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers')
23-
24-
# Compute fields
2519
offer_count = fields.Integer(string='Number of Offers', compute='_compute_offer_count')
2620

2721
# === Compute methods ===

0 commit comments

Comments
 (0)