Skip to content

Commit 4c98e9d

Browse files
committed
[IMP] estate: add default search for estate_property and stat button fpr offers
1 parent 538ac8c commit 4c98e9d

8 files changed

+60
-19
lines changed

estate/models/estate_property.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class EstateProperty(models.Model):
1313
("check_sell_price", "CHECK(selling_price > 0)",
1414
"The selling price of a property must be positive")
1515
]
16+
_order = "id desc"
1617

1718
name = fields.Char('name', required=True)
1819
description = fields.Text('description')
@@ -85,7 +86,7 @@ def action_sell(self):
8586
def action_cancel(self):
8687
if "sold" in self.mapped('state'):
8788
raise UserError("You can't cancel a sold property")
88-
self.state = "Cancelled"
89+
self.state = "cancelled"
8990

9091
return True
9192

estate/models/estate_property_offer.py

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class EstatePropertyOffer(models.Model):
99
_sql_constraints = [
1010
("check_price", "CHECK(price > 0)", "The offer price must be strictly positive")
1111
]
12+
_order = "price desc"
1213

1314
price = fields.Float('price')
1415
status = fields.Selection(
@@ -22,6 +23,7 @@ class EstatePropertyOffer(models.Model):
2223
property_id = fields.Many2one('estate.property', required=True)
2324
validity = fields.Integer(default=7)
2425
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
26+
property_type_id = fields.Many2one(related="property_id.property_type_id")
2527

2628
@api.depends("validity", "create_date")
2729
def _compute_date_deadline(self):
@@ -44,6 +46,7 @@ def action_accept(self):
4446
record.status = "accepted"
4547
record.property_id.selling_price = record.price
4648
record.property_id.buyer_id = record.partner_id
49+
record.property_id.state = "offer_accepted"
4750

4851
def action_refuse(self):
4952
for record in self:

estate/models/estate_property_tag.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ class EstatePropertyTag(models.Model):
77
_sql_constraints = [
88
("check_unique_name", "UNIQUE(name)", "Property tag must be unqie")
99
]
10+
_order = "name"
1011

1112
name = fields.Char('name', required=True)
13+
color = fields.Integer("color")

estate/models/estate_property_type.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import models, fields
1+
from odoo import api, models, fields
22

33

44
class EstatePropertyType(models.Model):
@@ -7,5 +7,14 @@ class EstatePropertyType(models.Model):
77
_sql_constraints = [
88
("check_unique_name", "UNIQUE(name)", "Property type name must be unqie")
99
]
10+
_order = "sequence, name"
1011

1112
name = fields.Char('name', required=True)
13+
property_ids = fields.One2many("estate.property", "property_type_id")
14+
sequence = fields.Integer("sequence")
15+
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
16+
offer_count = fields.Integer(compute="_compute_offer_count")
17+
18+
@api.depends("offer_ids")
19+
def _compute_offer_count(self):
20+
self.offer_count = len(self.offer_ids)

estate/views/estate_property_offer_views.xml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<odoo>
2+
<record id="estate_property_offer_action" model="ir.actions.act_window">
3+
<field name="name">Property Offers</field>
4+
<field name="res_model">estate.property.offer</field>
5+
<field name="view_mode">list,form</field>
6+
<field name="domain">[('property_type_id', '=', active_id)]</field>
7+
</record>
8+
29
<record id="estate_property_offer_view_list" model="ir.ui.view">
310
<field name="name">properties.view.offer.list</field>
411
<field name="model">estate.property.offer</field>
512
<field name="arch" type="xml">
6-
<list string="properties offer list">
13+
<list string="properties offer list" editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='refused'">
714
<field name="price"/>
815
<field name="validity"/>
916
<field name="date_deadline"/>
1017
<field name="partner_id"/>
11-
<button name="action_accept" string = "accept" type="object" icon="fa-check"/>
12-
<button name="action_refuse" string = "refuse" type="object" icon="fa-times"/>
13-
<field name="status"/>
18+
<field name="property_type_id"/>
19+
<button name="action_accept" string = "accept" type="object" icon="fa-check" invisible="status in ['accepted', 'refused']"/>
20+
<button name="action_refuse" string = "refuse" type="object" icon="fa-times" invisible="status in ['accepted', 'refused']"/>
1421
</list>
1522
</field>
1623
</record>

estate/views/estate_property_tag_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<field name="name">properties.view.tag.list</field>
1010
<field name="model">estate.property.tag</field>
1111
<field name="arch" type="xml">
12-
<list string="properties tag list">
12+
<list string="properties tag list" editable="bottom">
1313
<field name="name"/>
1414
</list>
1515
</field>

estate/views/estate_property_type_views.xml

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<field name="model">estate.property.type</field>
1111
<field name="arch" type="xml">
1212
<list string="properties type list">
13+
<field name="sequence" widget="handle"/>
1314
<field name="name"/>
1415
</list>
1516
</field>
@@ -21,9 +22,23 @@
2122
<field name="arch" type="xml">
2223
<form string="properties type form">
2324
<sheet>
25+
<button name="%(estate.estate_property_offer_action)d" type="action" icon="fa-money" string="offers">
26+
<field name="offer_count"/>
27+
</button>
2428
<h1>
2529
<field name="name"/>
2630
</h1>
31+
<notebook>
32+
<page string="Properties">
33+
<field name="property_ids">
34+
<list>
35+
<field name="name"/>
36+
<field name="expected_price"/>
37+
<field name="state"/>
38+
</list>
39+
</field>
40+
</page>
41+
</notebook>
2742
</sheet>
2843
</form>
2944
</field>

estate/views/estate_property_views.xml

+16-12
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
<field name="name">Properties</field>
44
<field name="res_model">estate.property</field>
55
<field name="view_mode">list,form</field>
6+
<field name="context">{'search_default_available': True}</field>
67
</record>
78

89
<record id="estate_property_view_list" model="ir.ui.view">
910
<field name="name">properties.view.list</field>
1011
<field name="model">estate.property</field>
1112
<field name="arch" type="xml">
12-
<list string="properties list">
13+
<list string="properties list" decoration-success="offer_ids" decoration-bf="state=='offer_accepted'" decoration-muted="state=='sold'">
1314
<field name="name"/>
1415
<field name="postcode"/>
16+
<field name="property_type_id"/>
17+
<field name="tag_ids" widget="many2many_tags" options="{'color_field':'color'}"/>
18+
<field name="state"/>
1519
<field name="bedrooms"/>
1620
<field name="living_area"/>
1721
<field name="expected_price"/>
1822
<field name="selling_price"/>
19-
<field name="availability_date"/>
23+
<field name="availability_date" optional="hide"/>
2024
</list>
2125
</field>
2226
</record>
@@ -27,17 +31,18 @@
2731
<field name="arch" type="xml">
2832
<form string="properties from">
2933
<header>
30-
<button name="action_sell" type="object" string="Mark as Sold"/>
31-
<button name="action_cancel" type="object" string="Cancel"/>
34+
<button name="action_sell" type="object" string="Mark as Sold" invisible="state in ['sold', 'cancelled']"/>
35+
<button name="action_cancel" type="object" string="Cancel" invisible="state in ['sold', 'cancelled']"/>
36+
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold"/>
3237
</header>
3338
<sheet>
3439
<h1>
3540
<field name="name"/>
3641
</h1>
37-
<field name="tag_ids" widget="many2many_tags"/>
42+
<field name="tag_ids" widget="many2many_tags" options="{'color_field':'color'}"/>
3843
<group>
3944
<group>
40-
<field name="property_type_id"/>
45+
<field name="property_type_id" options="{'no_create':true}"/>
4146
<field name="postcode"/>
4247
<field name="availability_date"/>
4348
</group>
@@ -56,14 +61,13 @@
5661
<field name="facades"/>
5762
<field name="garage"/>
5863
<field name="garden"/>
59-
<field name="garden_area"/>
60-
<field name="garden_orientation"/>
61-
<field name="state"/>
64+
<field name="garden_area" invisible="not garden"/>
65+
<field name="garden_orientation" invisible="not garden"/>
6266
<field name="total_area"/>
6367
</group>
6468
</page>
6569
<page string="Offers">
66-
<field name="offer_ids"/>
70+
<field name="offer_ids" readonly="state in ['offer_accepted', 'sold', 'cancelled']"/>
6771
</page>
6872
<page string="Other Info">
6973
<group>
@@ -85,11 +89,11 @@
8589
<field name="name"/>
8690
<field name="postcode"/>
8791
<field name="bedrooms"/>
88-
<field name="living_area"/>
92+
<field name="living_area" filter_domain="[('living_area', '>=', self)]"/>
8993
<field name="expected_price"/>
9094
<field name="selling_price"/>
9195
<field name="availability_date"/>
92-
<filter string="Available" name="state" domain="[('state','in',['new', 'offer_received'])]"/>
96+
<filter string="Available" name="available" domain="[('state', 'in', ['new', 'offer_received'])]"/>
9397
<group expand="1" string="Group By">
9498
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>
9599
</group>

0 commit comments

Comments
 (0)