Skip to content

Commit

Permalink
[IMP] estate: created controller of estate to access in website
Browse files Browse the repository at this point in the history
- Created the controller in estate
- Add pagination
- Add redirect of property detail view
- Covered the controller section
  • Loading branch information
amya-odoo committed Aug 27, 2024
1 parent 27fc6ce commit 21c63a7
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 0 deletions.
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import controller
1 change: 1 addition & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"security/ir.model.access.csv",
"data/estate.property.type.csv",
"report/estate_property_templates.xml",
"report/estate_propert_web_template.xml",
"report/estate_property_report.xml",
"views/res_user_views.xml",
"views/estate_property_views.xml",
Expand Down
1 change: 1 addition & 0 deletions estate/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property_controller
55 changes: 55 additions & 0 deletions estate/controller/estate_property_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import math
import logging
from odoo.http import Controller, request, route


class PropertyController(Controller):

@route(
["/properties", "/properties/page/<int:page>"],
auth="public",
type="http",
website=True,
)
def properties_controller(self, page=1, per_page=6, *args, **kwargs):
try:
property_recode = request.env["estate.property"]
page = int(page)
per_page = int(per_page)
offset = (page - 1) * per_page
limit = per_page
domain = [("state", "in", ["offer_recived", "offer_accepted"])]
properties = property_recode.search(
domain,
limit=limit,
offset=offset,
)
total_property = properties.search_count(domain)
total_pages = math.ceil(total_property / per_page)
pager = {
"url": "/properties/page/" + str(page),
"total": total_property,
"page": page,
"total_page": total_pages,
"step": per_page,
}
values = {"properties": properties, "pager": pager}
return request.render("estate.estate_properties_web", values)
except Exception as e:
logging.exception("Error while processing estate_property", e)

@route(
"/properties/<int:property_id>",
auth="public",
type="http",
website=True,
methods=["GET"],
)
def property_controller(self, property_id, *args, **kwargs):
try:
property_recode = request.env["estate.property"].browse(property_id)
return request.render(
"estate.estate_property_web", ({"property": property_recode})
)
except Exception as e:
logging.exception("Error while processing estate_property")
1 change: 1 addition & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EstateProperty(models.Model):
garden = fields.Boolean()
garden_area = fields.Integer()
active = fields.Boolean(default=True)
property_image = fields.Image("Property Image")
state = fields.Selection(
required=True,
copy=False,
Expand Down
121 changes: 121 additions & 0 deletions estate/report/estate_propert_web_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<odoo>
<template id="estate_properties_web" name="Estate Properties">
<t t-call="website.layout">
<div id="wrap" class="h-100 d-flex flex-column align-item-center justify-content-between">
<div class="container mt-4">
<h1 class="text-center mb-4">Estate Properties</h1>
<div class="row">
<t t-foreach="properties" t-as="property">
<div class="col-md-4 mb-4">
<a t-att-href="'/properties/' + str(property.id)" class="o_action" style="text-decoration:none;">
<div class="card d-f flex-column align-items-center">
<img t-if="property.property_image" class="" style="height: 300px; width: 410px; " t-att-src="image_data_uri(property.property_image)"/>
<div class="container p-1" style="width:90%;">
<div class="grid">
<t t-foreach="property.tag_ids" t-as="tag">
<span t-attf-class="badge rounded-pill text-bg-primary ">
<t t-out="tag.name"/>
</span>
</t>
</div>
</div>
<div style="width:90%" class="p-2">
<h6 class="card-title">
<t t-esc="property.name"/>
</h6>
</div>
</div>
</a>
</div>
</t>
</div>
</div>
<div class="d-flex flex-row align-items-center justify-content-center" style="width: 100%; height: 30px;">
<t t-foreach="pager['total_page']" t-as="page">
<div class="m-1 rounded-circle" style="width: 20px; height: 20px; background-color: #f2f2f2; text-align: center;">
<a t-att-href="'/properties/page/'+str(page+1)">
<t t-esc="page+1"/>
</a>
</div>
</t>
</div>
</div>
</t>
</template>

<template id="estate_property_web" name="Estate Properties">
<t t-call="website.layout">
<div class="container">
<!-- <h1 class="text-center mb-4"> <t t-esc="property.name"/></h1> -->
<div class="row m-5 ">
<div class="card mb-3" style="max-width:90%">
<div class="row g-0 ">
<t t-if="property.property_image">
<div class="col-md-6 d-flex align-items-center justify-content-center p-2">
<img t-if="property.property_image" class="img-fluid rounded-start " style="min-height: 400px; min-width: 400px; object-fit: cover;" t-att-src="image_data_uri(property.property_image)" />
</div>
</t>
<div class="col-md-5">
<div class="card-body">
<h4 class="card-title">
<t t-esc="property.name"/>
</h4>
<p class="card-text"> State:
<t t-esc="property.state"/>
<br/>
Expected Price:
<t t-esc="property.expected_price"/>
</p>
<p class="card-text">
<small class="text-body-secondary">
Selling Price:
<t t-esc="property.selling_price"/>
</small>
<br/>
<small class="text-body-secondary">
Available Date:
<t t-esc="property.date_availability"/>
</small>
<br/>
<small class="text-body-secondary">
Bedrooms:
<t t-esc="property.bedrooms"/>
</small>
<br/>
<small class="text-body-secondary">
Living Area:
<t t-esc="property.living_area"/>
m2
</small>
<br/>
<small class="text-body-secondary">
Grage:
<t t-esc="property.garage"/>
</small>
<br/>
<small class="text-body-secondary">
Salesman:
<t t-esc="property.salesman_id.name"/>
</small>
<br/>
<t t-if="property.property_type_id">
<small class="text-body-secondary">
Property Type:
<t t-esc="property.property_type_id.name"/>
</small>
</t>
<br/>
<small class="text-body-secondary">
Description:
<t t-esc="property.description"/>
</small>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</t>
</template>
</odoo>
4 changes: 4 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<record id="action_account_estate_property_tree" model="ir.ui.view">
<field name="name">estate_property_tree</field>
<field name="model">estate.property</field>

<field name="arch" type="xml">
<tree decoration-success="state in ('offer_accepted', 'Offer Accepted') or state in ('offer_recived', 'Offer Recieved')" decoration-bf="state in ('offer_accepted', 'Offer Accepted')" decoration-muted="state == 'sold'">
<field name="name" string="Title"/>
Expand Down Expand Up @@ -46,6 +47,9 @@
<div>
<h1>
<field name="name"/>

<field name="property_image" widget="image" class="oe_avatar" />

</h1>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" />
</div>
Expand Down

0 comments on commit 21c63a7

Please sign in to comment.