Skip to content

Commit 1065ee5

Browse files
committed
[ADD] estate : extend CRUD operations and add property view under user
. Restrict deletion of properties unless their state is New or Cancelled . Automatically update property state to Offer Received when a new offer is created . Prevent creation of offers lower than existing highest offer . Display salesperson’s available properties directly on the user form . Introduce a new tab in user settings to manage linked properties
1 parent 9b50772 commit 1065ee5

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"views/estate_property_type_views.xml",
1111
"views/estate_property_tag_views.xml",
1212
"views/estate_menus.xml",
13+
"views/res_user_view.xml",
1314
],
1415
"license": "LGPL-3",
1516
}

estate/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from . import estate_property_type
33
from . import estate_property_tag
44
from . import estate_property_offer
5+
from . import res_users

estate/models/estate_property.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,12 @@ def action_property_cancelled(self):
121121
for offer in self.offer_ids:
122122
if not offer.status:
123123
offer.status = "refused"
124+
125+
@api.ondelete(at_uninstall=False)
126+
def _check_before_deleting_record(self):
127+
# more than one record can be present in recordset
128+
for record in self:
129+
if record.state in ["offer_received", "offer_accepted", "sold"]:
130+
raise UserError(
131+
"Properties with received offers, accepted offers, or that have been sold cannot be deleted."
132+
)

estate/models/estate_property_offer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def action_offer_confirm(self):
5858
self.status = "accepted"
5959
self.property_id.write(
6060
{
61-
"state": "offer_accepted",
6261
"buyer": self.partner_id,
6362
"selling_price": self.price,
6463
}
@@ -77,3 +76,16 @@ def action_offer_cancel(self):
7776
if record.status in ["accepted", "refused"]:
7877
raise UserError(f"Offer is already {record.status}")
7978
record.status = "refused"
79+
80+
@api.model_create_multi
81+
def create(self, vals):
82+
for record in vals:
83+
property = self.env["estate.property"].browse(record["property_id"])
84+
85+
if record.get("price") < property.best_price:
86+
raise UserError(
87+
"The offers price cannot be lower than the existing offers"
88+
)
89+
90+
property.state = "offer_received"
91+
return super().create(vals)

estate/models/res_users.py

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

estate/views/res_user_view.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
3+
<odoo>
4+
5+
<record id="inherited_res_user_form_view" model="ir.ui.view">
6+
<field name="name">Inherited User View</field>
7+
<field name="model">res.users</field>
8+
<field name="inherit_id" ref="base.view_users_form"/>
9+
<field name="arch" type="xml">
10+
<xpath expr="//notebook" position="inside">
11+
<page name="Real Estate Properties">
12+
<field name="property_ids" />
13+
</page>
14+
</xpath>
15+
</field>
16+
</record>
17+
18+
</odoo>

0 commit comments

Comments
 (0)