Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unneccary diff.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"xml.symbols.enabled": false,
"python.languageServer": "None"
}
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
16 changes: 16 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Estate",
"application": True,
"installable": True,
"author": "sngoh",
"depeneds": ["base"],
"license": "LGPL-3",
"data": [
"security/ir.model.access.csv",
"views/estate_property_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_tag_views.xml",
"views/estate_property_offer_views.xml",
"views/estate_menus.xml",
],
}
4 changes: 4 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import estate_property
from . import estate_property_types
from . import estate_property_tag
from . import estate_property_offer
107 changes: 107 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
copy=False, default=fields.Date.add(fields.Date.today(), months=3)
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer(string="Living Area(sqm)")
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area(sqm)")
garden_orientation = fields.Selection(
string="Garden Orientation",
selection=[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
],
)
active = fields.Boolean("Active", default=True)
state = fields.Selection(
string="Property State",
selection=[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
default="new",
)
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
sales_man = fields.Many2one(
"res.users", string="Salesman", default=lambda self: self.env.user
)
buyer = fields.Many2one("res.partner", string="Buyer", copy=False)
tag = fields.Many2many("estate.property.tag", string="Tags")
offer = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Float(compute="_compute_total_area")
best_price = fields.Float(compute="_compute_best_price")

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

@api.depends("offer.price")
def _compute_best_price(self):
for records in self:
prices = records.mapped("offer.price")
records.best_price = max(prices) if prices else 0

_check_expected_price = models.Constraint(
"CHECK(expected_price > 0)",
"A property expected price must be strictly positive",
)

_check_selling_price = models.Constraint(
"CHECK(selling_price >= 0)",
"A property selling price must be positive",
)

@api.constrains("state")
def on_state_change(self):
for record in self:
if record.state == "offer_accepted" or record.state == "sold":
if float_compare(record.selling_price, record.expected_price * 0.9, 3):
raise ValidationError("Selling price error")

@api.onchange("garden")
def _on_change_garden(self):
for records in self:
if records.garden:
records.garden_area = 10
records.garden_orientation = "north"
else:
records.garden_area = False
records.garden_orientation = False

def sold_button(self):
for records in self:
if records.state == "cancelled":
raise UserError("Cancelled property cannot be sold.")
records.state = "sold"
records.selling_price = records.selling_price
return True

def cancel_button(self):
for records in self:
if records.state == "sold":
raise UserError("Sold property cannoy be cancelled.")
records.state = "cancelled"
records.state = False
return True
61 changes: 61 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from odoo import api, fields, models


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real E-state offer"

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

@api.depends("create_date", "validity")
def _compute_date_deadline(self):
for records in self:
base_date = (
records.create_date.date()
if records.create_date
else fields.Date.today()
)
records.date_deadline = fields.Date.add(base_date, days=records.validity)

_check_offer_price = models.Constraint(
"CHECK(price > 0)",
"An offer price must be strictly positive",
)

def _inverse_date_deadline(self):
for records in self:
base_date = (
records.create_date.date()
if records.create_date
else fields.Date.today()
)
if records.date_deadline:
records.validity = (records.date_deadline - base_date).days

def accept_button(self):
for records in self:
records.status = "accepted"
records.property_id.buyer = records.partner_id
records.property_id.selling_price = records.price
records.property_id.state = "offer_accepted"

def reject_button(self):
for records in self:
records.status = "refused"
if records.property_id.buyer == records.partner_id:
records.property_id.buyer = False
records.property_id.selling_price = False
records.property_id.state = "offer_received"
13 changes: 13 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real E-state Property Tag"

name = fields.Char(required=True)

_check_unique_tag = models.Constraint(
"UNIQUE(name)",
"A property tag name must be unique",
)
13 changes: 13 additions & 0 deletions estate/models/estate_property_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class EstatePropertyTypes(models.Model):
_name = "estate.property.type"
_description = "Real E-state Property Type"

name = fields.Char()

_check_unique_property_name = models.Constraint(
"UNIQUE(name)",
"A property type should be unique",
)
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
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,access_estdate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
11 changes: 11 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<odoo>
<menuitem id="menu_root" name="E-state">
<menuitem id="advertisement" name="Advertisements">
<menuitem id="property_menu" action="estate_property_action" />
</menuitem>
<menuitem id="settings" name="settings">
<menuitem id="property_types" action="estate_property_type_action" />
<menuitem id="property_tag" action="estate_property_tag_action" />
</menuitem>
</menuitem>
</odoo>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should be one empty line at the end of the file.

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

<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>
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field name="date_deadline" />
<button name="accept_button" title="Accept" type="object" icon="fa-check" />
<button name="reject_button" title="Reject" type="object" icon="fa-times" />
<field name="status" />
</list>
</field>
</record>

<record id="estate_property_offer_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>
<sheet>
<group>
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field name="date_deadline" />
<field name="status" />
</group>
</sheet>
</form>
</field>
</record>

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

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

<record id="estate_property_tag_list_view" 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>
<field name="name" />
</list>
</field>
</record>

<record id="estate_property_tag_form_view" 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>
<sheet>
<group>
<field name="name" />
</group>
</sheet>
</form>
</field>
</record>

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

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

<record id="estate_property_type_list_view" model="ir.ui.view">
<field name="name">estate.property.type.list</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<list>
<field name="name" />
</list>
</field>
</record>

<record id="estate_property_type_form_view" model="ir.ui.view">
<field name="name">etate.property.type.form</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form>
<div class="oe_title">
<h1>
<group>
<field name="name" />
</group>
</h1>
</div>
</form>
</field>
</record>

</odoo>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should be one empty line at the end of the file.

Loading