Skip to content

[ADD] estate: New module to manage estates #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 42 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5e4d31e
[ADD] estate: Creating apps and models
baje-odoo Jun 17, 2025
23ad338
[IMP] estate: Add Security rules
baje-odoo Jun 17, 2025
902379a
[IMP] estate: Add fields and parameters to models estate_property
baje-odoo Jun 18, 2025
9420b3a
[IMP] estate: Add list view
baje-odoo Jun 18, 2025
ef18c3f
[FIX] estate: pipeline fix
baje-odoo Jun 18, 2025
1be0e7a
[IMP] estate: Add form view
baje-odoo Jun 18, 2025
8ec4cb4
[IMP] estate: Add Searchbar view
baje-odoo Jun 18, 2025
9182210
[IMP] estate: Add many2one relations
baje-odoo Jun 18, 2025
c316dd2
[IMP] estate: Add many2many relations
baje-odoo Jun 18, 2025
b398197
[IMP] estate: Add one2many relations
baje-odoo Jun 18, 2025
5786a59
[IMP] estate: Add compute and inverse
baje-odoo Jun 18, 2025
0422878
[IMP] estate: Add onchange method
baje-odoo Jun 18, 2025
2949458
[IMP] estate: Add buttons
baje-odoo Jun 18, 2025
9d776f7
[IMP] estate: Add constraints
baje-odoo Jun 19, 2025
1d69faf
[IMP] estate: Add Inline views - widgets - list order - attributes
baje-odoo Jun 19, 2025
716c663
[IMP] estate: Add stat button
baje-odoo Jun 19, 2025
2a00cff
[IMP] estate: Add create and delete conditions - user inheritance
baje-odoo Jun 19, 2025
bfdb4ba
[ADD] estate_account: Add link between estate and account
baje-odoo Jun 20, 2025
9a0df1a
[IMP] estate: Add kanban view
baje-odoo Jun 20, 2025
199b3c2
[IMP] estate: Add more informations on cards
baje-odoo Jun 20, 2025
d5a3567
[REF] estate: Refactoring to the coding guidelines
baje-odoo Jun 20, 2025
2c139ac
[ADD] awesome_owl: implement counter and card
baje-odoo Jun 23, 2025
290ffe1
[IMP] awesome_owl: Add Markup use to card
baje-odoo Jun 23, 2025
2ad352d
[IMP] awesome_owl: Add validation - callbacks - foreach
baje-odoo Jun 23, 2025
58f4c23
[IMP] awesome_owl: Add dynamic attributes and event handler
baje-odoo Jun 23, 2025
9644d50
[IMP] awesome_owl: Add autofocus on todo list
baje-odoo Jun 23, 2025
3355116
[IMP] awesome_owl: Add deleting button on todo items
baje-odoo Jun 23, 2025
4a021e2
[IMP] awesome_owl: Add slots
baje-odoo Jun 23, 2025
374b700
[IMP] awesome_owl: Add t-if
baje-odoo Jun 23, 2025
e7ab77e
[ADD] awesome_dashboard: Add base layout
baje-odoo Jun 24, 2025
82592bd
[IMP] awesome_dashboard: Add navigation and dashboard item
baje-odoo Jun 24, 2025
fa0e393
[IMP] awesome_dashboard: Call the server to show statistics
baje-odoo Jun 24, 2025
d704def
[IMP] awesome_dashboard: Add statistics service
baje-odoo Jun 24, 2025
e0c0418
[IMP] awesome_dashboard: Add pie chart
baje-odoo Jun 24, 2025
d2cdb2a
[IMP] awesome_dashboard: reactive use
baje-odoo Jun 25, 2025
a0dabb8
[MOV] awesome_dashboard: made bundle folder for dashboard
baje-odoo Jun 25, 2025
1207f8c
[MOV] awesome_dashboard: made a pie chart folder
baje-odoo Jun 25, 2025
a5d023c
[IMP] awesome_dashboard: Generic Dashboard
baje-odoo Jun 25, 2025
8f2fe66
[IMP] awesome_dashboard: Extensible Dashboard
baje-odoo Jun 25, 2025
35aa75a
[IMP] awesome_dashboard: Add a dialog to configure the items
baje-odoo Jun 25, 2025
cf8ca37
[IMP] estate: Add master and demo data
baje-odoo Jun 26, 2025
1595efc
[IMP] estate: Add demo offers
baje-odoo Jun 26, 2025
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.languageServer": "None"

Choose a reason for hiding this comment

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

Of course, on real PRs, such files wouldn't be included.

}
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
21 changes: 21 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
'name': "estate",
'version': '18.0.1.0.0',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_type_views.xml',
'views/res_users_views.xml',
'views/estate_menus.xml',
],
'author': "baje",
'category': 'Uncategorized',
'description': """
An app to manage a Real Estate Agency
""",
'application': True,
'license': 'LGPL-3',
}
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_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
104 changes: 104 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from odoo import fields, models, api, _
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
"""Model representing a real estate property."""

_name = "estate.property"
_description = "Real Estate Properties"
_order = "id desc"
_sql_constraints = [
('check_expected_price', 'CHECK(expected_price > 0 )', 'Expected price must be strictly positive.'),
('check_selling_price', 'CHECK(selling_price >= 0 )', 'Selling price must be positive.'),
]

def _default_date_availability(self):
return fields.Date.today() + relativedelta(months=3)

name = fields.Char("Title", required=True)
description = fields.Text("Description")
postcode = fields.Char("Postcode")
date_availability = fields.Date("Available From", default=_default_date_availability)
expected_price = fields.Float("Expected Price", required=True)
selling_price = fields.Float("Selling Price", readonly=True, copy=False)
bedrooms = fields.Integer("Bedrooms", default=2)
living_area = fields.Integer("Living Area (sqm)")
facades = fields.Integer("Facades")
garage = fields.Boolean("Garage")
garden = fields.Boolean("Garden")
garden_area = fields.Integer("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="Status",
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('canceled', "Canceled"),
],
required=True,
copy=False,
default="new",
)
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
user_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user)
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Integer("Total Area (sqm)", compute="_compute_total_area")
best_price = fields.Float("Best Offer", compute="_compute_best_price")

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

@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.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

def action_sold(self):
for record in self:
if record.state == 'canceled':
raise UserError(_("Canceled properties cannot be sold."))
record.state = 'sold'

def action_cancel(self):
for record in self:
if record.state == 'sold':
raise UserError(_("Sold properties cannot be canceled."))
record.state = 'canceled'

@api.constrains('expected_price', 'selling_price')
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_rounding=0.01) and float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=0.01) < 0:
raise ValidationError(_("The selling price cannot be lower than 90% of the expected price."))

@api.ondelete(at_uninstall=False)
def _unlink_if_state_is_new_or_cancelled(self):
if any(record.state not in ('new', 'canceled') for record in self):
raise UserError(_("Only new and canceled properties can be deleted."))
65 changes: 65 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from odoo import fields, models, api, _
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_compare


class EstatePropertyOffer(models.Model):
"""Model representing an offer for a real estate property."""

_name = "estate.property.offer"
_description = "Real Estate Property Offers"
_order = "price desc"
_sql_constraints = [
('check_offer_price', 'CHECK(price > 0)', 'An offer price must be strictly positive.'),
]

price = fields.Float(string="Price")
status = fields.Selection(
string="Status",
selection=[
('accepted', "Accepted"),
('refused', "Refused"),
],
copy=False,
)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer("Validity (days)", default=7)
deadline = fields.Date("Deadline", compute="_compute_deadline", inverse="_inverse_deadline")
property_type_id = fields.Many2one(
"estate.property.type", related="property_id.property_type_id", string="Property Type")

@api.depends("validity")
def _compute_deadline(self):
for record in self:
record.deadline = fields.Date.today() + relativedelta(days=record.validity)

def _inverse_deadline(self):
for record in self:
record.validity = (record.deadline - fields.Date.today()).days

def action_accept(self):
if 'accepted' in self.mapped("property_id.offer_ids.status"):
raise UserError(_("An offer is already accepted."))
for record in self:
record.status = 'accepted'
record.property_id.state = 'offer_accepted'
record.property_id.buyer_id = record.partner_id
record.property_id.selling_price = record.price

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

@api.model_create_multi
def create(self, values):
for vals in values:
if vals.get("property_id") and vals.get("price"):
prop = self.env["estate.property"].browse(vals["property_id"])
if prop.offer_ids:
max_offer = max(prop.mapped("offer_ids.price"))
if float_compare(vals["price"], max_offer, precision_rounding=0.01) <= 0:
raise UserError(_("The offer must be higher than %.2f."), max_offer)
prop.state = "offer_received"
return super().create(values)
15 changes: 15 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class EstatePropertyTag(models.Model):
"""Model representing a property tag."""

_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_order = "name"
_sql_constraints = [
('unique_name', 'UNIQUE(name)', 'The tag name must be unique.'),
]

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


class EstatePropertyType(models.Model):
"""Model representing a property type."""

_name = "estate.property.type"
_description = "Real Estate Property Type"
_order = "name"
_sql_constraints = [
('unique_name', 'UNIQUE(name)', 'The type name must be unique.'),
]

name = fields.Char("Name", required=True)
sequence = fields.Integer("Sequence", default=10)
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers")
offer_count = fields.Integer(string="Offers Count", compute="_compute_offer_count")

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)

def action_view_offers(self):
res = self.env.ref("estate.estate_property_offer_action").read()[0]
res["domain"] = [("id", "in", self.offer_ids.ids)]
return res
11 changes: 11 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class ResUsers(models.Model):
"""Model extending users"""

_inherit = "res.users"

property_ids = fields.One2many(
"estate.property", "user_id", string="Properties", domain=[("state", "in", ["new", "offer_received"])],
)
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_estate_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="estate_menu_root" name="Real Estate">
<menuitem id="estate_advertisement_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_settings_menu" name="Settings">
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action"/>
</menuitem>
</menuitem>
</odoo>
19 changes: 19 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<odoo>
<record id="estate_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>
<record id="estate_property_offer_view_list" model="ir.ui.view">
<field name="name">estate.property.offer.view.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list string="Property Offers" editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
<field name="price"/>
<field name="partner_id"/>
<button name="action_accept" type="object" title="Accept" icon="fa-check"/>
<button name="action_refuse" type="object" title="Refuse" icon="fa-times"/>
</list>
</field>
</record>
</odoo>
16 changes: 16 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<record id="estate_property_tag_action" 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="estate_property_tag_view_list" model="ir.ui.view">
<field name="name">estate.property.tag.view.list</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list string="Property Tags" editable="bottom">
<field name="name"/>
</list>
</field>
</record>
</odoo>
51 changes: 51 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<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="estate_property_type_view_form" model="ir.ui.view">
<field name="name">estate.property.type.view.form</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
</div>
<div class="oe_button_box" name="button_box">
<button name="action_view_offers"
type="object"
class="oe_stat_button"
icon="fa-tags">
<field name="offer_count" widget="statinfo" string="Offers"/>
</button>
</div>
<notebook>
<page string="Properties">
<field name="property_ids">
<list>
<field name="name"/>
<field name="expected_price"/>
<field name="state"/>
</list>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="estate_property_type_view_list" model="ir.ui.view">
<field name="name">estate.property.type.view.list</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<list string="Types">
<field name="sequence" widget="handle" />
<field name="name"/>
</list>
</field>
</record>
</odoo>
Loading