Skip to content

Commit 99621c5

Browse files
committed
[IMP] estate : added display of the user's assigned properties
1 parent 1dbcf04 commit 99621c5

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'depends': ['base'],
66
'data': [
77
'security/ir.model.access.csv',
8+
'views/res_users_views.xml',
89
'views/estate_property_offer_view.xml',
910
'views/estate_property_view.xml',
1011
'views/estate_property_type_view.xml',

estate/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
estate_property_offer,
44
estate_property_tag,
55
estate_property_type,
6+
res_user,
67
)

estate/models/estate_property.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ def _check_expected_price(self):
113113
for offer in record.offer_ids:
114114
if offer.status == "yes" and float_compare(offer.price, 0.9 * record.expected_price, 2) < 0:
115115
raise ValidationError("There is an accepted offer for an amount less than 90 percent of the new selling price, action required!")
116+
117+
@api.ondelete(at_uninstall=False)
118+
def _unlink_property(self):
119+
if self.state not in ('new', 'cancelled'):
120+
raise ValidationError("Only new and canceled properties can be deleted.")

estate/models/estate_property_offer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def create(self, vals_list):
1818
for record in records:
1919
if record.property_id.state == "new":
2020
record.property_id.state = "offer_received"
21+
## Another way is to leave the super.create() at the end of the function and browse for the property by id
2122
return records
2223

2324
price = fields.Float("Expected Price")
@@ -38,7 +39,7 @@ def create(self, vals_list):
3839
required=True,
3940
)
4041
property_id = fields.Many2one(
41-
'estate.property', string='Property', ondelete='restrict', required=True,
42+
'estate.property', string='Property', ondelete='cascade', required=True,
4243
)
4344
property_type_id = fields.Many2one(
4445
related='property_id.property_type_id', string='Property Type', store=True,
@@ -78,3 +79,5 @@ def _check_offered_price(self):
7879
for record in self:
7980
if float_compare(record.price, 0.9 * record.property_id.expected_price, 2) < 0:
8081
raise ValidationError("Offer price cannot be less than 90 percent of property price")
82+
if float_compare(record.price, record.property_id.best_offer, 2) < 0:
83+
raise ValidationError(_("The offer must be higher than %s", str(record.property_id.best_offer)))

estate/models/res_user.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import fields, models
2+
3+
4+
class ResUsers(models.Model):
5+
6+
_inherit = "res.users"
7+
property_ids = fields.One2many("estate.property", "salesperson_id", string="Assigned Properties")

estate/views/res_users_views.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<data>
4+
<record id="res_users_view_form" model="ir.ui.view">
5+
<field name="name">res.users.view.form.inherit.estate</field>
6+
<field name="model">res.users</field>
7+
<field name="inherit_id" ref="base.view_users_form"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//page[@name='calendar']" position="after">
10+
<page string="Assigned Properties">
11+
<group>
12+
<field name="property_ids" domain="[('active','=','true')]"/>
13+
</group>
14+
</page>
15+
</xpath>
16+
</field>
17+
</record>
18+
</data>
19+
</odoo>

0 commit comments

Comments
 (0)