Skip to content

Commit b7a29bd

Browse files
committed
[IMP] estate: Add The Sprinkles
1 parent 3f82fdb commit b7a29bd

9 files changed

+67
-20
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
'data': [
1717
'security/ir.model.access.csv',
1818
'views/estate_property_views.xml',
19+
'views/estate_property_offer_views.xml',
1920
'views/estate_property_type_views.xml',
2021
'views/estate_property_tag_views.xml',
21-
'views/estate_property_offer_views.xml',
2222
'views/estate_menus.xml'
2323
],
2424
'demo': [

estate/models/estate_property.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EstateProperty(models.Model):
3535
copy=False,
3636
selection=[
3737
('new', 'New'),
38-
('offer_received','Offer Received'),
38+
('offer_received', 'Offer Received'),
3939
('offer_accepted', 'Offer Accepted'),
4040
('sold', 'Sold'),
4141
('cancelled', 'Cancelled')
@@ -66,6 +66,7 @@ def _compute_total_area(self):
6666
def _compute_best_price(self):
6767
for record in self:
6868
record.best_price = max(record.offer_ids.mapped('price'), default=0.0)
69+
6970
@api.onchange('garden')
7071
def _onchange_garden(self):
7172
if not self.garden:

estate/models/estate_property_offer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ class EstatePropertyOffer(models.Model):
1010
string='Status',
1111
default='new',
1212
copy=False,
13-
selection=[('accepted', 'Accepted'), ('refused', 'Refused'), ('new', 'New')])
13+
selection=[
14+
('accepted', 'Accepted'),
15+
('refused', 'Refused'),
16+
('new', 'New')
17+
])
1418
partner_id = fields.Many2one('res.partner', string='Buyer', required=True)
1519
property_id = fields.Many2one('estate.property', string='Estate Property', required=True)
1620
validity = fields.Integer('Validity', default=7)
1721
date_deadline = fields.Datetime('Deadline', compute='_compute_date_deadline', inverse='_inverse_date_deadline')
18-
22+
property_type_id = fields.Many2one(related='property_id.property_type_id', store=True)
1923
_check_positive_price = models.Constraint(
2024
'CHECK(price >= 0)',
2125
'The price must be positive.',
@@ -38,6 +42,7 @@ def action_accept_offer(self):
3842
record.status = 'accepted'
3943
record.property_id.buyer_id = record.partner_id
4044
record.property_id.selling_price = record.price
45+
record.property_id.state = 'offer_accepted'
4146
return True
4247

4348
def action_refuse_offer(self):

estate/models/estate_property_tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class EstatePropertyTag(models.Model):
66
_description = "Estate properties Tags"
77
_order = "name"
88
name = fields.Char('Name', required=True, translate=True)
9-
9+
color = fields.Integer('Color')
1010
_tags_uniq = models.Constraint(
1111
'unique(name)',
1212
"The tag name already exists",

estate/models/estate_property_type.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
22

33

44
class EstatePropertyType(models.Model):
@@ -8,7 +8,14 @@ class EstatePropertyType(models.Model):
88
name = fields.Char('Name', required=True, translate=True)
99
properties_ids = fields.One2many("estate.property", "property_type_id", "Properties")
1010
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
11+
offers_ids = fields.One2many("estate.property.offer", "property_type_id", "Offers")
12+
offers_count = fields.Integer(compute='_compute_offers_count')
1113
_types_uniq = models.Constraint(
1214
'unique(name)',
1315
"The type name already exists",
1416
)
17+
18+
@api.depends('offers_ids')
19+
def _compute_offers_count(self):
20+
for record in self:
21+
record.offers_count = len(record.offers_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,26 @@
2020
<field name="name">estate.property.offer.list</field>
2121
<field name="model">estate.property.offer</field>
2222
<field name="arch" type="xml">
23-
<list string="Offers">
23+
<list string="Offers" editable="bottom"
24+
decoration-success="status == 'accepted'"
25+
decoration-danger="status == 'refused'">
2426
<field name="price" />
2527
<field name="partner_id" />
2628
<field name="validity" />
2729
<field name="date_deadline" />
28-
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check" />
29-
<button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times" />
30+
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check"
31+
invisible="status != 'new'" />
32+
<button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times"
33+
invisible="status != 'new'" />
3034
<field name="status" />
3135
</list>
3236
</field>
3337
</record>
38+
39+
<record id="estate_property_offer_action" model="ir.actions.act_window">
40+
<field name="name">Property Offers</field>
41+
<field name="res_model">estate.property.offer</field>
42+
<field name="view_mode">list</field>
43+
<field name="domain">[('property_type_id', '=', active_id)]</field>
44+
</record>
3445
</odoo>

estate/views/estate_property_tag_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
</field>
1717
</record>
1818

19+
<record id="estate_property_tag_view_list" model="ir.ui.view">
20+
<field name="name">estate.property.tag.list</field>
21+
<field name="model">estate.property.tag</field>
22+
<field name="arch" type="xml">
23+
<list string="Types" multi_edit="1" editable="bottom" >
24+
<field name="name" />
25+
</list>
26+
</field>
27+
</record>
28+
1929
<record id="estate_property_tag_action" model="ir.actions.act_window">
2030
<field name="name">Estate Property Tags</field>
2131
<field name="res_model">estate.property.tag</field>

estate/views/estate_property_type_views.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
<field name="name" placeholder="House" class="mb16" />
1212
</h1>
1313
</div>
14+
<button name="%(estate.estate_property_offer_action)d"
15+
type="action"
16+
string="Offers"
17+
class="oe_stat_button">
18+
<field name="offers_count" widget="statinfo" />
19+
</button>
20+
1421
<notebook>
1522
<page string="Properties">
1623
<field name="properties_ids">
@@ -27,7 +34,7 @@
2734
</field>
2835
</record>
2936

30-
<record id="estate_property_view_list" model="ir.ui.view">
37+
<record id="estate_property_type_view_list" model="ir.ui.view">
3138
<field name="name">estate.property.type.list</field>
3239
<field name="model">estate.property.type</field>
3340
<field name="arch" type="xml">

estate/views/estate_property_views.xml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<field name="postcode" />
1111
<field name="expected_price" />
1212
<field name="bedrooms" />
13-
<field name="living_area" />
13+
<field name="living_area" filter_domain="[('living_area', '>=', self)]" />
1414
<field name="facades" />
1515
<separator />
1616
<filter string="Available properties" name="available_properties"
@@ -27,20 +27,23 @@
2727
<field name="arch" type="xml">
2828
<form string="Estate Property">
2929
<header>
30-
<button name="action_sold_property" type="object" string="Sold" />
31-
<button name="action_cancel_property" type="object" string="Cancel" />
30+
<button name="action_sold_property" type="object" string="Sold"
31+
invisible="state == 'sold'" />
32+
<button name="action_cancel_property" type="object" string="Cancel"
33+
invisible="state == 'sold'" />
3234
<field name="state" widget="statusbar" />
3335
</header>
3436
<sheet>
3537
<div class="oe_title">
3638
<h1 class="mb32">
3739
<field name="name" placeholder="House" class="mb16" />
3840
</h1>
39-
<field name="property_tags_ids" widget="many2many_tags" />
41+
<field name="property_tags_ids" widget="many2many_tags"
42+
options="{'color_field': 'color'}" />
4043
</div>
4144
<group>
4245
<group>
43-
<field name="property_type_id" />
46+
<field name="property_type_id" options="{'no_create_edit': true, 'no_create': true}" />
4447
<field name="postcode" />
4548
<field name="date_availability" />
4649
</group>
@@ -59,14 +62,14 @@
5962
<field name="facades" />
6063
<field name="garage" />
6164
<field name="garden" />
62-
<field name="garden_area" />
63-
<field name="garden_orientation" />
65+
<field name="garden_area" invisible="not garden" />
66+
<field name="garden_orientation" invisible="not garden" />
6467
<field name="total_area" />
6568
</group>
6669
</page>
6770
<page string="Offers">
6871
<group>
69-
<field name="offer_ids" />
72+
<field name="offer_ids" readonly="state in ('offer_accepted', 'sold', 'cancelled')" />
7073
</group>
7174
</page>
7275
<page string="Other Info">
@@ -85,15 +88,18 @@
8588
<field name="name">estate.property.list</field>
8689
<field name="model">estate.property</field>
8790
<field name="arch" type="xml">
88-
<list string="Properties">
91+
<list string="Properties"
92+
decoration-success="state in ('offer_received', 'offer_accepted')"
93+
decoration-bf="state == 'offer_accepted'"
94+
decoration-muted="state == 'sold'">
8995
<field name="name" string="Title" />
9096
<field name="property_type_id" />
9197
<field name="postcode" />
9298
<field name="bedrooms" />
9399
<field name="living_area" />
94100
<field name="expected_price" />
95101
<field name="selling_price" />
96-
<field name="date_availability" />
102+
<field name="date_availability" optional="hide" />
97103
</list>
98104
</field>
99105
</record>

0 commit comments

Comments
 (0)