Skip to content

Commit 8b9ad65

Browse files
committed
[IMP] Add the sprinkles
1 parent 4851e11 commit 8b9ad65

9 files changed

+84
-30
lines changed

estate/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
'data': [
1313
'security/ir.model.access.csv',
1414

15+
'views/estate_property_offer_views.xml',
1516
'views/estate_property_views.xml',
16-
'views/estate_property_type_views.xml',
1717
'views/estate_property_tag_views.xml',
18-
'views/estate_property_offer_views.xml',
18+
'views/estate_property_type_views.xml',
1919
'views/estate_menus.xml',
2020
],
2121
# # data files containing optionally loaded demonstration data

estate/models/estate_property.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class EstateProperty(models.Model):
88
_name = "estate.property"
99
_description = "Real estate propreties"
10+
_order = "id desc"
1011

1112
_check_expected_price = models.Constraint(
1213
'CHECK(expected_price > 0)',
@@ -36,10 +37,10 @@ class EstateProperty(models.Model):
3637
seller_id = fields.Many2one('res.users', default=lambda self: self.env.user)
3738
buyer_id = fields.Many2one('res.partner')
3839
tag_ids = fields.Many2many('estate.property.tag', string="Tags")
40+
type_id = fields.Many2one('estate.property.type', string="Type")
3941
offer_ids = fields.One2many('estate.property.offer', 'property_id')
4042
total_area = fields.Float(compute="_compute_total_area", readonly=True, copy=False)
4143
best_price = fields.Float(compute="_get_best_price", readonly=True, copy=False)
42-
is_available = fields.Boolean(compute='_compute_is_available')
4344

4445
@api.depends('living_area', 'garden_area')
4546
def _compute_total_area(self):
@@ -78,11 +79,6 @@ def action_set_cancelled(self):
7879
self.state = 'cancelled'
7980
return 1
8081

81-
@api.depends('offer_ids.status')
82-
def _compute_is_available(self):
83-
for record in self:
84-
record.is_available = not any(s == 'accepted' for s in record.offer_ids.mapped('status'))
85-
8682
@api.constrains('selling_price', 'expected_price')
8783
def _check_selling_price(self):
8884
self.ensure_one()

estate/models/estate_property_offer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class EstatePropertyOffer(models.Model):
66
_name = "estate.property.offer"
77
_description = "Offers for propreties"
8+
_order = "price desc"
89

910
_check_price = models.Constraint(
1011
'CHECK(price > 0)',
@@ -17,7 +18,7 @@ class EstatePropertyOffer(models.Model):
1718
create_date = fields.Date(default=fields.Date.today(), readonly=True)
1819
validity = fields.Integer(default=7)
1920
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
20-
is_available = fields.Boolean(related="property_id.is_available")
21+
property_type_id = fields.Many2one(related="property_id.type_id")
2122

2223
@api.depends('validity', 'create_date')
2324
def _compute_date_deadline(self):
@@ -29,10 +30,10 @@ def _inverse_date_deadline(self):
2930
record.validity = (record.date_deadline - record.create_date).days
3031

3132
def action_accept_offer(self):
32-
for record in self:
33-
record.status = 'accepted'
34-
record.property_id.buyer_id = record.partner_id
35-
record.property_id.selling_price = record.price
33+
self.ensure_one()
34+
self.status = 'accepted'
35+
self.property_id.buyer_id = self.partner_id
36+
self.property_id.selling_price = self.price
3637
return 1
3738

3839
def action_refuse_offer(self):

estate/models/estate_property_tag.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Define the tags of the property"
7+
_order = "name"
78

89
_check_unique_tag = models.Constraint(
910
'UNIQUE(name)',
1011
'Tag already exists.',
1112
)
1213
name = fields.Char(required=True)
14+
color = fields.Integer(default=1)
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
from odoo import fields, models
1+
from odoo import fields, models, api
22

33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Define the type of the property"
7+
_order = "sequence, name"
78

89
_check_unique_type = models.Constraint(
910
'UNIQUE(name)',
1011
'Type already exists.',
1112
)
1213
name = fields.Char(required=True)
14+
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
15+
property_ids = fields.One2many("estate.property", "type_id")
16+
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
17+
offer_count = fields.Integer(compute="_compute_offer_count", readonly=True)
18+
19+
@api.depends('offer_ids')
20+
def _compute_offer_count(self):
21+
for record in self:
22+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<odoo>
3+
<record id="estate_property_offer_from_property_action" model="ir.actions.act_window">
4+
<field name="name">Offers</field>
5+
<field name="res_model">estate.property.offer</field>
6+
<field name="view_mode">list</field>
7+
<field name="domain">[('property_type_id', '=', active_id)]</field>
8+
</record>
9+
310
<record id="estate_property_offer_view_list" model="ir.ui.view">
411
<field name="name">estate.property.offer.list</field>
512
<field name="model">estate.property.offer</field>
613
<field name="arch" type="xml">
7-
<list string="Channel">
14+
<list string="Channel" editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
815
<field name="price"/>
916
<field name="partner_id" string="Partner"/>
1017
<field name="validity" string="Validity (days)"/>
1118
<field name="date_deadline" string="Deadline"/>
12-
<button name="action_accept_offer" type="object" icon="fa-check" string="Accept" invisible="not is_available"/>
13-
<button name="action_refuse_offer" type="object" icon="fa-times" string="Refuse"/>
14-
<field name="status"/>
19+
<button name="action_accept_offer" type="object" icon="fa-check" string="Accept" invisible="status"/>
20+
<button name="action_refuse_offer" type="object" icon="fa-times" string="Refuse" invisible="status"/>
1521
</list>
1622
</field>
1723
</record>

estate/views/estate_property_tag_views.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
<field name="view_mode">list,form</field>
77
</record>
88

9-
<record id="estate_property_type_view_form" model="ir.ui.view">
9+
<record id="estate_property_tag_view_list" model="ir.ui.view">
10+
<field name="name">estate.property.tag.list</field>
11+
<field name="model">estate.property.tag</field>
12+
<field name="arch" type="xml">
13+
<list string="Channel" editable="bottom">
14+
<field name="name" string="Tag"/>
15+
</list>
16+
</field>
17+
</record>
18+
19+
<record id="estate_property_tag_view_form" model="ir.ui.view">
1020
<field name="name">estate.property.tag.form</field>
1121
<field name="model">estate.property.tag</field>
1222
<field name="arch" type="xml">

estate/views/estate_property_type_views.xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,40 @@
66
<field name="view_mode">list,form</field>
77
</record>
88

9+
<record id="estate_property_type_view_list" model="ir.ui.view">
10+
<field name="name">estate.property.type.list</field>
11+
<field name="model">estate.property.type</field>
12+
<field name="arch" type="xml">
13+
<list string="Channel">
14+
<field name="sequence" widget="handle"/>
15+
<field name="name" string="Type"/>
16+
</list>
17+
</field>
18+
</record>
19+
920
<record id="estate_property_type_view_form" model="ir.ui.view">
1021
<field name="name">estate.property.type.form</field>
1122
<field name="model">estate.property.type</field>
1223
<field name="arch" type="xml">
13-
<form string="Propreties Types">
24+
<form string="Type">
25+
<header>
26+
<button class="oe_stat_button" type="action" name="%(estate.estate_property_offer_from_property_action)d" string="Offers"/>
27+
</header>
1428
<sheet>
1529
<h1>
16-
<field name="name"/>
30+
<field name="name" string="Type"/>
1731
</h1>
32+
<notebook>
33+
<page string="Properties">
34+
<field name="property_ids">
35+
<list>
36+
<field name="name" string="Title"/>
37+
<field name="expected_price"/>
38+
<field name="state" string="Status"/>
39+
</list>
40+
</field>
41+
</page>
42+
</notebook>
1843
</sheet>
1944
</form>
2045
</field>

estate/views/estate_property_views.xml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
<field name="name">Properties</field>
55
<field name="res_model">estate.property</field>
66
<field name="view_mode">list,form</field>
7+
<field name="context">{'search_default_available': True}</field>
78
</record>
89

910
<record id="estate_property_view_list" 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 string="Channel">
14+
<list string="Channel" decoration-success="offer_ids or buyer_id" decoration-bf="buyer_id" decoration-muted="state == 'cancelled'">
1415
<field name="name" string="Title"/>
1516
<field name="postcode"/>
17+
<field name="tag_ids" string="Tags" widget="many2many_tags" options="{'color_field': 'color'}"/>
1618
<field name="bedrooms"/>
1719
<field name="living_area" string="Living Area (sqm)"/>
1820
<field name="expected_price"/>
1921
<field name="selling_price"/>
20-
<field name="date_availability" string="Available From"/>
22+
<field name="date_availability" string="Available From" optional="hide"/>
2123
</list>
2224
</field>
2325
</record>
@@ -28,8 +30,9 @@
2830
<field name="arch" type="xml">
2931
<form string="Propreties">
3032
<header>
31-
<button name="action_set_sold" string="Sold" type="object"/>
32-
<button name="action_set_cancelled" string="Cancel" type="object"/>
33+
<button name="action_set_sold" string="Sold" type="object" invisible="state in ['sold', 'cancelled']"/>
34+
<button name="action_set_cancelled" string="Cancel" type="object" invisible="state in ['sold', 'cancelled']"/>
35+
<field name="state" widget="statusbar" statusbar_visible="new,received,accepted,sold"/>
3336
</header>
3437
<sheet>
3538
<h1>
@@ -39,6 +42,7 @@
3942
<group>
4043
<field name="postcode"/>
4144
<field name="date_availability"/>
45+
<field name="type_id" options="{'no_quick_create': true, 'no_create_edit': true}"/>
4246
</group>
4347
<group>
4448
<field name="expected_price"/>
@@ -55,14 +59,14 @@
5559
<field name="facades"/>
5660
<field name="garage"/>
5761
<field name="garden"/>
58-
<field name="garden_area" string="Garden Area (sqm)"/>
59-
<field name="garden_orientation"/>
62+
<field name="garden_area" string="Garden Area (sqm)" invisible="not garden"/>
63+
<field name="garden_orientation" invisible="not garden"/>
6064
<field name="total_area" string="Total Area (sqm)"/>
61-
<field name="tag_ids" widget="many2many_tags"/>
65+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': true}"/>
6266
</group>
6367
</page>
6468
<page string="Offers">
65-
<field name="offer_ids"/>
69+
<field name="offer_ids" readonly="state in ['sold', 'cancelled', 'accepted']"/>
6670
</page>
6771
<page string="More Info">
6872
<group>
@@ -85,7 +89,7 @@
8589
<field name="postcode"/>
8690
<field name="expected_price"/>
8791
<field name="bedrooms"/>
88-
<field name="living_area" string="Living Area (sqm)"/>
92+
<field name="living_area" string="Living Area (sqm)" filter_domain="[('living_area', '>=', self)]"/>
8993
<field name="facades"/>
9094
<filter string="Available" name="available" domain="['|', ('state', '=', 'new'), ('state', '=', 'received')]"/>
9195
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>

0 commit comments

Comments
 (0)