Skip to content

Commit

Permalink
[IMP] estate: implemented modifications in data and security
Browse files Browse the repository at this point in the history
- Updated data files to reflect recent changes in property and offer models.
- Enhanced security for estate-related models.
- Added security rules to ensure proper access levels for different user roles.
  • Loading branch information
akya-odoo committed Sep 3, 2024
1 parent 45e4a94 commit ff21063
Show file tree
Hide file tree
Showing 41 changed files with 817 additions and 65 deletions.
2 changes: 2 additions & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import models
from . import controllers
from . import wizard
14 changes: 13 additions & 1 deletion estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
'summary': 'Manage real estate properties',
'description': 'Module to manage real estate properties',
'author': 'Akya',
'depends': ['base', 'mail'],
'category': 'Real Estate/Brokerage',
'sequence': '15',
'depends': ['base', 'mail','website'],
'data': [
'security/estate_security.xml',
'security/ir.model.access.csv',
'data/estate.property.type.csv',
'wizard/estate_property_offer_wizard.xml',
'wizard/estate_property_event_view.xml',
'views/estate_property_views.xml',
'views/estate_property_controller_template.xml',
'views/estate_property_offer_view.xml',
'views/estate_property_tag_view.xml',
'views/estate_property_type_view.xml',
'views/res_users_view.xml',
'views/estate_menus.xml',
'report/estate_property_reports.xml',
'report/estate_property_templates.xml',
],
'demo':[
'demo/estate_property_demo.xml'
],
'installable': True,
'application': True,
Expand Down
1 change: 1 addition & 0 deletions estate/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property_controller
22 changes: 22 additions & 0 deletions estate/controllers/estate_property_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import http


class WebsiteProperty(http.Controller):

@http.route("/properties", auth="public", website=True)
def display_properties(self, page=1, **kwargs):
page = int(page)
items_per_page = 6
offset = (page - 1) * items_per_page
total_properties = http.request.env["estate.property"].search_count([('state', '!=', 'sold'), ('state', '!=', 'canceled')])
total_page = (total_properties + items_per_page - 1) // items_per_page
properties = http.request.env["estate.property"].search([('state', '!=', 'sold'), ('state', '!=', 'canceled')], limit=items_per_page, offset=offset)
return http.request.render(
"estate.property_page", {"properties": properties, 'page': page, 'total_page': total_page}
)

@http.route('/property/<model("estate.property"):each_property>', type='http', auth='public', website=True)
def property_details(self, each_property, **kwargs):
return http.request.render('estate.property_detail_page', {
'property': each_property,
})
5 changes: 5 additions & 0 deletions estate/data/estate.property.type.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name
id1,Residential
id2,Commercial
id3,Industrial
id4,Land
84 changes: 84 additions & 0 deletions estate/demo/estate_property_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<odoo>
<record id="demo_data_1" model="estate.property">
<field name="title">Big villa</field>
<field name="state">new</field>
<field name="description">A nice and big villa</field>
<field name="postcode">12345</field>
<field name="availability_date">2020-02-02</field>
<field name="expected_price">100</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">100000</field>
<field name="facades">4</field>
<field name="garden_orientation">south</field>
<field name="property_type_id" ref="estate.id1"></field>
</record>

<record id="demo_data_2" model="estate.property">
<field name="title">BTrailer home</field>
<field name="state">canceled</field>
<field name="description">home in a trailer park</field>
<field name="postcode">54321</field>
<field name="availability_date">1970-01-01</field>
<field name="expected_price">100</field>
<field name="bedrooms">1</field>
<field name="living_area">10</field>
<field name="garage">False</field>
<field name="facades">4</field>
<field name="property_type_id" ref="estate.id1"></field>
</record>

<record id="demo_data_3" model="estate.property">
<field name="title">Luxury villa</field>
<field name="state">new</field>
<field name="description">A very nice villa</field>
<field name="postcode">12345</field>
<field name="availability_date">2020-02-02</field>
<field name="expected_price">100</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">100000</field>
<field name="garden_orientation">south</field>
<field name="facades">4</field>
<field name="offer_ids" eval="[
Command.create({
'partner_id': ref('base.res_partner_2'),
'price': 190000000,
'validity': 14
}),
]"/>
<field name="property_type_id" ref="estate.id1"></field>
</record>

<record id="demo_estate_offer_1" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_1"/>
<field name="property_id" ref="demo_data_1"/>
<field name="price">100</field>
<field name="validity" >14</field>

</record>

<record id="demo_estate_offer_2" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_2"/>
<field name="property_id" ref="demo_data_1"/>
<field name="price">150</field>
<field name="validity">14</field>

</record>

<record id="demo_estate_offer_3" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_3"/>
<field name="property_id" ref="demo_data_1"/>
<field name="price">151</field>
<field name="validity">14</field>
<field name="date_deadline" eval="datetime.now()+ relativedelta(days = 14)"/>
</record>
</odoo>
</odoo>
6 changes: 5 additions & 1 deletion estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, res_users
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
13 changes: 8 additions & 5 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class EstateProperty(models.Model):
seller_id = fields.Many2one('res.users', string="Salesperson", ondelete='set null')
tag_ids = fields.Many2many('estate.property.tag')
offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
property_image = fields.Binary(string="Property Image")
company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company)

_sql_constraints = [
('check_expected_price', 'CHECK(expected_price >= 0)', 'The expected price must be strictly positive.'),
('check_selling_price', 'CHECK(selling_price >= 0)', 'The selling price must be positive.')
]

@api.depends('living_area', 'garden_area')
def _compute_total(self):
Expand Down Expand Up @@ -74,6 +81,7 @@ def action_cancel(self):
return True

def action_sold(self):
print("Old method called ############")
if self.state != "canceled":
if self.state == 'offer_accepted':
self.state = "sold"
Expand All @@ -83,11 +91,6 @@ def action_sold(self):
raise UserError("This property can't be sold as it is canceled already")
return True

_sql_constraints = [
('check_expected_price', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'),
('check_selling_price', 'CHECK(selling_price >= 0)', 'The selling price must be positive.')
]

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
Expand Down
8 changes: 4 additions & 4 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class EstatePropertyOffer(models.Model):
property_id = fields.Many2one('estate.property', 'Property', required=True, ondelete="cascade")
property_type_id = fields.Many2one(related="property_id.property_type_id")

_sql_constraints = [
('check_offer_price', 'CHECK(price > 0)', 'The offer price must be strictly positive.')
]

@api.depends('create_date', 'validity')
def _compute_date_deadline(self):
for record in self:
Expand Down Expand Up @@ -49,10 +53,6 @@ def action_refuse(self):
self.status = 'refused'
return True

_sql_constraints = [
('check_offer_price', 'CHECK(price > 0)', 'The offer price must be strictly positive.')
]

@api.model
def create(self, vals):
record = super().create(vals)
Expand Down
2 changes: 1 addition & 1 deletion estate/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class ResUsers(models.Model):
'estate.property',
'seller_id',
string='Properties',
domain=[('state', '=', 'available')]
domain="['|', ('state', '=', 'new'), ('state', '=', 'offer received')]"
)
24 changes: 24 additions & 0 deletions estate/report/estate_property_reports.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record id="report_property_details" model="ir.actions.report">
<field name="name">Real Estate Property</field>
<field name="model">estate.property</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">estate.report_property_offers</field>
<field name="report_file">estate.report_property_offers</field>
<field name="binding_model_id" ref="model_estate_property"/>
<field name="binding_type">report</field>
</record>

<record id="report_user_properties" model="ir.actions.report">
<field name="name">User Real Estate Property</field>
<field name="model">res.users</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">estate.report_property_offers_users</field>
<field name="report_file">estate.report_property_offers_users</field>
<field name="binding_model_id" ref="base.model_res_users"/>
<field name="binding_type">report</field>
</record>
</data>
</odoo>
100 changes: 100 additions & 0 deletions estate/report/estate_property_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="table_template">
<t t-if="property.offer_ids">
<table class="table">
<thead>
<tr>
<th>Price</th>
<th>Partner</th>
<th>Validity(days)</th>
<th>Deadline</th>
<th>State</th>
</tr>
</thead>
<tbody>
<t t-set="offers" t-value="property.mapped('offer_ids')"/>
<tr t-foreach="offers" t-as="offer">
<td>
<span t-field="offer.price"/>
</td>
<td>
<span t-field="offer.partner_id"/>
</td>
<td>
<span t-field="offer.validity"/>
</td>
<td>
<span t-field="offer.date_deadline"/>
</td>
<td>
<span t-field="offer.status"/>
</td>
</tr>
</tbody>
</table>
</t>
<t t-else = "">
<strong> There are no offers for this properpty yet.</strong>
</t>
</template>

<template id="report_property_offers">
<t t-foreach="docs" t-as="property">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<h2>
<span t-field="property.title"/>
</h2>
<div>
<strong>Salesman: </strong>
<span t-field="property.seller_id"/>
</div>
<div>
<strong>Expected Price: </strong>
<span t-field="property.expected_price"/>
</div>
<div class="state">
<strong>Status: </strong>
<span t-field="property.state"/>
</div>
<t t-call="estate.table_template"/>
</div>
</t>
</t>
</t>
</template>

<template id="report_property_offers_users">
<t t-foreach="docs" t-as="user">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<h2>
<strong>Salesman: </strong>
<span t-field="user.name"/>
</h2>
<t t-foreach="user.property_ids" t-as="property">
<div>

<h2>
<span t-field="property.title" />
</h2>
</div>
<div>
<strong>Expected Price: </strong>
<span t-field="property.expected_price"/>
</div>
<div>
<strong>Status: </strong>
<span t-field="property.state"/>
</div>
<t t-call="estate.table_template"/>
</t>
</div>
</t>
</t>
</t>
</template>
</odoo>
37 changes: 37 additions & 0 deletions estate/security/estate_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="estate_group_user" model="res.groups">
<field name="name">Agent</field>
<field name="category_id" ref="base.module_category_real_estate_brokerage"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="estate_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="base.module_category_real_estate_brokerage"/>
<field name="implied_ids" eval="[(4, ref('estate_group_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>

<record id="estate_property_user_access_rule" model="ir.rule">
<field name="name">Estate Property User Access Rule</field>
<field name="model_id" ref="model_estate_property"/>
<field name="groups" eval="[Command.link(ref('estate.estate_group_user'))]"/>
<field name="domain_force">['|', ('seller_id', '=', user.id), ('seller_id', '=', False)]</field>
</record>

<record id="estate_property_manager_access_rule" model="ir.rule">
<field name="name">Estate Property User Access Rule</field>
<field name="model_id" ref="model_estate_property"/>
<field name="groups" eval="[Command.link(ref('estate.estate_group_manager'))]"/>
</record>

<record model="ir.rule" id="record_restricted_company_rule">
<field name="name">Restricted Record: multi-company</field>
<field name="model_id" ref="model_estate_property"/>
<field name="global" eval="True"/>
<field name="domain_force">
[('company_id', 'in', company_ids)]
</field>
</record>
</odoo>
Loading

0 comments on commit ff21063

Please sign in to comment.