Skip to content

Commit 54ed146

Browse files
committed
[IMP] estate: add inheritance and module interaction features
Added model and view inheritance for extending existing functionality., Implemented interaction with external modules using dependencies., Updated estate module to demonstrate cross-module field access and method calls.
1 parent 5e5b2db commit 54ed146

File tree

9 files changed

+84
-7
lines changed

9 files changed

+84
-7
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'views/estate_property_offer_views.xml',
1010
'views/estate_property_type_views.xml',
1111
'views/estate_menus.xml',
12+
'views/inherit_res_users_view.xml',
1213
'security/ir.model.access.csv'
1314

1415
]

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 inherited_res_users

estate/models/estate_property.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EstateProperty(models.Model):
2929
selection=[('north', 'North'), ('south', 'South'),('east', 'East'),('west', 'West')],
3030
)
3131

32-
active = fields.Boolean(default=False)
32+
active = fields.Boolean(default=True)
3333

3434
state = fields.Selection(
3535
selection=[
@@ -41,7 +41,7 @@ class EstateProperty(models.Model):
4141
copy = False
4242
)
4343

44-
# property will have Many to one relation with property since many properties can belong to one property type
44+
# property will have Many to one relation with property type since many properties can belong to one property type
4545

4646
property_type_id = fields.Many2one("estate.property.type", "Property Type")
4747

@@ -116,6 +116,7 @@ def action_sell_property(self):
116116
print("the object on sell action", record.read())
117117
if property_sell_status_dict[record.status]:
118118
record.status = 'sold'
119+
record.state = 'sold'
119120
return
120121
raise UserError('Cancelled property cannot be sold.')
121122

@@ -157,5 +158,16 @@ def _check_selling_price(self):
157158

158159

159160

161+
# delete opration for the process
162+
163+
164+
@api.ondelete(at_uninstall=False)
165+
def _unlink_if_state_new_or_cancelled(self):
166+
for data in self:
167+
if not bool(self.state == 'new' or self.state == 'cancelled') :
168+
raise UserError("Can't delete property which is not in new or cancelled state!")
169+
170+
171+
160172

161173

estate/models/estate_property_offer.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from datetime import datetime
1111
from dateutil.relativedelta import relativedelta
1212
from odoo.exceptions import UserError
13+
from odoo.tools.float_utils import float_compare
14+
1315

1416
class EstatePropertyOffer(models.Model):
1517
_name = 'estate.property.offer'
@@ -84,4 +86,23 @@ def action_offer_refuse(self):
8486
record.status = 'refused'
8587

8688

87-
89+
90+
# now in case of offer creation CRUD
91+
# self will be a proxy object ,
92+
# property_id feilds is available in vals
93+
@api.model_create_multi
94+
def create(self, vals):
95+
96+
# will check the offer value and does property has other offers which are max thw\an this one
97+
for value in vals:
98+
property_details = self.env['estate.property'].browse(value.get('property_id'))
99+
for property_data in property_details:
100+
offers_list = property_data.mapped("offer_ids.price")
101+
max_offer = max(offers_list, default=0)
102+
comparison_result = float_compare(value.get('price'),max_offer, precision_digits=2)
103+
104+
if comparison_result == -1 :
105+
raise UserError('Offer with a lower amount than an existing offer')
106+
107+
return super().create(vals)
108+

estate/models/inherited_res_users.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
# This model inherits from res.users model
4+
5+
from odoo import models, fields
6+
7+
class InheritedResUsers(models.Model):
8+
_inherit = 'res.users'
9+
property_ids = fields.One2many('estate.property', 'user_id', "Estate Property",
10+
domain=[('state', 'in', ['new','offer_received'])]
11+
)
12+

estate/views/estate_property_views.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
<field name="arch" type="xml">
4040
<form string="Property Info">
4141
<header>
42-
<button name="action_sell_property" type="object" string="Sold"/>
43-
<button name="action_cancel_property_selling" type="object" string="Cancel"/>
44-
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted, sold"/>
42+
<button name="action_sell_property" type="object" string="Mark As Sold" class="oe_highlight" invisible="state in ('sold','cancelled')"/>
43+
<button name="action_cancel_property_selling" type="object" string="Cancel" invisible="state in ('sold','cancelled')"/>
44+
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted, sold"/>
4545
</header>
4646
<sheet>
4747
<div class="oe_title">
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
<odoo>
3+
<data>
4+
5+
<record id="res_users_view_form" model="ir.ui.view">
6+
<field name="name">res.users.view.form.inherit.estate.property</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+
<notebook position="inside">
11+
<page name="estate.properties" string="Real Estate Properties">
12+
<field name="property_ids"/>
13+
14+
</page>
15+
</notebook>
16+
</field>
17+
</record>
18+
19+
</data>
20+
</odoo>

estate_account/__init__.py

Whitespace-only changes.

estate_account/__manifest__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
'name': 'Real Estate Invoicing',
3+
'category': 'All',
4+
'application': True,
5+
'installable': True,
6+
'depends' : ['base','account', 'estate'],
7+
'data': [
8+
9+
]
10+
}

0 commit comments

Comments
 (0)