Skip to content

Commit a9e522a

Browse files
committed
[IMP] estate: add inline editing, widgets and stat_button
1 parent 60becd9 commit a9e522a

8 files changed

Lines changed: 92 additions & 14 deletions

estate/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
'data': [
99
'security/ir.model.access.csv',
1010
'views/estate_property_views.xml',
11+
'views/estate_property_offer_views.xml',
1112
'views/estate_property_type_views.xml',
1213
'views/estate_property_tag_views.xml',
1314
'views/estate_menus.xml',
14-
'views/estate_property_offer_views.xml',
1515
],
1616
'application': True,
1717
'author': 'Odoo S.A.',
18+
'license': 'LGPL-3',
1819
}

estate/models/estate_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class EstateProperty(models.Model):
1111
_name = "estate.property"
1212
_description = "Real Estate Property"
13+
_order = "id desc"
1314

1415
name = fields.Char(string="Title", required=True)
1516
description = fields.Text(string="Description")

estate/models/estate_property_offer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class PropertyOffer(models.Model):
88
_name = "estate.property.offer"
99
_description = "Real Estate Property Offer"
10+
_order = "price desc"
1011

1112
price = fields.Float()
1213
status = fields.Selection(selection=PROPERTY_OFFER_STATE, copy=False)
@@ -17,6 +18,8 @@ class PropertyOffer(models.Model):
1718
validity = fields.Integer(string="Validity (days)", default=7)
1819
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
1920

21+
property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id", string="Property Type", store=True)
22+
2023
_check_price = models.Constraint(
2124
'CHECK(price > 0)',
2225
"The offer price must be strictly positive."
@@ -39,6 +42,7 @@ def action_accept_offer(self):
3942
offer.status = "accepted"
4043
offer.property_id.buyer_id = offer.partner_id
4144
offer.property_id.selling_price = offer.price
45+
offer.property_id.state = "offer_accepted"
4246
for competing_offer in offer.property_id.offer_ids:
4347
if competing_offer != offer:
4448
competing_offer.status = "refused"
@@ -48,3 +52,11 @@ def action_refuse_offer(self):
4852
for offer in self:
4953
offer.status = "refused"
5054
return True
55+
56+
@api.model
57+
def create(self, vals):
58+
offer = super().create(vals)
59+
property_record = offer.property_id
60+
if property_record.state == 'new':
61+
property_record.state = 'offer_received'
62+
return offer

estate/models/estate_property_tag.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
class PropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Real Estate Property Tag"
7+
_order = "name"
78

89
name = fields.Char(string="Name", required=True)
10+
color = fields.Integer(string="Color Index")
911

1012
_check_unique_name = models.Constraint(
1113
'UNIQUE(name)',
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
from odoo import models, fields
1+
from odoo import api, models, fields
22

33

44
class PropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Real Estate Property Type"
7+
_order = "name"
78

89
name = fields.Char(string="Property Type", required=True)
10+
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
11+
sequence = fields.Integer('Sequence', default=1)
12+
13+
offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers")
14+
offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count")
915

1016
_check_unique_name = models.Constraint(
1117
'UNIQUE(name)',
1218
"The property type name must be unique."
1319
)
20+
21+
@api.depends("offer_ids")
22+
def _compute_offer_count(self):
23+
for property_type in self:
24+
property_type.offer_count = len(property_type.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?xml version="1.0"?>
22
<odoo>
3+
<record id="estate_property_offer_action" model="ir.actions.act_window">
4+
<field name="name">Property Offers</field>
5+
<field name="res_model">estate.property.offer</field>
6+
<field name="view_mode">list,form</field>
7+
<field name="domain">[('property_type_id', '=', active_id)]</field>
8+
</record>
39
<record id="estate_property_offer_view_tree" model="ir.ui.view">
410
<field name="name">estate.property.offer.list</field>
511
<field name="model">estate.property.offer</field>
612
<field name="arch" type="xml">
7-
<list>
13+
<list editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='refused'">
814
<field name="price"/>
915
<field name="partner_id"/>
10-
<field name="status"/>
1116
<field name="validity"/>
1217
<field name="date_deadline"/>
1318
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check" invisible="status != False"/>

estate/views/estate_property_type_views.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,48 @@
66
<field name="view_mode">list,form</field>
77
</record>
88

9+
<record id="estate_property_type_view_form" model="ir.ui.view">
10+
<field name="name">estate.property.type.form</field>
11+
<field name="model">estate.property.type</field>
12+
<field name="arch" type="xml">
13+
<form>
14+
<sheet>
15+
<div name="button_box" class="oe_button_box">
16+
<button class="oe_stat_button" type="action" name="%(estate.estate_property_offer_action)d" icon="fa-book">
17+
<div class="o_stat_info">
18+
<span class="o_stat_text">Offers</span>
19+
</div>
20+
</button>
21+
</div>
22+
<div class="oe_title">
23+
<h1>
24+
<field name="name"/>
25+
</h1>
26+
27+
</div>
28+
<notebook>
29+
<page name="Properties">
30+
<field name="property_ids">
31+
<list>
32+
<field name="name"/>
33+
<field name="expected_price"/>
34+
<field name="state"/>
35+
</list>
36+
</field>
37+
</page>
38+
</notebook>
39+
</sheet>
40+
</form>
41+
</field>
42+
</record>
43+
<record id="estate_property_type_view_tree" model="ir.ui.view">
44+
<field name="name">estate.property.type.list</field>
45+
<field name="model">estate.property.type</field>
46+
<field name="arch" type="xml">
47+
<list>
48+
<field name="sequence" widget="handle"/>
49+
<field name="name"/>
50+
</list>
51+
</field>
52+
</record>
953
</odoo>

estate/views/estate_property_views.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
<field name="name">Properties</field>
66
<field name="res_model">estate.property</field>
77
<field name="view_mode">list,form</field>
8+
<field name="context">{'search_default_available': True, 'search_default_current': True}</field>
89
</record>
910
<record id="estate_property_view_tree" model="ir.ui.view">
1011
<field name="name">estate.property.list</field>
1112
<field name="model">estate.property</field>
1213
<field name="arch" type="xml">
13-
<list>
14+
<list decoration-success="state in ('offer_received','offer_accepted')" decoration-bf="state=='offer_accepted'" decoration-muted="state=='sold'">
1415
<field name="name"/>
1516
<field name="postcode"/>
1617
<field name="bedrooms"/>
1718
<field name="living_area"/>
1819
<field name="expected_price"/>
1920
<field name="selling_price"/>
20-
<field name="date_availability"/>
21+
<field name="date_availability" optional="hide"/>
2122
</list>
2223
</field>
2324
</record>
@@ -29,19 +30,20 @@
2930
<form>
3031
<header>
3132
<button name="action_cancel_property" type="object" string="Cancel"/>
32-
<button name="action_sold_property" type="object" string="Sold"/>
33+
<button name="action_sold_property" type="object" string="Sold" invisible="state == 'offer_accepted'"/>
34+
<button name="action_sold_property" type="object" string="Sold" class="oe_highlight" invisible="state != 'offer_accepted'"/>
35+
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold"/>
3336
</header>
3437
<sheet>
3538
<div class="oe_title">
3639
<h1>
3740
<field name="name"/>
3841
</h1>
39-
<field name="property_tag_ids" widget="many2many_tags"/>
42+
<field name="property_tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
4043
</div>
4144
<group>
4245
<group>
43-
<field name="state"/>
44-
<field name="property_type_id"/>
46+
<field name="property_type_id" options="{'no_create': True, 'no_edit': True}"/>
4547
<field name="postcode"/>
4648
<field name="date_availability"/>
4749
</group>
@@ -60,13 +62,13 @@
6062
<field name="facades"/>
6163
<field name="garage"/>
6264
<field name="garden"/>
63-
<field name="garden_area"/>
64-
<field name="garden_orientation"/>
65+
<field name="garden_area" invisible="not garden"/>
66+
<field name="garden_orientation" invisible="not garden"/>
6567
<field name="total_area"/>
6668
</group>
6769
</page>
6870
<page name="Offers">
69-
<field name="offer_ids"/>
71+
<field name="offer_ids" readonly="state in ['sold', 'offer_accepted','cancelled']"/>
7072
</page>
7173
<page name="Other Info">
7274
<group>
@@ -88,7 +90,7 @@
8890
<field name="postcode"/>
8991
<field name="expected_price"/>
9092
<field name="bedrooms"/>
91-
<field name="living_area"/>
93+
<field name="living_area" filter_domain="[('living_area', '>=', self)]"/>
9294
<field name="facades"/>
9395
<filter string="Available" name="available" domain="[('state', 'in', ('new', 'offer_received'))]"/>
9496
<group>

0 commit comments

Comments
 (0)