Skip to content

Commit 6fc8809

Browse files
committed
[IMP] estate: enhance property management with new views, ordering, and field adjustments
1 parent 2afca8f commit 6fc8809

10 files changed

+139
-28
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
'data': [
1212
'security/ir.model.access.csv',
1313
'views/estate_property_views.xml',
14+
'views/estate_property_offer_views.xml',
1415
'views/estate_property_type_views.xml',
1516
'views/estate_property_tag_views.xml',
16-
'views/estate_property_offer_views.xml',
1717
'views/estate_menus.xml',
1818
],
1919
}

estate/models/estate_property.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstateProperty(models.Model):
77
_name = 'estate.property'
88
_description = 'Property'
9+
_order = 'id desc'
910

1011
name = fields.Char('Title', required=True)
1112
description = fields.Text('Description')
@@ -49,8 +50,8 @@ class EstateProperty(models.Model):
4950
)
5051
property_type_id = fields.Many2one('estate.property.type', string='Property Types')
5152
property_tag_ids = fields.Many2many('estate.property.tag', string='Property Tags')
52-
buyer = fields.Many2one('res.partner', string='Buyer', copy=False)
53-
salesperson = fields.Many2one(
53+
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False)
54+
salesperson_id = fields.Many2one(
5455
'res.users', string='Salesperson', default=lambda self: self.env.user
5556
)
5657
offer_ids = fields.One2many(
@@ -71,10 +72,7 @@ def _compute_total_area(self):
7172
@api.depends('offer_ids.price')
7273
def _compute_best_price(self):
7374
for property in self:
74-
if len(self.offer_ids):
75-
property.best_price = max(property.offer_ids.mapped('price'))
76-
else:
77-
property.best_price = 0
75+
property.best_price = max(property.offer_ids.mapped('price'), default=0.0)
7876

7977
@api.onchange('garden')
8078
def _onchange_garden(self):
@@ -88,6 +86,9 @@ def _onchange_garden(self):
8886
@api.constrains('selling_price', 'expected_price')
8987
def _check_selling_price(self):
9088
for property in self:
89+
if property.state != 'offer_accepted':
90+
continue
91+
9192
if (
9293
property.state == 'offer_accepted'
9394
and float_compare(property.selling_price, 0, 2) == -1

estate/models/estate_property_offer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Property Offer"
9+
_order = 'price desc'
910

1011
price = fields.Float('Price')
1112
status = fields.Selection(
@@ -24,6 +25,9 @@ class EstatePropertyOffer(models.Model):
2425
date_deadline = fields.Date(
2526
'Deadline', compute='_compute_date_deadline', inverse='_inverse_date_deadline'
2627
)
28+
property_type_id = fields.Many2one(
29+
related='property_id.property_type_id', store=True
30+
)
2731

2832
_check_price = models.Constraint(
2933
'CHECK(price > 0)', 'The price must be strictly positive.'
@@ -50,7 +54,7 @@ def action_accept(self):
5054

5155
offer.status = 'accepted'
5256
offer.property_id.state = 'offer_accepted'
53-
offer.property_id.buyer = offer.partner_id
57+
offer.property_id.buyer_id = offer.partner_id
5458
offer.property_id.selling_price = offer.price
5559
return True
5660

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 EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Property Tag"
7+
_order = 'name'
78

89
name = fields.Char('Tag', required=True)
10+
color = fields.Integer('Color')
911

1012
_name_uniq = models.Constraint(
1113
'unique(name)', 'A tag with the same name already exists.'
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

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

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

1019
_name_uniq = models.Constraint(
1120
'unique(name)', 'A type with the same name already exists.'
1221
)
22+
23+
@api.depends('offer_ids')
24+
def _compute_offer_count(self):
25+
for type in self:
26+
type.offer_count = len(type.offer_ids)

estate/security/ir.model.access.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
22
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
33
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
44
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
5-
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
5+
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1

estate/views/estate_property_offer_views.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@
2222
<field name="name">estate.property.offer.list</field>
2323
<field name="model">estate.property.offer</field>
2424
<field name="arch" type="xml">
25-
<list string="Offers">
25+
<list string="Offers" editable="bottom" decoration-danger="status == 'refused'"
26+
decoration-success="status == 'accepted'">
2627
<field name="price" />
2728
<field name="partner_id" />
2829
<field name="validity" />
2930
<field name="date_deadline" />
30-
<button name="action_accept" type="object" icon="fa-check" title="Accept" />
31-
<button name="action_refuse" type="object" icon="fa-times" title="Refuse" />
32-
<field name="status" />
31+
<button name="action_accept" type="object" icon="fa-check" title="Accept"
32+
invisible='status' />
33+
<button name="action_refuse" type="object" icon="fa-times" title="Refuse"
34+
invisible='status' />
3335
</list>
3436
</field>
3537
</record>
36-
</odoo>
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,form</field>
43+
<field name="domain">[('property_type_id', '=', active_id)]</field>
44+
</record>
45+
</odoo>

estate/views/estate_property_tag_views.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<odoo>
3+
<record id='estate_property_tag_view_form' model='ir.ui.view'>
4+
<field name='name'>estate.property.tag.form</field>
5+
<field name='model'>estate.property.tag</field>
6+
<field name='arch' type='xml'>
7+
<form string='Tag'>
8+
<sheet>
9+
<group>
10+
<field name='name' />
11+
<field name='color' widget='color_picker' />
12+
</group>
13+
</sheet>
14+
</form>
15+
</field>
16+
</record>
17+
18+
<record id='estate_property_tag_view_tree' model='ir.ui.view'>
19+
<field name='name'>estate.property.tag.list</field>
20+
<field name='model'>estate.property.tag</field>
21+
<field name='arch' type='xml'>
22+
<list string='Tags' editable='bottom'>
23+
<field name='name' />
24+
<field name='color' widget='color_picker' />
25+
</list>
26+
</field>
27+
</record>
28+
329
<record id="estate_property_tag_action" model="ir.actions.act_window">
430
<field name="name">Property Tags</field>
531
<field name="res_model">estate.property.tag</field>

estate/views/estate_property_type_views.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<odoo>
3+
<record id='estate_property_type_view_form' model='ir.ui.view'>
4+
<field name='name'>estate.property.type.form</field>
5+
<field name='model'>estate.property.type</field>
6+
<field name='arch' type='xml'>
7+
<form string='Property Types'>
8+
<header>
9+
<button class='oe_stat_button' string='Offers' type='action'
10+
name='%(estate.estate_property_offer_action)d' />
11+
</header>
12+
<sheet>
13+
<div class='oe_title mb-4'>
14+
<h1>
15+
<field name='name' />
16+
</h1>
17+
</div>
18+
<notebook>
19+
<page string='Properties'>
20+
<field name='property_ids'>
21+
<list>
22+
<field name='name' />
23+
<field name='expected_price' />
24+
<field name='state' />
25+
</list>
26+
</field>
27+
</page>
28+
</notebook>
29+
</sheet>
30+
</form>
31+
</field>
32+
</record>
33+
34+
<record id="estate_property_type_view_tree" model="ir.ui.view">
35+
<field name="name">estate.property.type.list</field>
36+
<field name="model">estate.property.type</field>
37+
<field name="arch" type="xml">
38+
<list string="Property Types">
39+
<field name='sequence' widget='handle' />
40+
<field name="name" />
41+
</list>
42+
</field>
43+
</record>
44+
345
<record id="estate_property_type_action" model="ir.actions.act_window">
446
<field name="name">Property Types</field>
547
<field name="res_model">estate.property.type</field>

estate/views/estate_property_views.xml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<field name="postcode" />
1212
<field name="expected_price" />
1313
<field name="bedrooms" />
14-
<field name="living_area" />
14+
<field name="living_area" filter_domain="[('living_area', '>=', self)]" />
1515
<field name="facades" />
16-
<filter string="Available" name="state"
16+
<filter name="state" string="Available"
1717
domain="[('state', 'in', ('new', 'offer_received'))]" />
1818
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}" />
1919
</search>
@@ -26,19 +26,23 @@
2626
<field name="arch" type="xml">
2727
<form string="Property">
2828
<header>
29-
<button name='action_set_property_as_sold' type='object' string='Sold' />
30-
<button name='action_set_property_as_canceled' type='object' string='Cancel' />
29+
<button name='action_set_property_as_sold' type='object' string='Sold'
30+
invisible='state in ("canceled", "sold")' />
31+
<button name='action_set_property_as_canceled' type='object' string='Cancel'
32+
invisible='state in ("canceled", "sold")' />
33+
<field name='state' widget='statusbar' />
3134
</header>
3235
<sheet>
3336
<div class="oe_title mb-4">
3437
<h1>
3538
<field name="name" />
3639
</h1>
37-
<field name="property_tag_ids" widget="many2many_tags" />
40+
<field name="property_tag_ids" widget="many2many_tags"
41+
options="{'color_field': 'color'}" />
3842
</div>
3943
<group>
4044
<group>
41-
<field name="property_type_id" />
45+
<field name="property_type_id" options='{"no_create": true}' />
4246
<field name="postcode" />
4347
<field name="date_availability" />
4448
</group>
@@ -57,18 +61,20 @@
5761
<field name="facades" />
5862
<field name="garage" />
5963
<field name="garden" />
60-
<field name="garden_area" />
61-
<field name="garden_orientation" />
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"
71+
readonly='state in ("offer_accepted", "sold", "canceled")'
72+
/>
6773
</page>
6874
<page string="Other info">
6975
<group>
70-
<field name="salesperson" />
71-
<field name="buyer" />
76+
<field name="salesperson_id" />
77+
<field name="buyer_id" />
7278
</group>
7379
</page>
7480
</notebook>
@@ -81,15 +87,21 @@
8187
<field name="name">estate.property.list</field>
8288
<field name="model">estate.property</field>
8389
<field name="arch" type="xml">
84-
<list string="Properties">
90+
<list string="Properties"
91+
decoration-success="state in ('offer_received', 'offer_accepted')"
92+
decoration-bf="state == 'offer_accepted'"
93+
decoration-muted="state == 'sold'">
8594
<field name="name" />
8695
<field name="property_type_id" />
8796
<field name="postcode" />
97+
<field name="property_tag_ids" widget="many2many_tags"
98+
options="{'color_field': 'color'}"
99+
/>
88100
<field name="bedrooms" />
89101
<field name="living_area" />
90102
<field name="expected_price" />
91103
<field name="selling_price" />
92-
<field name="date_availability" />
104+
<field name="date_availability" optional="hide" />
93105
</list>
94106
</field>
95107
</record>
@@ -98,5 +110,6 @@
98110
<field name="name">Property</field>
99111
<field name="res_model">estate.property</field>
100112
<field name="view_mode">list,form</field>
113+
<field name="context">{'search_default_state': True}</field>
101114
</record>
102115
</odoo>

0 commit comments

Comments
 (0)