Skip to content

Commit 7e5c59e

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 5eb85ca commit 7e5c59e

File tree

9 files changed

+98
-25
lines changed

9 files changed

+98
-25
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
"license": "AGPL-3",

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 inherited_res_users

estate/models/estate_property.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from odoo import fields, models, api
2-
from odoo.exceptions import UserError,ValidationError
2+
from odoo.exceptions import UserError, ValidationError
33
from odoo.tools.float_utils import float_compare
44

55

6-
76
class EstateProperty(models.Model):
87
_name = "estate.property"
98
_description = "Estate Model"
@@ -30,7 +29,7 @@ class EstateProperty(models.Model):
3029
],
3130
)
3231

33-
active = fields.Boolean(default=False, string="Active")
32+
active = fields.Boolean(default=True, string="Active")
3433

3534
state = fields.Selection(
3635
selection=[
@@ -44,7 +43,7 @@ class EstateProperty(models.Model):
4443
copy=False,
4544
)
4645

47-
# property will have Many to one relation with property since many properties can belong to one property type
46+
# property will have Many to one relation with property type since many properties can belong to one property type
4847

4948
property_type_id = fields.Many2one("estate.property.type", "Property Type")
5049

@@ -71,17 +70,22 @@ class EstateProperty(models.Model):
7170

7271
best_price = fields.Integer(compute="_compute_best_price", string="Best Price")
7372

74-
7573
status = fields.Char(default="new", string="Status")
7674

7775
_order = "id desc"
7876

79-
80-
_sql_constraints = [('check_expected_price', 'CHECK(expected_price > 0)', 'Expected price must be strictly positive'),
81-
('check_selling_price', 'CHECK(selling_price >= 0)', 'Selling price should be positive')
77+
_sql_constraints = [
78+
(
79+
"check_expected_price",
80+
"CHECK(expected_price > 0)",
81+
"Expected price must be strictly positive",
82+
),
83+
(
84+
"check_selling_price",
85+
"CHECK(selling_price >= 0)",
86+
"Selling price should be positive",
87+
),
8288
]
83-
84-
8589

8690
@api.depends("garden_area", "living_area")
8791
def _compute_total_property_area(self):
@@ -135,22 +139,29 @@ def action_cancel_property_selling(self):
135139
else:
136140
raise UserError("Sold property cannot be cancelled.")
137141

138-
# constrains for the selling price
139-
140-
@api.constrains('selling_price', 'expected_price')
142+
# constrains for the selling price
141143

144+
@api.constrains("selling_price", "expected_price")
142145
def _check_selling_price(self):
143-
144146
for data in self:
145147
# if call will come after selling price change than it will allow updated price to work
146-
if data.selling_price <= 0 :
148+
if data.selling_price <= 0:
147149
return
148150

149-
price_float_ratio = (data.selling_price/self.expected_price)
150-
ratio_diffrence = float_compare(price_float_ratio,0.9, precision_digits=2)
151-
if ratio_diffrence == -1 :
151+
price_float_ratio = data.selling_price / self.expected_price
152+
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2)
153+
if ratio_diffrence == -1:
152154
data.selling_price = 0
153-
raise ValidationError('The selling price cannot be lower than 90% of the expected price')
154-
155-
155+
raise ValidationError(
156+
"The selling price cannot be lower than 90% of the expected price"
157+
)
158+
159+
# delete opration for the process
156160

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

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
@@ -43,9 +43,9 @@
4343
<field name="arch" type="xml">
4444
<form string="Property Info">
4545
<header>
46-
<button name="action_sell_property" type="object" string="Sold"/>
47-
<button name="action_cancel_property_selling" type="object" string="Cancel"/>
48-
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted, sold"/>
46+
<button name="action_sell_property" type="object" string="Mark As Sold" class="oe_highlight" invisible="state in ('sold','cancelled')"/>
47+
<button name="action_cancel_property_selling" type="object" string="Cancel" invisible="state in ('sold','cancelled')"/>
48+
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted, sold"/>
4949
</header>
5050

5151
<sheet>
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "Real Estate Invoicing",
3+
"category": "All",
4+
"application": True,
5+
"installable": True,
6+
"depends": ["base", "account", "estate"],
7+
}

0 commit comments

Comments
 (0)