Skip to content

Commit

Permalink
[IMP] estate: updated controller, and /properties UI
Browse files Browse the repository at this point in the history
- added pager (for pagination on the properties page)
- added single property page(s)
- added menu to the website.layout menus, to navigate to `/properties`
  • Loading branch information
kiga-odoo committed Jan 17, 2025
1 parent d104611 commit e2a97d8
Show file tree
Hide file tree
Showing 25 changed files with 269 additions and 51 deletions.
2 changes: 1 addition & 1 deletion estate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import models
from . import wizard
from . import controllers
from . import controllers
2 changes: 1 addition & 1 deletion estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
'demo/estate_property_demo.xml',
'demo/estate_property_offers_demo.xml',
],
}
}
2 changes: 1 addition & 1 deletion estate/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import property_web_view_controlller
from . import property_web_view_controller
48 changes: 48 additions & 0 deletions estate/controllers/property_web_view_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from odoo import http
from odoo.http import request


class PropertyWebView(http.Controller):
@http.route(["/properties", "/properties/page/<int:page>"], type="http", auth="public", website=True)
def show_properties(self, page=1):
step = 6
offset = (page - 1) * step

properties = (
request.env["estate.property"].sudo().search(
[
"&",
("state", "in", ["new", "offer_received", "offer_accepted"]),
("active", "=", True),
],
limit=step,
offset=offset,
)
)

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

pager = request.website.pager(
url="/properties", total=total_properties, step=step, page=page
)

return request.render(
"estate.estate_property_web_view", {"properties": properties, "pager": pager}
)



@http.route(["/property/<int:id>"], type="http", auth="public", website=True)
def show_property_by_ID(self, id):
property = request.env['estate.property'].sudo().search([('id', '=', id)])

if property:
return request.render('estate.estate_property_web_view_single', {
'property': property
})
14 changes: 0 additions & 14 deletions estate/controllers/property_web_view_controlller.py

This file was deleted.

2 changes: 1 addition & 1 deletion estate/data/estate.property.type.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ id,name
property_type_1,Residential
property_type_2,Commercial
property_type_3,Industrial
property_type_4,Land
property_type_4,Land
12 changes: 12 additions & 0 deletions estate/demo/estate_property_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<field name="garden_area">100000</field>
<field name="garden_orientation">south</field>
<field name="property_type_id" ref="property_type_1" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_2" model="estate.property">
Expand All @@ -31,6 +32,7 @@
<field name="facades">4</field>
<field name="garage">False</field>
<field name="property_type_id" ref="property_type_1" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_3" model="estate.property">
Expand All @@ -50,6 +52,7 @@
})
]"></field>
<field name="property_type_id" ref="property_type_4" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_4" model="estate.property">
Expand All @@ -69,6 +72,7 @@
})
]"></field>
<field name="property_type_id" ref="property_type_3" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_5" model="estate.property">
Expand All @@ -86,6 +90,7 @@
<field name="garden_area">500</field>
<field name="garden_orientation">north</field>
<field name="property_type_id" ref="property_type_2" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_6" model="estate.property">
Expand All @@ -103,6 +108,7 @@
<field name="garden_area">300</field>
<field name="garden_orientation">west</field>
<field name="property_type_id" ref="property_type_3" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="estate_property_demo_7" model="estate.property">
Expand All @@ -119,7 +125,13 @@
<field name="garage">True</field>
<field name="garden">False</field>
<field name="property_type_id" ref="property_type_1" />
<field name="image" type="base64" file="estate/static/properties/1.jpg"></field>
</record>

<record id="menu_contactus" model="website.menu">
<field name="name">Properties</field>
<field name="url">/properties</field>
<field name="parent_id" ref="website.main_menu"/>
</record>

</odoo>
2 changes: 1 addition & 1 deletion estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, res_users
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, res_users
4 changes: 3 additions & 1 deletion estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class EstateProperty(models.Model):
garage = fields.Boolean("Garage", readonly=False)
garden = fields.Boolean("Garden", readonly=False)

image = fields.Image("Image")

@api.onchange('garden')
def _onchange_garden(self):
if self.garden:
Expand Down Expand Up @@ -135,4 +137,4 @@ def action_make_offer(self):
'context': {
'default_property_ids': self.ids
}
}
}
2 changes: 1 addition & 1 deletion estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def create(self, vals_list):

_sql_constraints = [
('check_offer_price', 'CHECK(price > 0)', 'The offer price should be strictly positive.')
]
]
2 changes: 1 addition & 1 deletion estate/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
class ResUsers(models.Model):
_inherit = 'res.users'

property_ids = fields.One2many('estate.property', 'seller_id', domain=[('state', 'not in', ['sold', 'cancelled'])])
property_ids = fields.One2many('estate.property', 'seller_id', domain=[('state', 'not in', ['sold', 'cancelled'])])
2 changes: 1 addition & 1 deletion estate/report/estate_property_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
</xpath>
</template>

</odoo>
</odoo>
4 changes: 2 additions & 2 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ estate.manager_access_estate_property_model,manager_access_estate_property_model
estate.manager_access_estate_property_type_model,manager_access_estate_property_type_model,estate.model_estate_property_type,estate.estate_group_manager,1,1,1,1
estate.manager_access_estate_property_tags_model,manager_access_estate_property_tags_model,estate.model_estate_property_tag,estate.estate_group_manager,1,1,1,1
estate.manager_access_estate_property_offer,manager_access_estate_property_offer,estate.model_estate_property_offer,estate.estate_group_manager,1,1,1,1
estate.access_estate_property_make_offer,access_estate_property_make_offer,estate.model_estate_property_make_offer,estate_group_manager,1,1,1,1
estate.manager_access_estate_property_make_offer,manager_access_estate_property_make_offer,estate.model_estate_property_make_offer,estate_group_manager,1,1,1,1
estate.agent_access_estate_property_model,agent_access_estate_property_model,estate.model_estate_property,estate.estate_group_user,1,1,1,0
estate.agent_access_estate_property_type_model,agent_access_estate_property_type_model,estate.model_estate_property_type,estate.estate_group_user,1,0,0,0
estate.agent_access_estate_property_tags_model,agent_access_estate_property_tags_model,estate.model_estate_property_tag,estate.estate_group_user,1,0,0,0
estate.agent_access_estate_property_offer,agent_access_estate_property_offer,estate.model_estate_property_offer,estate.estate_group_user,1,1,1,1
estate.access_estate_property_make_offer,access_estate_property_make_offer,estate.model_estate_property_make_offer,estate_group_user,1,1,1,1
estate.agent_access_estate_property_make_offer,agent_access_estate_property_make_offer,estate.model_estate_property_make_offer,estate_group_user,1,1,1,1
Binary file added estate/static/properties/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added estate/static/properties/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added estate/static/properties/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added estate/static/properties/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added estate/static/properties/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added estate/static/properties/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e2a97d8

Please sign in to comment.