Skip to content
Open
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
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
18 changes: 18 additions & 0 deletions Estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
'name': 'estate',
'depends': ['base'],
'application': True,
'installable': True,
'author': 'estate',
'category': 'Tutorials',
'license': 'AGPL-3',
'data': [
'security/ir.model.access.csv',
'views/estate_property_type_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_views.xml',
'views/res_users_view.xml',
'views/estate_menus.xml',
],
}
5 changes: 5 additions & 0 deletions Estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_offer
from . import estate_property_type
from . import estate_property_tag
from . import res_users
109 changes: 109 additions & 0 deletions Estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from datetime import timedelta

from odoo import models, fields, api
from odoo.exceptions import ValidationError


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property"
_order = "id desc"
name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
create_date = fields.Datetime()
expected_price = fields.Float(required=True)
selling_price = fields.Float()
bedrooms = fields.Integer()
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection([("north", "North"),("south", "South"),("east", "East"),("west", "West"),])
active = fields.Boolean(default=True)
state = fields.Selection([("new", "New"),("offer_received", "Offer Received"),("offer_accepted", "Offer Accepted"),("sold", "Sold"),("canceled", "Canceled")], required=True, copy=False , )

Choose a reason for hiding this comment

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

Suggested change
state = fields.Selection([("new", "New"),("offer_received", "Offer Received"),("offer_accepted", "Offer Accepted"),("sold", "Sold"),("canceled", "Canceled")], required=True, copy=False , )
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("canceled", "Canceled")
], required=True, copy=False)

For better readability.

property_type_id = fields.Many2one("estate.property.type", string="Property Type")
buyer_id = fields.Many2one("res.partner", string="Buyer")
salesperson_id = fields.Many2one("res.users", string="Salesperson")
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Float(compute="_compute_total_area", string="Total Area", store=True)
best_price = fields.Float(compute="_compute_best_price", string="Best Offer", store=True)
validity_days = fields.Integer(default=7)
date_deadline = fields.Date(compute="_compute_date_deadline",inverse="_inverse_date_deadline",store=True,)

Choose a reason for hiding this comment

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

Suggested change
date_deadline = fields.Date(compute="_compute_date_deadline",inverse="_inverse_date_deadline",store=True,)
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True,)

property_type_id = fields.Many2one("estate.property.type", string="Property Type")

_check_price = models.Constraint(
'CHECK(expected_price > 0 AND selling_price >= 0)',
'The expected price of a property must be strictly positive.'
)

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

@api.depends("offer_ids.price")
def _compute_best_price(self):
for record in self:
record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0.0

@api.depends("create_date", "validity_days")
def _compute_date_deadline(self):
for record in self:
create_date = record.create_date or fields.Date.today()
if hasattr(create_date, "date"):
create_date = create_date.date()
record.date_deadline = create_date + timedelta(days=record.validity_days)

def _inverse_date_deadline(self):
for record in self:
create_date = record.create_date or fields.Date.today()
if hasattr(create_date, "date"):
create_date = create_date.date()
delta = (record.date_deadline - create_date).days if record.date_deadline else 0
record.validity_days = delta

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

def action_set_sold(self):
for record in self:
record.state = "sold"

def action_set_canceled(self):
for record in self:
record.state = "canceled"

def action_set_next_status(self):
for record in self:
if record.state == "new":
record.state = "offer_received"
elif record.state == "offer_received":
record.state = "offer_accepted"
elif record.state == "offer_accepted":
record.state = "sold"

def action_back_to_new(self):
for record in self:
record.state = "new"

@api.constrains("selling_price", "expected_price")
def _check_selling_price_ratio(self):
for record in self:
if record.selling_price < 0.9 * record.expected_price:
raise ValidationError("Selling price must be at least 90% of the expected price")

def _unlink(self):
for record in self:
if record.state in ["new"]:
raise ValidationError("You cannot delete a new or canceled property.")
return super().unlink()
33 changes: 33 additions & 0 deletions Estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from odoo import models, fields, api
from odoo.exceptions import ValidationError


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer"
_order = "price desc"
price = fields.Float(required=True)
status = fields.Selection(
[
('pending', 'Pending'),
('accepted', 'Accepted'),
('refused', 'Refused'),
],
)

property_id = fields.Many2one("estate.property", string="Property", required=True)
partner_id = fields.Many2one("res.partner", string="Buyer", required=True)

def action_accept_offer(self):
for record in self:
record.status = 'accepted'

def action_refuse_offer(self):
for record in self:
record.status = 'refused'

@api.constrains("price")
def _check_price_ratio(self):
for record in self:
if record.price <= 0.0:
raise ValidationError("Price must be greater than 0")
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 models, fields


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_order = "name desc"
color = fields.Integer( string='Color Index', default=3)

name = fields.Char(required=True)
31 changes: 31 additions & 0 deletions Estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from odoo import models, fields, api
from odoo.exceptions import ValidationError


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"
_order="name desc"

name = fields.Char(required=True)
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
sequence = fields.Integer('Sequence', default=7)
offer_count = fields.Integer(string="Number of Offers",compute="_compute_offer_count")

_check_type_name_unique_ratio = models.Constraint(
'CHECK(name)',
'The property name must be unique.'
)
@api.depends('property_ids.offer_ids')
def _compute_offer_count(self):
for property_type in self:
offer_count = 0
for property in property_type.property_ids:
offer_count += len(property.offer_ids)
property_type.offer_count = offer_count
@api.constrains('name')
def _check_type_name_unique(self):
for record in self:
existing_type = self.search([('name', '=', record.name)])
if existing_type:
raise ValidationError(f"The property type name '{record.name}' must be unique.")
9 changes: 9 additions & 0 deletions Estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import models, fields


class ResUsers(models.Model):
_inherit = "res.users"

estate_property_ids = fields.One2many(
"estate.property", "salesperson_id", string="Properties as Salesperson"
)
6 changes: 6 additions & 0 deletions Estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
estate.access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
estate.access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
estate.access_res_users,access_res_users,model_res_users,base.group_user,1,1,1,1
40 changes: 40 additions & 0 deletions Estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<menuitem id="estate_root_menu" name="Estate"/>

<menuitem id="estate_advertisement_menu"
name="Advertisements"
parent="estate_root_menu"/>
<menuitem id="estate_property_menu"
name="Properties"
parent="estate_advertisement_menu"
action="action_estate_property"/>
Comment on lines +6 to +12
Copy link

Choose a reason for hiding this comment

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

Same as below.

<menuitem id="estate_property_list_menu"
name="List"
parent="estate_property_menu"
action="action_estate_property"/>

Copy link

Choose a reason for hiding this comment

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

unnecessary diff.

<menuitem id="estate_property_form_menu"
name="Form"
parent="estate_property_menu"
action="estate_property_form_action"/>

<menuitem id="menu_estate_settings"
name="Settings"
parent="estate_root_menu" />
<menuitem id="menu_estate_property_type_action_settings"
name="Property Types"
parent="menu_estate_settings"
action="estate_property_type_action" />

<menuitem id="menu_estate_property_tag_action_settings"
name="Property Tags"
parent="menu_estate_settings"
action="action_estate_property_tag" />

<menuitem id="menu_estate_users_action_settings"
name="Users"
parent="menu_estate_settings"
action="action_res_users_estate_properties" />
</odoo>
34 changes: 34 additions & 0 deletions Estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<odoo>

<record id="estate_property_offer_tree_view" 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" />
<button name="action_accept_offer" string="accept" type="object" invisible="status in ['accepted', 'refused']" />
<button name="action_refuse_offer" string="refuse" type="object" invisible="status in ['accepted', 'refused']" />
<field name="status" />
</list>
</field>
</record>

<record id="estate_property_offer_form_view" 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="status"/>
<button name="action_accept_offer" string="accept" type="object" invisible="status in ['accepted', 'refused']" />
<button name="action_refuse_offer" string="refuse" type="object" invisible="status in ['accepted', 'refused']" />
</group>
</sheet>
</form>
</field>
</record>
</odoo>

Choose a reason for hiding this comment

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

EOL missing.

17 changes: 17 additions & 0 deletions Estate/views/estate_property_tags_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<odoo>
<record id="action_estate_property_tag" model="ir.actions.act_window">
<field name="name">Property Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
</record>
<record id="view_estate_property_tag_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>
<field name="name"/>
<field name="color" widget="color_picker"/>
</list>
</field>
</record>
</odoo>
40 changes: 40 additions & 0 deletions Estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<odoo>
<record id="estate_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="view_estate_property_type_list" 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="view_estate_property_type_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>
<header>
<field name="offer_count" string="Offers:-" readonly="1"/>
</header>
<group>
<field name="name"/>
<field name="property_ids" widget="one2many_list">
<list>
<field name="name"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="state"/>
</list>
</field>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
Loading