Skip to content

Commit

Permalink
[IMP] estate: minor PR changes
Browse files Browse the repository at this point in the history
Refactored code according to common coding guidelines followed here.
  • Loading branch information
nipl-odoo committed Jan 17, 2025
1 parent 1261bf9 commit 1ad40ed
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 81 deletions.
20 changes: 12 additions & 8 deletions estate/controllers/estate_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EstateWebsite(http.Controller):
@http.route(
["/properties", "/properties/page/<int:page>"],
type="http",
auth="user",
auth="public",
website=True,
)
def list_properties(self, page=1, **kwargs):
Expand All @@ -28,12 +28,16 @@ def list_properties(self, page=1, **kwargs):
)
)

total_properties = request.env["estate.property"].sudo().search_count(
[
"&",
("status", "in", ["new", "offer_received", "offer_accepted"]),
("active", "=", True),
]
total_properties = (
request.env["estate.property"]
.sudo()
.search_count(
[
"&",
("status", "in", ["new", "offer_received", "offer_accepted"]),
("active", "=", True),
]
)
)

pager = request.website.pager(
Expand All @@ -49,7 +53,7 @@ def list_properties(self, page=1, **kwargs):
@http.route(
"/property/<model('estate.property'):property>",
type="http",
auth="user",
auth="public",
website=True,
)
def property_detail(self, property, **kwargs):
Expand Down
10 changes: 4 additions & 6 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from odoo import models, fields, api
from odoo.exceptions import UserError
from datetime import datetime
from dateutil.relativedelta import relativedelta

from odoo import api, fields, models
from odoo.exceptions import UserError


class EstateProperty(models.Model):
_name = "estate.property"
Expand All @@ -18,7 +19,6 @@ class EstateProperty(models.Model):
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer()

living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
Expand Down Expand Up @@ -60,6 +60,7 @@ class EstateProperty(models.Model):
"res.company", default=lambda self: self.env.company, required=True
)
image = fields.Image("Image")

_sql_constraints = [
(
"check_expected_price",
Expand Down Expand Up @@ -138,7 +139,4 @@ def action_make_offer(self):
"target": "new",
"view_mode": "form",
"res_model": "estate.property.make.offer",
"context": {
"default_property_ids": self.ids,
},
}
5 changes: 3 additions & 2 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from odoo import models, fields, api
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.tools.float_utils import float_compare

from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare


class EstatePropertyOffer(models.Model):
Expand Down
3 changes: 2 additions & 1 deletion estate/models/estate_property_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from odoo import models, fields
import random

from odoo import fields, models


class EstatePropertyTags(models.Model):
_name = "estate.property.tags"
Expand Down
9 changes: 5 additions & 4 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import fields, models


class EstatePropertyType(models.Model):
Expand All @@ -8,14 +8,15 @@ class EstatePropertyType(models.Model):

name = fields.Char(required=True)
property_ids = fields.One2many("estate.property", "property_type_id")
_sql_constraints = [
("name_uniq", "unique(name)", "Type must be unique"),
]
offer_ids = fields.One2many(
comodel_name="estate.property.offer", inverse_name="property_type_id"
)
offer_count = fields.Integer(compute="_compute_offer_count")

_sql_constraints = [
("name_uniq", "unique(name)", "Type must be unique"),
]

def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
13 changes: 9 additions & 4 deletions estate/models/inherited_users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from odoo import models, fields
from odoo import fields, models


class inheritedUser(models.Model):
_inherit = 'res.users'

property_ids=fields.One2many('estate.property', 'salesman_id',domain=[('status','not in',["sold","canceled"])])
_inherit = "res.users"

property_ids = fields.One2many(
"estate.property",
"salesman_id",
domain=[("status", "not in", ["sold", "canceled"])],
)
2 changes: 1 addition & 1 deletion estate/security/estate_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<field name="name">Estate Manager rules for all properties</field>
<field name="model_id" ref="estate.model_estate_property"/>
<field name="groups" eval="[Command.link(ref('estate.estate_group_manager'))]" />
<field name="domain_force">[]</field>
<field name="domain_force">[(1,'=',1)]</field>
</record>

<record model="ir.rule" id="estate_company_rule">
Expand Down
3 changes: 1 addition & 2 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Estate Property Offer</field>
<field name="res_model">estate.property.offer</field>
Expand All @@ -25,7 +24,7 @@
</record>

<!-- form view -->
<record id="estate_property_offer_view_wizard" model="ir.ui.view">
<record id="estate_property_offer_view_form" model="ir.ui.view">
<field name="name">estate_property_offer.view.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
Expand Down
2 changes: 0 additions & 2 deletions estate/views/estate_property_tags_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<!-- Estate property Tags action -->
<record id="estate_property_tags_action" model="ir.actions.act_window">
<field name="name">property tag</field>
Expand All @@ -27,5 +26,4 @@
</list>
</field>
</record>

</odoo>
2 changes: 0 additions & 2 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<!-- Estate proprty type action -->
<record id="estate_property_type_action" model="ir.actions.act_window">
<field name="name">property type</field>
Expand All @@ -16,7 +15,6 @@
</field>
</record>


<!-- Estate property type form view -->
<record id="estate_property_type_view_form" model="ir.ui.view">
<field name="name">estate_property_type.view.form</field>
Expand Down
17 changes: 10 additions & 7 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@
<field name="status" readonly="1" widget="statusbar" nolabel="1"></field>
</header>
<sheet>
<group name="Basics">
<h1>
<field name="name" label="Property Name" placeholder="Property Name" />
</h1>
<field name="image" widget="image" options="{'size': [150, 150]}"/>

<field name="tag_ids" widget="many2many_tags" placeholder="eg. Cozy, Quiet, Furnished, ..." options="{'color_field': 'color'}"/>
<group >
<group >
<h1>
<field name="name" label="Property Name" placeholder="Property Name" />
</h1>
<field name="tag_ids" widget="many2many_tags" placeholder="eg. Cozy, Quiet, Furnished, ..." options="{'color_field': 'color'}"/>

</group>
<group>
<field name="image" widget="image" class="oe_avatar" options="{'size': [150,150]}" nolabel="1"/>
</group>
</group>

<group>
Expand Down
61 changes: 28 additions & 33 deletions estate/views/estate_website_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@
<div class="row">
<t t-foreach="properties" t-as="property">
<div class="col-md-4 mb-4">
<div class="card">
<div class="ratio ratio-4x3">
<t t-if="property.image">
<img t-att-src="'/web/image/estate.property/%d/image' % property.id" class="card-img-top object-fit-cover" alt="Property Image"/>
</t>
<t t-else="">
<img t-att-src="'https://images.pexels.com/photos/186077/pexels-photo-186077.jpeg'" class="card-img-top object-fit-cover" alt="Default Property Image"/>
</t>
<a t-att-href="'/property/%d' % property.id" class="btn btn-outline-primary">
<div class="card">
<div class="ratio ratio-4x3">
<t t-if="property.image">
<img t-att-src="'/web/image/estate.property/%d/image' % property.id" class="card-img-top object-fit-cover" alt="Property Image"/>
</t>
<t t-else="">
<img t-att-src="'https://images.pexels.com/photos/186077/pexels-photo-186077.jpeg'" class="card-img-top object-fit-cover" alt="Default Property Image"/>
</t>
</div>
<div class="card-body">
<h5 class="card-title">
<t t-esc="property.name"/>
</h5>
<p class="card-text">
<strong>Price:</strong>
<t t-esc="property.expected_price"/>$
</p>
</div>
</div>
<div class="card-body">
<h5 class="card-title">
<t t-esc="property.name"/>
</h5>
<p class="card-text">
<strong>Price:</strong>
<t t-esc="property.expected_price"/>
$
</p>
<a t-att-href="'/property/%d' % property.id" class="btn btn-outline-primary">
View Details
</a>
</div>
</div>
</a>
</div>
</t>

</div>
<div class="d-flex justify-content-center my-3">
<t t-call="website.pager"/>
Expand Down Expand Up @@ -87,8 +84,8 @@
<strong>
<i class="fa fa-dollar-sign text-warning"></i> Expected Price:</strong>
<span class="text-success fw-bold">
<t t-esc="property.expected_price" />
$</span>
<t t-esc="property.expected_price" />$
</span>
</li>
</ul>
</div>
Expand All @@ -110,8 +107,8 @@
<strong>
<i class="fa fa-couch"></i> Living Area:</strong>
<span>
<t t-esc="property.living_area" />
</span>
<t t-esc="property.living_area" />
</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<strong>
Expand All @@ -137,8 +134,8 @@
<strong>
<i class="fa fa-leaf"></i> Garden Area:</strong>
<span>
<t t-esc="property.garden_area" />
</span>
<t t-esc="property.garden_area" />
</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<strong>
Expand All @@ -151,15 +148,13 @@
<strong>
<i class="fa fa-ruler-combined"></i> Total Area:</strong>
<span>
<t t-esc="property.total_area" />
</span>
<t t-esc="property.total_area" />
</span>
</li>
</ul>
</div>
</div>
</div>
</t>
</template>

</odoo>

8 changes: 4 additions & 4 deletions estate/wizard/estate_property_make_offer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import fields, models


class EstatePropertyMakeOffer(models.TransientModel):
Expand All @@ -12,18 +12,18 @@ class EstatePropertyMakeOffer(models.TransientModel):

def make_offer(self):
failed_properties = []
for property in self.property_ids:
for property in self.env.context.get("active_ids"):
try:
self.env["estate.property.offer"].create(
{
"price": self.offer_price,
"property_id": property.id,
"property_id": property,
"partner_id": self.partner_id.id,
"validity": self.offer_validity,
}
)
except Exception:
failed_properties.append(property.name)
failed_properties.append(str(property))
if failed_properties:
return {
"type": "ir.actions.client",
Expand Down
2 changes: 0 additions & 2 deletions estate/wizard/estate_property_wizard_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="estate_property_make_offer_view_form" model="ir.ui.view">
<field name="name">estate_property_make_offer.view.form</field>
<field name="model">estate.property.make.offer</field>
Expand All @@ -18,5 +17,4 @@
</form>
</field>
</record>

</odoo>
3 changes: 1 addition & 2 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"website": "https://www.odoo.com",
"category": "Tutorials/Estate_Account",
"version": "0.1",
"application": True,
"installable": True,
"depends": ["base_setup","estate","account"],
"depends": ["base_setup", "estate", "account"],
"data": [],
"license": "AGPL-3",
}
2 changes: 1 addition & 1 deletion estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields, Command
from odoo import Command, fields, models


class InheritedModel(models.Model):
Expand Down

0 comments on commit 1ad40ed

Please sign in to comment.