Skip to content

Commit c5e1685

Browse files
committed
[IMP] Estate: Improve relation between model\n create new models: estate_property_? offer, tag and type\n create one2many, many2one and many2many fields
1 parent b6990b9 commit c5e1685

11 files changed

+155
-12
lines changed

estate/__manifest__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
'security/ir.model.access.csv',
1313
'view/estate_property_views.xml',
1414
'view/estate_property_type_views.xml',
15+
'view/estate_property_tag_views.xml',
16+
'view/estate_property_offer_views.xml',
1517
'view/estate_menus.xml',
1618
],
1719
'license': 'LGPL-3',

estate/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import estate_property, estate_property_type
1+
from . import estate_property, estate_property_tag, estate_property_type, estate_property_offer

estate/models/estate_property.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2-
from odoo import fields, models
2+
from odoo import api, fields, models
33

44

55
class Estate(models.Model):
@@ -8,25 +8,29 @@ class Estate(models.Model):
88

99
name = fields.Char(required=True, default='Unknown')
1010
property_type_id = fields.Many2one('estate.property.type')
11+
tag_ids = fields.Many2many('estate.property.tag')
1112
last_seen = fields.Datetime('Last Seen', default=fields.Datetime.now)
1213
description = fields.Char(required=True)
1314
postcode = fields.Char()
14-
date_availability = fields.Date(
15-
default=fields.Date.today() + relativedelta(months=3), copy=False
16-
)
15+
date_availability = fields.Date(default=fields.Date.today() + relativedelta(months=3), copy=False)
1716
active = fields.Boolean(default=True)
1817
expected_price = fields.Float(required=True)
1918
selling_price = fields.Float(readonly=True, copy=False)
19+
best_offer = fields.Float(compute='_compute_best_offer')
20+
sales_person_id = fields.Many2one('res.users', string='Salesperson', default=lambda self: self.env.user)
21+
offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offer')
22+
buyer_id = fields.Many2one('res.partner', string='Customer')
2023
bedrooms = fields.Integer(default=2)
21-
living_area = fields.Integer()
2224
facades = fields.Integer()
2325
garage = fields.Boolean()
2426
garden = fields.Boolean()
25-
garden_area = fields.Integer()
2627
garden_orientation = fields.Selection(
2728
string='Orientation',
2829
selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')],
2930
)
31+
living_area = fields.Integer()
32+
garden_area = fields.Integer()
33+
total_area = fields.Float(compute='_compute_total_area')
3034
state = fields.Selection(
3135
string='State',
3236
selection=[
@@ -39,3 +43,18 @@ class Estate(models.Model):
3943
default='new',
4044
readonly=True,
4145
)
46+
47+
@api.depends('living_area', 'garden_area')
48+
def _compute_total_area(self):
49+
for record in self:
50+
record.total_area = record.living_area + record.garden_area
51+
52+
@api.depends('offer_ids')
53+
def _compute_best_offer(self):
54+
for record in self:
55+
all_price = record.offer_ids.mapped('price')
56+
if all_price:
57+
record.best_offer = max(all_price)
58+
else:
59+
record.best_offer = 0
60+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from dateutil.relativedelta import relativedelta
2+
from odoo import api, fields, models
3+
4+
5+
class EstateOffer(models.Model):
6+
_name = 'estate.property.offer'
7+
_description = 'It allows to create a new property offer'
8+
9+
price = fields.Float(required=True)
10+
validity = fields.Integer()
11+
date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date')
12+
create_date = fields.Date(default=fields.Date.today(), required=True)
13+
partner_id = fields.Many2one('res.partner', string='Customer')
14+
property_id = fields.Many2one('estate.property', string='Property')
15+
status= fields.Selection(
16+
string='State',
17+
selection=[
18+
('pending', 'Pending'),
19+
('accepted', 'Accepted'),
20+
('refused', 'Refused'),
21+
],
22+
default='pending',
23+
)
24+
25+
@api.depends('create_date', 'validity')
26+
def _compute_date_deadline(self):
27+
for record in self:
28+
if record.create_date:
29+
record.date_deadline = record.create_date + relativedelta(days=record.validity)
30+
else:
31+
record.date_deadline = fields.Date.today() + relativedelta(days=record.validity)
32+
33+
34+
def _inverse_date(self):
35+
for record in self:
36+
record.validity = (record.date_deadline - fields.Date.today()).days

estate/models/estate_property_tag.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import fields, models
2+
3+
4+
class EstateTags(models.Model):
5+
_name = 'estate.property.tag'
6+
_description = 'It allows to create a new property tag'
7+
8+
name = fields.Char(required=True)

estate/models/estate_property_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from dateutil.relativedelta import relativedelta
21
from odoo import fields, models
32

43

estate/security/ir.model.access.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
22
access_estate_property,access_estate_property,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
4+
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

estate/view/estate_menus.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<menuitem id='test_first_level_menu' name='First Level'>
44
<menuitem id='test_model_menu_action' action='action_test_action'/>
55
</menuitem>
6-
<menuitem id='property_type_menu' name='Property'>
6+
<menuitem id='property_type_menu' name='Settings'>
77
<menuitem id='property_type_menu_action' action='estate_property_type_action'/>
8+
<menuitem id='property_tag_menu_action' action='estate_property_tag_action'/>
9+
<menuitem id='property_offer_menu_action' action='estate_property_offer_action'/>
810
</menuitem>
911
</menuitem>
1012
</odoo>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<odoo>
2+
<record id="estate_offer_list_view_tree" model="ir.ui.view">
3+
<field name="name">estate.offer.main.list</field>
4+
<field name="model">estate.property.offer</field>
5+
<field name="arch" type="xml">
6+
<list string="Channel">
7+
<field name="property_id"/>
8+
<field name="partner_id"/>
9+
<field name="price"/>
10+
<field name="status"/>
11+
</list>
12+
</field>
13+
</record>
14+
15+
<record id="estate_offer_view_form" model="ir.ui.view">
16+
<field name="name">estate.offer.form</field>
17+
<field name="model">estate.property.offer</field>
18+
<field name="arch" type="xml">
19+
<form string="Estate Offer">
20+
<sheet>
21+
<h1 class="oe_title">
22+
<field name="property_id"/>
23+
</h1>
24+
<div class="row">
25+
<div class="col-12">
26+
<group>
27+
<field name="partner_id"/>
28+
<field name="price"/>
29+
<field name="status"/>
30+
<field name="validity"/>
31+
<field name="date_deadline"/>
32+
<field name="create_date"/>
33+
</group>
34+
</div>
35+
</div>
36+
</sheet>
37+
</form>
38+
</field>
39+
</record>
40+
41+
<record id='estate_property_offer_action' model='ir.actions.act_window'>
42+
<field name='name'>property_offer_action</field>
43+
<field name='res_model'>estate.property.offer</field>
44+
<field name='view_mode'>list,form</field>
45+
</record>
46+
</odoo>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<odoo>
2+
<record id="estate_tag_list_view_tree" model="ir.ui.view">
3+
<field name="name">estate.tag.main.list</field>
4+
<field name="model">estate.property.tag</field>
5+
<field name="arch" type="xml">
6+
<list string="Channel" editable="top">
7+
<field name="name"/>
8+
</list>
9+
</field>
10+
</record>
11+
12+
<record id='estate_property_tag_action' model='ir.actions.act_window'>
13+
<field name='name'>property_tag_action</field>
14+
<field name='res_model'>estate.property.tag</field>
15+
<field name='view_mode'>list</field>
16+
</record>
17+
</odoo>

estate/view/estate_property_views.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
<form string="Estate">
2323
<sheet>
2424
<h1 class="oe_title">
25-
<field name="name" class="mb16"/>
25+
<field name="name"/>
2626
</h1>
27+
<field name="tag_ids" widget="many2many_tags" class="mb16"/>
2728
<div class="row">
2829
<div class="col-6">
2930
<group>
@@ -35,6 +36,7 @@
3536
<group>
3637
<field name="expected_price"/>
3738
<field name="selling_price"/>
39+
<field name="best_offer"/>
3840
</group>
3941
</div>
4042
</div>
@@ -43,15 +45,25 @@
4345
<group>
4446
<field name="description"/>
4547
<field name="bedrooms"/>
46-
<field name="living_area"/>
4748
<field name="facades"/>
4849
<field name="garage"/>
4950
<field name="garden"/>
50-
<field name="garden_area"/>
5151
<field name="garden_orientation"/>
52+
<field name="garden_area"/>
53+
<field name="living_area"/>
54+
<field name="total_area"/>
5255
<field name="property_type_id"/>
5356
</group>
5457
</page>
58+
<page string="Other Info">
59+
<group>
60+
<field name="sales_person_id"/>
61+
<field name="buyer_id"/>
62+
</group>
63+
</page>
64+
<page string="Offers">
65+
<field name="offer_ids"/>
66+
</page>
5567
</notebook>
5668
</sheet>
5769
</form>

0 commit comments

Comments
 (0)