Skip to content

Commit 6422caa

Browse files
committed
Chapter 12
1 parent 43a6688 commit 6422caa

8 files changed

Lines changed: 55 additions & 18 deletions

estate/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'views/estate_property_offers_views.xml',
1616
'views/estate_property_types_views.xml',
1717
'views/estate_property_views.xml',
18-
'views/estate_menus.xml'
18+
'views/estate_menus.xml',
19+
'views/res_users_views.xml'
1920
]
2021
}

estate/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . import estate_property
22
from . import estate_property_type
33
from . import estate_property_tag
4-
from . import estate_property_offer
4+
from . import estate_property_offer
5+
from . import res_users

estate/models/estate_property.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def _onchange_garden(self):
8888
self.garden_area = False
8989
self.garden_orientation = False
9090

91+
@api.ondelete(at_uninstall=False)
92+
def _unlike_property(self):
93+
for record in self:
94+
if record.state != 'new' and record.state != 'canceled':
95+
raise exceptions.UserError("You cannot delete this property: only new and canceled properities can be deleted.")
96+
9197
def action_mark_as_sold(self):
9298
for record in self:
9399
if record.state != 'canceled':

estate/models/estate_property_offer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def _inverse_date_deadline(self):
3434
for record in self:
3535
record.validity = (record.date_deadline-fields.Date.to_date(record.create_date)).days
3636

37+
@api.model
38+
def create(self, vals_list):
39+
for vals in vals_list:
40+
related_property = self.env['estate.property'].browse(vals['property_id'])
41+
for offer in related_property.offer_ids:
42+
if offer.price > vals['price']:
43+
raise exceptions.UserError("This offer price is lower than the current ones")
44+
45+
return super().create(vals_list)
46+
3747
def action_accept_offer(self):
3848
for record in self:
3949
if record.status == 'accepted':

estate/models/res_users.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from odoo import api, fields, models, exceptions
2+
from dateutil.relativedelta import relativedelta
3+
4+
5+
class ResUsers(models.Model):
6+
_inherit = 'res.users'
7+
_name = 'res.users'
8+
9+
property_ids = fields.One2many('estate.property', 'seller_id',
10+
domain=['|', ('state', '=', 'new'), ('state', '=', 'offer received')])

estate/views/estate_property_offers_views.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<field name="partner_id" string="Partner"/>
99
<field name="validity" string="Validity (Days)"/>
1010
<field name="date_deadline" string="Deadline"/>
11+
<field name="property_id" invisible="1"/> <!-- just to use it in the offer creation constraints-->
1112
<button name="action_accept_offer" string=" " type="object" icon="fa-check" invisible="status"/>
1213
<button name="action_refuse_offer" string=" " type="object" icon="fa-times" invisible="status"/>
1314
</list>

estate/views/estate_property_types_views.xml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55
<field name="arch" type="xml">
66
<form>
77
<field name="name" nolable="1"/>
8-
<div class="oe_button_box" name="button_box">
9-
<!-- <button name="action_schedule_meeting" type="object"
10-
class="oe_stat_button" icon="fa-calendar"
11-
context="{'partner_id': partner_id}"
12-
attrs="{'invisible': [('type', '=', 'lead')]}">
13-
<div class="o_stat_info">
14-
<field name="meeting_count" class="o_stat_value"/>
15-
<span class="o_stat_text" attrs="{'invisible': [('meeting_count', '&lt;', 2)]}"> Meetings</span>
16-
<span class="o_stat_text" attrs="{'invisible': [('meeting_count', '&gt;', 1)]}"> Meeting</span>
17-
</div>
18-
</button> -->
19-
<button name="%(estate_property_offer_action)d" type="action"
20-
class="oe_stat_button" icon="fa-money" string="Offers">
21-
<field name="offer_count"/>
22-
</button>
23-
</div>
8+
<div class="oe_button_box" name="button_box">
9+
<button name="%(estate_property_offer_action)d" type="action"
10+
class="oe_stat_button" icon="fa-money" string="Offers">
11+
<div class="o_stat_info">
12+
<field name="offer_count" class="o_stat_value"/>
13+
</div>
14+
</button>
15+
</div>
2416
<notebook>
2517
<page string="Properties">
2618
<field name="property_ids">

estate/views/res_users_views.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<odoo>
2+
<record id="res_users_view_form" model="ir.ui.view">
3+
<field name="name">res.users.view.form.inherit.gamification</field>
4+
<field name="model">res.users</field>
5+
<field name="inherit_id" ref="base.view_users_form"/>
6+
<field name="arch" type="xml">
7+
<notebook>
8+
<page string="Real Estate Properties">
9+
<group>
10+
<field name="property_ids" nolabel="1"/>
11+
</group>
12+
</page>
13+
</notebook>
14+
</field>
15+
</record>
16+
</odoo>

0 commit comments

Comments
 (0)