Skip to content

Commit 342118b

Browse files
committed
[IMP] estate: imp inheritance
1 parent b7a29bd commit 342118b

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'views/estate_property_offer_views.xml',
2020
'views/estate_property_type_views.xml',
2121
'views/estate_property_tag_views.xml',
22+
'views/estate_user_views.xml',
2223
'views/estate_menus.xml'
2324
],
2425
'demo': [

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 estate_user

estate/models/estate_property.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ def _check_selling_price(self):
105105
raise ValidationError(
106106
"The selling price cannot be lower than 90 precent of the expected price."
107107
)
108+
@api.ondelete(at_uninstall=False)
109+
def _unlink_if_valid_state(self):
110+
if any(record.state not in ('new', 'cancelled') for record in self):
111+
raise UserError("Can't delete a property that is not New or Cancelled!")

estate/models/estate_property_offer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ def action_refuse_offer(self):
5151
raise exceptions.UserError('You cant refuse an already accepted offer')
5252
record.status = 'refused'
5353
return True
54+
55+
@api.model
56+
def create(self, vals):
57+
for val in vals:
58+
linked_property = self.env['estate.property'].browse(val['property_id'])
59+
if val['price']< linked_property.best_price:
60+
raise exceptions.UserError("An offer with a higher price already exists")
61+
linked_property.state = 'offer_received'
62+
return super(EstatePropertyOffer, self).create(vals)

estate/models/estate_user.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from odoo import models, fields
2+
3+
class EstateUser(models.Model):
4+
_inherit = 'res.users'
5+
6+
property_ids = fields.One2many(
7+
'estate.property', 'sales_person_id',
8+
string='Real Estate Properties',
9+
domain=[('state', 'in', ('new','cancelled', 'offer_received'))]
10+
)

estate/views/estate_property_type_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<field name="name" placeholder="House" class="mb16" />
1212
</h1>
1313
</div>
14-
<button name="%(estate.estate_property_offer_action)d"
14+
<button name="%(estate.estate_property_action)d"
1515
type="action"
1616
string="Offers"
1717
class="oe_stat_button">

estate/views/estate_user_views.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<odoo>
2+
<record id="estate_user_view_form" model="ir.ui.view">
3+
<field name="name">res.users.view.form.estate</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 position="inside">
8+
<page string="Estate Properties">
9+
<field
10+
name="property_ids"
11+
filter_domain="[(property_ids.state, 'in', ('new', 'offer_received'))]"
12+
/>
13+
</page>
14+
</notebook>
15+
</field>
16+
</record>
17+
</odoo>

0 commit comments

Comments
 (0)