Skip to content

Commit 315e008

Browse files
committed
[IMP] estate: add stat button, default filter, decorations
Implemented stat button on property type default filter in property page decorations in property offer and property make editable list view for property tag
1 parent cefa841 commit 315e008

8 files changed

+49
-34
lines changed

estate/models/estate_property.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,30 @@ class EstateProperty(models.Model):
3030
('west', 'West')
3131
]
3232
)
33-
active = fields.Boolean(default=False)
33+
active = fields.Boolean(default=True)
3434
state = fields.Selection(
3535
selection=[
3636
('new', 'New'),
3737
('offer_received', 'Offer Received'),
3838
('offer_accepted', 'Offer Accepted'),
3939
('sold', 'Sold'),
4040
('cancelled', 'Cancelled')
41-
]
41+
],
42+
default="new"
4243
)
43-
property_type_id = fields.Many2one("estate.property.type")
44+
type_id = fields.Many2one("estate.property.type")
4445
buyer = fields.Many2one("res.partner", copy=False)
4546
salesperson = fields.Many2one("res.users", default=lambda self: self.env.user)
4647
tag_ids = fields.Many2many("estate.property.tag")
4748
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
4849
total_area = fields.Float(compute="_compute_total_area")
4950
best_offer = fields.Float(compute="_compute_best_offer")
50-
51+
5152
@api.depends('living_area', 'garden_area')
5253
def _compute_total_area(self):
5354
for record in self:
5455
record.total_area = record.living_area + record.garden_area
55-
56+
5657
@api.depends('offer_ids.price')
5758
def _compute_best_offer(self):
5859
for record in self:

estate/models/estate_property_offer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dateutil.relativedelta import relativedelta
22

33
from odoo import models, fields, api
4-
from odoo.exceptions import UserError, ValidationError
4+
from odoo.exceptions import UserError
55

66

77
class EstatePropertyOffer(models.Model):
@@ -18,6 +18,7 @@ class EstatePropertyOffer(models.Model):
1818
)
1919
partner_id = fields.Many2one("res.partner", required=True)
2020
property_id = fields.Many2one("estate.property", required=True)
21+
property_type_id = fields.Many2one(related="property_id.type_id", store=True)
2122
validity = fields.Integer(default=7)
2223
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline")
2324

@@ -53,4 +54,3 @@ def action_refuse(self):
5354
'CHECK(price>=0)',
5455
'offer price must be positive',
5556
)
56-

estate/models/estate_property_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class EstatePropertyTag(models.Model):
88

99
name = fields.Char()
1010
property_ids = fields.Many2many('estate.property')
11-
color=fields.Integer()
11+
color = fields.Integer()
1212

1313
_unique_name = models.Constraint(
1414
'UNIQUE(name)',
1515
'name already exists!',
16-
)
16+
)
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
22

33

44
class EstatePropertyType(models.Model):
55
_name = 'estate.property.type'
66
_description = "Real Estate Property Type"
7-
_order = "sequence"
7+
_order = "sequence, name"
88

99
name = fields.Char(required=True)
10-
property_ids = fields.One2many('estate.property', 'property_type_id')
10+
property_ids = fields.One2many('estate.property', 'type_id')
1111
sequence = fields.Integer(string="Sequence", default=1)
12+
offer_count = fields.Integer(compute="_compute_total_offers")
13+
offer_ids = fields.One2many("estate.property.offer","property_type_id")
1214

13-
_unique_name = models.Constraint(
14-
'UNIQUE(name)',
15-
'name already exists!',
16-
)
15+
@api.depends("offer_ids")
16+
def _compute_total_offers(self):
17+
for record in self:
18+
record.offer_count = len(record.property_ids.mapped("offer_ids"))

estate/views/estate_property_offer_views.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
<record id="estate_property_offer_list" model="ir.ui.view">
44
<field name="model">estate.property.offer</field>
55
<field name="arch" type="xml">
6-
<list>
6+
<list decoration-danger="status == 'refused'" decoration-success="status == 'accepted'">
77
<field name="price" />
88
<field name="partner_id" />
99
<field name="validity"/>
1010
<field name="date_deadline"/>
11-
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
12-
<button name="action_refuse" string="Cancelled" type="object" icon="fa-times"/>
13-
<field name="status"/>
11+
<button name="action_accept" string="Accept" type="object" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
12+
<button name="action_refuse" string="Cancelled" type="object" icon="fa-times" invisible="status in ('accepted', 'refused')"/>
1413
</list>
1514
</field>
1615
</record>

estate/views/estate_property_tag_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<record id="estate_property_tag_list" model="ir.ui.view">
1313
<field name="model">estate.property.tag</field>
1414
<field name="arch" type="xml">
15-
<list string="List">
15+
<list string="List" editable="top">
1616
<field name="name"/>
1717
</list>
1818
</field>

estate/views/estate_property_type_views.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<field name="arch" type="xml">
1717
<form>
1818
<sheet>
19+
<header>
20+
<button type="action" name="%(estate.estate_property_offer_action)d" class="oe_stat_button" icon="fa-money">
21+
<field name="offer_count" widget="statinfo" string="Offers"/>
22+
</button>
23+
</header>
1924
<group>
2025
<group>
2126
<field name="name"/>
@@ -37,6 +42,12 @@
3742
<field name="name">Property type</field>
3843
<field name="res_model">estate.property.type</field>
3944
<field name="view_mode">list,form</field>
40-
<field name="context">{"search_default_available":1}</field>
45+
</record>
46+
47+
<record id="estate_property_offer_action" model="ir.actions.act_window">
48+
<field name="name">Property type Offer</field>
49+
<field name="res_model">estate.property.offer</field>
50+
<field name="view_mode">list</field>
51+
<field name="domain">[("property_id.type_id", "=", active_id)]</field>
4152
</record>
4253
</odoo>

estate/views/estate_property_views.xml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@
1010
<field name="expected_price"/>
1111
<field name="selling_price"/>
1212
<field name="facades"/>
13-
<field name="property_type_id"/>
14-
<filter string="Available" name="group_by_available" domain="['|' ,('state', '=', 'new'), ('state', '=', 'offer_received')]"/>
13+
<field name="type_id"/>
14+
<filter string="Available" name="available" domain="['|' ,('state', '=', 'new'), ('state', '=', 'offer_received')]"/>
15+
<field name="living_area" filter_domain="[('living_area','>=',self)]"/>
1516
</search>
1617
</field>
1718
</record>
1819

1920
<record id="estate_property_list" model="ir.ui.view">
2021
<field name="model">estate.property</field>
2122
<field name="arch" type="xml">
22-
<list>
23+
<list decoration-success="state == 'offer_received' or state == 'offer_accepted'" decoration-bf="state == 'offer_accepted'" decoration-muted="state == 'sold'">
2324
<field name="name"/>
24-
<field name="postcode"/>
2525
<field name="bedrooms"/>
2626
<field name="total_area"/>
2727
<field name="selling_price"/>
28-
<field name="date_availability"/>
29-
<field name="property_type_id"/>
28+
<field name="date_availability" optional="hidden"/>
29+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
30+
<field name="type_id"/>
31+
<field name="living_area"/>
3032
</list>
3133
</field>
3234
</record>
@@ -36,15 +38,15 @@
3638
<field name="arch" type="xml">
3739
<form>
3840
<header>
39-
<button name="cancel_property" type="object" string="Cancel"/>
40-
<button name="sold_property" type="object" string="Sold"/>
41+
<button name="cancel_property" type="object" string="Cancel" invisible="state in ('sold', 'cancelled')"/>
42+
<button name="sold_property" type="object" string="Sold" invisible="state in ('sold', 'cancelled')"/>
4143
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold,cancelled"/>
4244
</header>
4345
<sheet>
4446
<group>
4547
<group>
4648
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
47-
<field name="property_type_id" options="{'no_create': true, 'no_open': true}" />
49+
<field name="type_id" options="{'no_create': true, 'no_open': true, 'no_edit': true}"/>
4850
<field name="name"/>
4951
<field name="state"/>
5052
<field name="date_availability"/>
@@ -71,14 +73,14 @@
7173
<field name="living_area"/>
7274
<field name="garage"/>
7375
<field name="garden"/>
74-
<field name="garden_area"/>
75-
<field name="garden_orientation"/>
76+
<field name="garden_area" invisible="not garden"/>
77+
<field name="garden_orientation" invisible="not garden"/>
7678
<field name="total_area"/>
7779
</group>
7880
</group>
7981
</page>
8082
<page string="Offers">
81-
<field name="offer_ids"/>
83+
<field name="offer_ids" readonly="state in ('offer_accepted','sold','cancelled')"/>
8284
</page>
8385
<page string="Other Info">
8486
<group>

0 commit comments

Comments
 (0)