Skip to content

Commit

Permalink
[ADD] real_estate: added inheritance in the module
Browse files Browse the repository at this point in the history
This commit extends the Real Estate module by incorporating three types of
inheritance:

Python inheritance: Applied Python inheritance to streamline code
structure, promoting reusability and maintainability.

Model inheritance: Utilized Odoo's model inheritance features to extend existing
models, adding new fields and behaviors while preserving core functionalities.

View inheritance: Employed view inheritance to customize and enrich user
interfaces, ensuring seamless integration with existing elements.
  • Loading branch information
span-odoo committed Sep 18, 2024
1 parent 2bbbbe9 commit f44c91d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 13 deletions.
1 change: 1 addition & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"views/estate_property_type_view.xml",
"views/estate_property_tag_view.xml",
"views/estate_menu.xml",
"views/res_users.xml",
],
}
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
9 changes: 8 additions & 1 deletion estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class EstateProperty(models.Model):
("canceled", "Canceled"),
],
default="new",
readonly=True,
)
active = fields.Boolean(default=True)
saler_id = fields.Many2one(
Expand Down Expand Up @@ -74,8 +75,8 @@ def _compute_area(self):
def _compute_bestprice(self):
for record in self:
if record.offer_ids:
max1 = 0
for i in record.offer_ids:
max1 = 0
if i.price > max1:
max1 = i.price
record.best_price = max1
Expand All @@ -102,6 +103,12 @@ def _check_selling_price(self):
raise ValidationError(
"the selling price cannot be lower than 90'%' of the expected price."
)
#creating a delection check function that will check if the property is sold or not
@api.ondelete(at_uninstall=False)
def _check_property(self):
if any(user.state not in ("new", "canceled") for user in self):
raise UserError("You can't delete a property that is in process.")


# created the action for the sold button that will chage the state field of the property to sold
def action_sold(self):
Expand Down
17 changes: 11 additions & 6 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from odoo import api, models, fields
from dateutil.relativedelta import relativedelta
from datetime import date
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError


class EstateProperty(models.Model):
Expand Down Expand Up @@ -39,18 +39,23 @@ def _compute_deadline(self):
record.create_date = date.today()
record.deadline = record.create_date + relativedelta(days=record.Validity)

@api.onchange("name")
def _onchange_offer(self):
if self.name:
self.property_id.state = "offer_recieved"

# created the inverse function that will compute the validity when we manually update the deadline i.e deadline - creation date
def _inverse_deadline(self):
for record in self:
record.Validity = (
record.deadline.toordinal() - record.create_date.toordinal()
)

# create a create model that will make status as offer recieved when we create the offer
@api.model
def create(self, vals):
record = super().create(vals)
if record.price < record.property_id.best_price:
raise ValidationError("One of the offer is present which is best than your offer.")
record.property_id.state = "offer_recieved"
return record


# created the action for the accept button that will accept the offer from the offers for a property.
def action_accept(self):
# checks weather any other offer is alredy accepted. if offer is alredy accepted then it will raise an error
Expand Down
7 changes: 7 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class resuserinherit(models.Model):
_inherit = "res.users"

property_ids = fields.One2many("estate.property", "saler_id")
15 changes: 9 additions & 6 deletions estate/views/estate_property_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form string="estate property type form ">
<header>
<button type="action" name="%(estate.action_open_offer)d" string="Offer"
icon="fa-money" class="oe_stat_button">
<field name="offer_count" string="Offer Count" class="oe_stat_button" />
</button>
</header>
<sheet>
<div class="d-flex justify-content-end">
<header>
<button type="action" name="%(estate.action_open_offer)d" string="Offer"
icon="fa-money" class="oe_stat_button">
<field name="offer_count" class="oe_stat_button"
string="Offers Count"/> Offers
</button>
</header>
</div>
<div>
<H1>
<field name="name"></field>
Expand Down
24 changes: 24 additions & 0 deletions estate/views/res_users.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<odoo>
<record id="inherited_res_users_form" model="ir.ui.view">
<field name="name">inherited.res.user</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form" />
<field name="arch" type="xml">
<!-- find field description and add the field
new_field after it -->
<xpath expr="//page[@name='preferences']" position="after">
<page string="Real Estate Properties">
<field name="property_ids">
<tree>
<field name='name' string='Title' />
<field name='state' string='Status' />
<field name='selling_price' string='Selling Price' />
<field name='expected_price' string='Expected Price' />
</tree>
</field>

</page>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions estate_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Estate Account",
"version": "0.1",
"license": "LGPL-3",
"category": "Estate_props",
"author": "sahilpanghal(span)",
"summary": "Estate Account",
"description": "Estate Account",
"application": True,
"installable": True,
"auto_install": True,
"depends": ["base","account","estate"],
"data": [],
}

0 comments on commit f44c91d

Please sign in to comment.