Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
.vscode/settings.json
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
'name': "Estate",
'version': '1.0',
'depends': ['base'],
'author': "Asurk",
'category': 'Real Estate/Brokerage',
'description': """
A module so that customers can bid on real estates
""",
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_menus.xml'
],
'license': 'LGPL-3', # Default License
'application': True,
'installable': True,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of using 'installable': True?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When installable is set to true , user can install the module from web interface

# data files always loaded at installation

}
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer
100 changes: 100 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from odoo import fields, models, api
from odoo.exceptions import UserError, ValidationError


class EstateProperty(models.Model):

_name = 'estate.property'
_description = "A real estate model with many fields"
active = fields.Boolean(string="Active", default="Active")
bedrooms = fields.Integer(string="Bedrooms", default="2")
best_price = fields.Float(
string="Best Price", compute='_compute_best_price')
buyer = fields.Many2one(
'res.partner', string="Buyer", ondelete='restrict',
)
date_availability = fields.Datetime(
string="Available From", copy=False, default=lambda self: fields.Date.add(fields.Date.context_today(self), months=3))
description = fields.Text(string="Description")
expected_price = fields.Float(string="Expected Price", required=True)
facades = fields.Integer(string="Facades")
garden = fields.Boolean(string="Garden")
garden_area = fields.Float(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
string="Direction",
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West")
],
help="Type is used to specify the garden orientation"
)
garage = fields.Boolean(string="Garage")
living_area = fields.Float(string="Living Area (sqm)")
name = fields.Char(string="Title", required=True)
offer_ids = fields.One2many(
'estate.property.offer', 'property_id', string='Offers')
postcode = fields.Char(string="Postcode")
property_type_id = fields.Many2one(
'estate.property.type', string="Property Type")
salesman = fields.Many2one(
'res.users', string="Salesman", ondelete='restrict',
)
selling_price = fields.Float(
string="Selling Price", readonly=True, copy=False)
state = fields.Selection([('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled")
],
default='new')
tag_ids = fields.Many2many(
'estate.property.tag',
string="Tags"
)
total_area = fields.Float(
string="Total Area", compute='_compute_total_area'
)

@api.depends('living_area', 'garden_area')
def _compute_total_area(self):
for rec in self:
rec.total_area = rec.living_area + rec.garden_area

@api.depends('offer_ids.price')
def _compute_best_price(self):
for rec in self:
rec.best_price = max(rec.mapped('offer_ids.price') or [0])

@api.onchange('garden')
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = 'north'
else:
self.garden_area = 0
self.garden_orientation = False

@api.constrains('expected_price')
def _check_price(self):
for rec in self:
if rec.expected_price <= 0:
raise ValidationError("Price must be positive") # Shown in UI

def action_property_sold(self):
for rec in self:
if rec.state == 'cancelled':
raise UserError('A cancelled property cannot be sold')
else:
rec.state = 'sold'
return True

def action_property_cancelled(self):
for rec in self:
if rec.state == 'sold':
raise UserError('A sold property cannot be cancelled')
else:
rec.state = 'cancelled'
return True
53 changes: 53 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


class EstatePropertyOffer(models.Model):

_name = 'estate.property.offer'
_description = "A model where offer for the properties are stored"

price = fields.Float(required=True)
status = fields.Selection(selection=[('accepted', "Accepted"),
('refused', "Refused")])
partner_id = fields.Many2one('res.partner', required=True)
property_id = fields.Many2one(
'estate.property', required=True)
validity = fields.Integer(string="Validity", default='7')
date_deadline = fields.Datetime(
string="Deadline", compute='_compute_date_deadline', inverse='_inverse_date_deadline')

@api.depends('validity', 'create_date')
def _compute_date_deadline(self):
for rec in self:
create_date = rec.create_date or fields.Date.context_today(self)
rec.date_deadline = fields.Date.add(create_date, days=rec.validity)

def _inverse_date_deadline(self):
for rec in self:
create_date = rec.create_date or fields.Date.context_today(self)
rec.validity = (rec.date_deadline - create_date).days

def action_status_accepted(self):
for rec in self:
if rec.status == 'accepted':
raise UserError("Offer has already been accepted")
rec.status = 'accepted'

rec.property_id.write({
'buyer': rec.partner_id.id,
'selling_price': rec.price,
})

return True

def action_status_refused(self):
for rec in self:
if rec.status == 'refused':
raise UserError("Offer has already been refused")
rec.status = 'refused'
rec.property_id.write({
'buyer': False,
'selling_price': False,
})
return True
10 changes: 10 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class EstatePropertyTag(models.Model):

_name = "estate.property.tag"
_description = "Tags for properties"

name = fields.Char(string="Tags")
color = fields.Integer(string="Color")
11 changes: 11 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class EstatePropertyType(models.Model):

_name = 'estate.property.type'
_description = "A model where property types are defined"

name = fields.Char(required=True, string="Property Type")
property_ids = fields.One2many(
'estate.property', inverse_name='property_type_id', string="Properties")
5 changes: 5 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
Binary file added estate/static/description/Real_Estate_Logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>

<menuitem id="real_estate_root" name="Real Estate" web_icon="estate,static/description/Real_Estate_Logo.jpg"/>

<menuitem id="real_estate_properties_menu" name="Advertisements" parent="real_estate_root"/>
<menuitem id="real_estate_properties_settings_menu" name="Settings" parent="real_estate_root"/>

<menuitem id="real_estate_menu_action" name="All Properties " parent="real_estate_properties_menu"
action="test_property_action"/>
<menuitem id="real_estate_property_type_action" name="Property Types" parent="real_estate_properties_settings_menu"
action="test_property_type_action"/>
<menuitem id="real_estate_property_tags_action" name="Property Tags" parent="real_estate_properties_settings_menu"
action="test_property_tags_action"/>


</odoo>
51 changes: 51 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<odoo>


<!--_________________________________________ WINDOW ACTION _________________________________________-->

<record id="test_property_offer_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list,form</field>
</record>


<!--_________________________________________ LIST VIEW _________________________________________-->
<record id="estate_property_offer_view_list" model="ir.ui.view">
<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>

<field name="arch" type="xml">
<list string="">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline" widget="datetime"/>
<button name="action_status_accepted" string="Accept" type="object" class="btn-primary"/>
<button name="action_status_refused" string="Refuse" type="object" class="btn-secondary"/>
<field name="status" />
</list>
</field>
</record>
<!--_________________________________________ FORM VIEW _________________________________________-->

<record id="estate_property_tags_view_form" model="ir.ui.view">
<field name="name">estate.property.offer.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<form string="">
<sheet>
<group>
<field name="price" widget=""/>
<field name="partner_id" widget="many2one_avatar_user"/>
<field name="validity"/>
<field name="date_deadline" widget="datetime"/>
<field name="status" widget="radio"/>
</group>
</sheet>
</form>
</field>
</record>

</odoo>
60 changes: 60 additions & 0 deletions estate/views/estate_property_tags_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0"?>
<odoo>


<!--_________________________________________ WINDOW ACTION _________________________________________-->

<record id="test_property_tags_action" model="ir.actions.act_window">
<field name="name">Property Types</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
</record>

<!--_________________________________________ LIST ACTION _________________________________________-->


<record id="estate_property_tags_view_list" model="ir.ui.view">
<field name="name">estate.property.tag.list</field>
<field name="model">estate.property.tag</field>

<field name="arch" type="xml">
<list string="">


<field name="name" default_focus="1" class="oe_inline"/>

<field name="color" widget="color_picker"/>


</list>
</field>

</record>


<!--_________________________________________ FORM VIEW _________________________________________-->

<record id="estate_property_tags_view_form" model="ir.ui.view">
<field name="name">estate.property.tag.form</field>
<field name="model">estate.property.tag</field>

<field name="arch" type="xml">
<form string="">
<sheet>
<div class="oe_title ">
<label for="name"/>
<h1>
<field name="name" default_focus="1" class="oe_inline"/>
</h1>
<h4>
<field name="color" widget="color_picker"/>
</h4>
</div>
</sheet>
</form>
</field>

</record>


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

<record id="test_property_type_action" model="ir.actions.act_window">
<field name="name">Property Types</field>
<field name="res_model">estate.property.type</field>
<field name="view_mode">list,form</field>
</record>

<record id="estate_property_type_view_form" model="ir.ui.view">
<field name="name">estate.property.type.form</field>
<field name="model">estate.property.type</field>

<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title oe_inline text-center">
<label for="name"/>
<h1>
<field name="name" default_focus="1" class="oe_inline"/>
</h1>
</div>
</sheet>
</form>
</field>
</record>

</odoo>
Loading