Skip to content

Commit c592c35

Browse files
committed
You'll have to re-write this commit message
1 parent d6d9aeb commit c592c35

11 files changed

+188
-108
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
'views/estate_property_views.xml',
1313
'views/estate_settings_views.xml',
14+
'views/estate_property_offer_views.xml',
1415
'views/estate_menu_views.xml'
1516
],
1617
'installable': True,

estate/demo/estate_demo.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<field name="garden">True</field>
6060
<field name="garden_area">420</field>
6161
<field name="garden_orientation">south</field>
62-
<field name="property_type" ref="estate_property_type_2" />
62+
<field name="type_id" ref="estate_property_type_2" />
6363
<field name="salesperson" ref="base.user_demo"/>
6464
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_1'), ref('estate_property_tag_2')])]"/>
6565
<field name="offer_ids" eval="[(6, 0, [ref('estate_property_offer_1')])]"/>
@@ -78,7 +78,7 @@
7878
<field name="garage">False</field>
7979
<field name="garden">False</field>
8080
<field name="garden_area">0</field>
81-
<field name="property_type" ref="estate_property_type_1"/>
81+
<field name="type_id" ref="estate_property_type_1"/>
8282
<field name="salesperson" ref="base.user_admin"/>
8383
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_3')])]"/>
8484
<field name="offer_ids" eval="[(6, 0, [ref('estate_property_offer_2'), ref('estate_property_offer_4'), ref('estate_property_offer_3')])]"/>

estate/models/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from . import estate_property_infos
2-
from . import estate_property
1+
from . import estate_property_infos, estate_property, estate_property_offer

estate/models/estate_property.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class Estate_Property(models.Model):
77
_name = "estate_property"
88
_description = "Estate properties"
9+
_order = "id desc"
910
active = False
1011

1112
name = fields.Char(required=True, string="Title")
@@ -56,10 +57,12 @@ class Estate_Property(models.Model):
5657

5758
garden_orientation = fields.Selection(
5859
[("north", "North"), ("south", "South"), ("west", "West"), ("east", "East")],
59-
string="Garden Orientation"
60+
string="Garden Orientation",
6061
)
6162

62-
property_type = fields.Many2one("estate_property_type", string="Property Type")
63+
type_id = fields.Many2one(
64+
"estate_property_type", required=True, string="Property Type"
65+
)
6366

6467
buyer = fields.Many2one("res.partner", copy=False, string="Buyer")
6568

@@ -73,10 +76,21 @@ class Estate_Property(models.Model):
7376

7477
total_area = fields.Integer(compute="_compute_total_area", string="Total Area")
7578

76-
best_offer = fields.Float(compute="_compute_best_offer", default=0.0, string="Best Offer")
79+
best_offer = fields.Float(
80+
compute="_compute_best_offer", default=0.0, string="Best Offer"
81+
)
7782

7883
_sql_constraints = [
79-
("check_positive_expected_price", "CHECK(expected_price >= 0.0)", "Expected Price should be a positive number."), ("check_positive_selling_price", "CHECK(selling_price >= 0.0)", "Selling Price should be a positive number.")
84+
(
85+
"check_positive_expected_price",
86+
"CHECK(expected_price >= 0.0)",
87+
"Expected Price should be a positive number.",
88+
),
89+
(
90+
"check_positive_selling_price",
91+
"CHECK(selling_price >= 0.0)",
92+
"Selling Price should be a positive number.",
93+
),
8094
]
8195

8296
@api.depends("garden_area", "living_area")
@@ -101,8 +115,12 @@ def _onchange_garden(self):
101115
@api.constrains("selling_price", "expected_price")
102116
def _check_expected_vs_selling_price(self):
103117
for record in self:
104-
if (record.selling_price > 0.0) and (record.selling_price < 0.9 * record.expected_price):
105-
raise exceptions.ValidationError(r"Cannot sell for less than 90% of expected price.")
118+
if (record.selling_price > 0.0) and (
119+
record.selling_price < 0.9 * record.expected_price
120+
):
121+
raise exceptions.ValidationError(
122+
r"Cannot sell for less than 90% of expected price."
123+
)
106124

107125
def action_sold(self):
108126
for record in self:
Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
from odoo import api, exceptions, fields, models
2-
from datetime import date
3-
from dateutil.relativedelta import relativedelta
1+
from odoo import fields, models
42

53

64
class Estate_Property_Type(models.Model):
75
_name = "estate_property_type"
86
_description = "Estate property Types"
9-
active = False
7+
_order = "name"
108

119
name = fields.Char(
1210
required=True,
1311
string="Type"
1412
)
1513

14+
property_ids = fields.One2many(
15+
"estate_property",
16+
"type_id",
17+
string="Estate Properties"
18+
)
19+
1620
_sql_constraints = [
1721
("check_unique_type", "UNIQUE(name)", "Property types must be unique.")
1822
]
@@ -21,6 +25,7 @@ class Estate_Property_Type(models.Model):
2125
class Estate_Property_Tag(models.Model):
2226
_name = "estate_property_tag"
2327
_description = "Estate property Tags"
28+
_order = "name"
2429

2530
name = fields.Char(
2631
required=True,
@@ -35,75 +40,3 @@ class Estate_Property_Tag(models.Model):
3540
_sql_constraints = [
3641
("check_unique_tag", "UNIQUE(name)", "Property tags must be unique.")
3742
]
38-
39-
40-
class Estate_Property_Offer(models.Model):
41-
_name = "estate_property_offer"
42-
_description = "Estate Property Offers"
43-
44-
price = fields.Float(
45-
string="Price"
46-
)
47-
48-
status = fields.Selection(
49-
[("accepted", "Accepted"), ("refused", "Refused")],
50-
readonly=True,
51-
copy=False,
52-
string="Status"
53-
)
54-
55-
partner_id = fields.Many2one(
56-
'res.partner',
57-
required=True,
58-
string="Partner"
59-
)
60-
61-
property_id = fields.Many2one(
62-
'estate_property',
63-
string="Property"
64-
)
65-
66-
validity = fields.Integer(
67-
default=7,
68-
string="Validity (days)"
69-
)
70-
71-
deadline = fields.Date(
72-
compute="_compute_deadline",
73-
copy=False,
74-
string="Deadline"
75-
)
76-
77-
_sql_constraints = [
78-
("check_positive_price", "CHECK(price > 0.0)", "Offer Price should be a positive number (higher than 0).")
79-
]
80-
81-
@api.depends("validity")
82-
def _compute_deadline(self):
83-
for record in self:
84-
record.deadline = date.today() + relativedelta(days=+record.validity)
85-
86-
def _inverse_deadline(self):
87-
for record in self:
88-
record.validity = relativedelta(date.today(), record.deadline)
89-
90-
def action_accept(self):
91-
for record in self:
92-
if not any(offer_status == "accepted" for offer_status in record.property_id.offer_ids.mapped("status")):
93-
# Set values in the Property itself
94-
record.property_id.selling_price = record.price
95-
record.property_id.buyer = record.partner_id
96-
97-
record.status = "accepted"
98-
else:
99-
raise exceptions.UserError("An offer has already been accepted.")
100-
return True
101-
102-
def action_refuse(self):
103-
for record in self:
104-
if record.status == "accepted":
105-
# Set values in the Property itself
106-
record.property_id.selling_price = 0.0
107-
record.property_id.buyer = None
108-
record.status = "refused"
109-
return True
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from odoo import api, exceptions, fields, models
2+
from datetime import date
3+
from dateutil.relativedelta import relativedelta
4+
5+
6+
class Estate_Property_Offer(models.Model):
7+
_name = "estate_property_offer"
8+
_description = "Estate Property Offers"
9+
_order = "price desc"
10+
11+
price = fields.Float(
12+
string="Price"
13+
)
14+
15+
status = fields.Selection(
16+
[("accepted", "Accepted"), ("refused", "Refused")],
17+
readonly=True,
18+
copy=False,
19+
string="Status"
20+
)
21+
22+
partner_id = fields.Many2one(
23+
'res.partner',
24+
required=True,
25+
string="Partner"
26+
)
27+
28+
property_id = fields.Many2one(
29+
'estate_property',
30+
string="Property"
31+
)
32+
33+
validity = fields.Integer(
34+
default=7,
35+
string="Validity (days)"
36+
)
37+
38+
deadline = fields.Date(
39+
compute="_compute_deadline",
40+
copy=False,
41+
string="Deadline"
42+
)
43+
44+
_sql_constraints = [
45+
("check_positive_price", "CHECK(price > 0.0)", "Offer Price should be a positive number (higher than 0).")
46+
]
47+
48+
@api.depends("validity")
49+
def _compute_deadline(self):
50+
for record in self:
51+
record.deadline = date.today() + relativedelta(days=+record.validity)
52+
53+
def _inverse_deadline(self):
54+
for record in self:
55+
record.validity = relativedelta(date.today(), record.deadline)
56+
57+
def action_accept(self):
58+
for record in self:
59+
if not any(offer_status == "accepted" for offer_status in record.property_id.offer_ids.mapped("status")):
60+
# Set values in the Property itself
61+
record.property_id.selling_price = record.price
62+
record.property_id.buyer = record.partner_id
63+
64+
record.status = "accepted"
65+
else:
66+
raise exceptions.UserError("An offer has already been accepted.")
67+
return True
68+
69+
def action_refuse(self):
70+
for record in self:
71+
if record.status == "accepted":
72+
# Set values in the Property itself
73+
record.property_id.selling_price = 0.0
74+
record.property_id.buyer = None
75+
record.status = "refused"
76+
return True

estate/static/description/icon.webp

9.45 KB
Binary file not shown.

estate/views/estate_menu_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<!-- SUBHEADERS: Settings -->
3636
<menuitem
3737
id="menu_estate_property_types"
38-
name="Property types"
38+
name="Property Types"
3939
sequence="1"
4040
parent="estate.menu_estate_settings"
4141
action="estate_property_types_view"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<!-- List view -->
5+
<record id="estate_property_offer_view_list" model="ir.ui.view">
6+
<field name="name">estate_property_offer_list</field>
7+
<field name="model">estate_property_offer</field>
8+
<field name="arch" type="xml">
9+
<list editable="top">
10+
<field name="price"/>
11+
<field name="partner_id"/>
12+
<field name="validity"/>
13+
<field name="deadline"/>
14+
<button name="action_accept" type="object" string="Accept" icon="fa-check"/>
15+
<button name="action_refuse" type="object" string="Refuse" icon="fa-times"/>
16+
<field name="status"/>
17+
</list>
18+
</field>
19+
</record>
20+
21+
<record id="estate_property_offer_view" model="ir.actions.act_window">
22+
<field name="name">Offers</field>
23+
<field name="res_model">estate_property_offer</field>
24+
<field name="view_mode">list</field>
25+
</record>
26+
27+
</odoo>

estate/views/estate_property_views.xml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,28 @@
3030

3131
<field name="arch" type="xml">
3232
<form string="Estate Property">
33+
<header>
34+
<button name="action_sold" type="object" string="Sold" />
35+
<button name="action_cancel" type="object" string="Cancel" />
36+
<field name="status" widget="statusbar"
37+
statusbar_visible="new,offer_received,offer_accepted,sold"
38+
options="{'clickable': 1}" type="selection" />
39+
</header>
40+
3341
<sheet>
3442
<div class="oe_title">
35-
<button name="action_sold" type="object" string="Sold"/>
36-
<button name="action_cancel" type="object" string="Cancel"/>
3743
<h1>
3844
<field name="name" string="Property" placeholder="Property Name"
3945
required="True" />
4046
</h1>
41-
<field name="tag_ids" widget="many2many_tags"/>
47+
<field name="tag_ids" widget="many2many_tags" />
4248
</div>
4349

4450
<separator />
4551

4652
<group>
4753
<group>
48-
<field name="property_type" />
54+
<field name="type_id" />
4955
<field name="postcode" />
5056
<field name="date_availability" />
5157
</group>
@@ -70,22 +76,11 @@
7076
<field name="garden_area" />
7177
<field name="garden_orientation" />
7278
<field name="total_area" />
73-
<field name="status" />
7479
</group>
7580
</page>
7681

7782
<page string="Offers">
78-
<field name="offer_ids">
79-
<list default_order="status,price desc" editable="top">
80-
<field name="price"/>
81-
<field name="partner_id"/>
82-
<field name="validity"/>
83-
<field name="deadline"/>
84-
<button name="action_accept" type="object" string="Accept" icon="fa-check"/>
85-
<button name="action_refuse" type="object" string="Refuse" icon="fa-times"/>
86-
<field name="status"/>
87-
</list>
88-
</field>
83+
<field name="offer_ids" />
8984
</page>
9085

9186
<page string="Other Info">

0 commit comments

Comments
 (0)