Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f8e1bc0
[ADD] Estate:createthe app
jedel-odoo Oct 20, 2025
c558c6b
[IMP] estate : set application to True
jedel-odoo Oct 20, 2025
cd52496
[IMP] Estate : Chapter 3
jedel-odoo Oct 20, 2025
8cb8dc5
[IMP] estate : add security model
jedel-odoo Oct 20, 2025
a0182ea
[IMP] estate : adding menus and fields
jedel-odoo Oct 20, 2025
a449045
[IMP] estate : adding custom views (chapter 6)
jedel-odoo Oct 21, 2025
ded2b66
[IMP] estate : adding types, tags and offers (chapter 7)
jedel-odoo Oct 21, 2025
286c828
[IMP] estate: Add notes.
Mathilde411 Oct 21, 2025
fa3f1ea
[IMP] estate: adding computed fields and onchanges (chapter 8)
jedel-odoo Oct 21, 2025
f9ed8a6
[IMP] estate: adding computed fields and onchanges (chapter8)
jedel-odoo Oct 21, 2025
2ff906f
[IMP] estate: style corrections
jedel-odoo Oct 21, 2025
67147af
[IMP] estate: tutorials corrections
jedel-odoo Oct 21, 2025
a0a6f39
[IMP] estate: tutorials corrections
jedel-odoo Oct 21, 2025
abc4cdf
[IMP] estate: adding buttons (chapter 9
jedel-odoo Oct 21, 2025
1c19652
[IMP] estate: corrections
jedel-odoo Oct 21, 2025
c5e045e
[IMP] estate: adding constraints (chapter 10)
jedel-odoo Oct 22, 2025
3ef6943
[IMP] estate: adding sprinkels (chapter 11)
jedel-odoo Oct 22, 2025
6a76b10
[IMP] estate: adding user inheritance (chapter 12)
jedel-odoo Oct 22, 2025
dd2110b
[IMP] estate: style corrections
jedel-odoo Oct 22, 2025
a4d520a
[ADD] estate_account: adding a child class
jedel-odoo Oct 23, 2025
25c5923
[IMP] estate, estate_account: style corrections
jedel-odoo Oct 23, 2025
383a8d6
[IMP] estate: kanban view
jedel-odoo Oct 23, 2025
f19a562
[IMP] estate: corrections
jedel-odoo Oct 23, 2025
1313f2b
[IMP] estate: corrections
jedel-odoo Oct 23, 2025
47aa27d
[IMP] estate: adding some tests
jedel-odoo Oct 24, 2025
92f8ce1
[FIX] estate: corrections
jedel-odoo Oct 24, 2025
7cc8a96
[IMP] estate: add demo data
jedel-odoo Nov 3, 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
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': "Real Estate",
'depends': ['base'],
'application': True,
'author': "Jeanne Delneste",
'license': "LGPL-3",
'data': [
'views/estate_property_views.xml',
'views/estate_property_user_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_menus.xml',
'security/ir.model.access.csv'
],
}
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 estate_property_user
96 changes: 96 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from odoo import api, models, fields
from odoo.exceptions import UserError
import datetime
from dateutil.relativedelta import relativedelta
from odoo.tools.float_utils import float_compare, float_is_zero


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

Choose a reason for hiding this comment

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

Suggested change
_description = "Property for the Real Estate app"
_description = "Estate Property"

_description contains a short human-readable name for the model

_order = "id desc"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
notes = fields.Html()
date_availability = fields.Date(copy=False, default=lambda self: datetime.date.today() + relativedelta(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()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")])
active = fields.Boolean(default=True)
state = fields.Selection(selection=[("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")], copy=False, required=True, default="new")
property_type_id = fields.Many2one("estate.property.type", string="Type")
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
salesperson_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user)
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Integer(compute="_compute_total_area", string="Total Area (sqm)")
best_price = fields.Float(compute="_compute_best_offer", string="Best Offer")

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

@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_offer(self):
for record in self:
prices = record.offer_ids.mapped("price")
if len(prices) > 0:
record.best_price = max(prices)
else:
record.best_price = 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 = None

def sell_property(self):
self.ensure_one()
for record in self:
if record.state == "cancelled":
raise UserError("Error - You cannot sell a cancelled property !")
record.state = "sold"
return True

def cancel_property(self):
self.ensure_one()
for record in self:
if record.state == "sold":
raise UserError("Error - You cannot cancel a sold property !")
record.state = "cancelled"
return True

@api.constrains('expected_price', 'selling_price')
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=3):
if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=3) < 0:
raise UserError(r"The selling price must be at least 90% of the expected price !")

@api.ondelete(at_uninstall=False)
def _unlike_if_stats_new_or_cancelled(self):
for record in self:
if record.state in ('new', 'cancelled'):
raise UserError("You cannot delete a new or cancelled property !")
Comment on lines +99 to +103

Choose a reason for hiding this comment

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

Suggested change
@api.ondelete(at_uninstall=False)
def _unlike_if_stats_new_or_cancelled(self):
for record in self:
if record.state in ('new', 'cancelled'):
raise UserError("You cannot delete a new or cancelled property !")
@api.ondelete(at_uninstall=False)
def _unlink_if_stats_new_or_cancelled(self):
for record in self:
if record.state in ('new', 'cancelled'):
raise UserError("You cannot delete a new or cancelled property !")

Spelling.
Also method ordering ! This is one of the CRUD methods, it should go higher :)

57 changes: 57 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from odoo import api, models, fields
from odoo.exceptions import UserError
import datetime


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Offers for properties"
_order = "price desc"

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

_positive_price = models.Constraint(
'CHECK(price > 0)',
'The price of an offer must be strictly positive'
)

@api.depends("create_date", "validity")
def _compute_deadline(self):
for offer in self:
offer.date_deadline = fields.Date.add((offer.create_date or datetime.date.today()), days=offer.validity)

def _inverse_deadline(self):
for offer in self:
delta = offer.date_deadline - (fields.Date.to_date(offer.create_date) or fields.Date.to_date(datetime.date.today()))
offer.validity = delta.days

def accept_offer(self):
for offer in self:
for other_offer in offer.property_id.offer_ids:
if other_offer.status == "accepted" and offer.id != other_offer.id:
raise UserError("An offer is already accepted...")
offer.status = "accepted"
offer.property_id.buyer_id = offer.partner_id
offer.property_id.selling_price = offer.price
offer.property_id.state = 'offer_accepted'

def refuse_offer(self):
for offer in self:
offer.status = "refused"
Comment on lines +45 to +46

Choose a reason for hiding this comment

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

Suggested change
for offer in self:
offer.status = "refused"
self.status = "refused"
return True

Assigning attributes on recordsets works !


@api.model_create_multi
def create(self, vals_list):
for val in vals_list:
offers = self.env['estate.property.offer'].search([('property_id', '=', val['property_id'])])
if len(offers) > 0:
if val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")

Choose a reason for hiding this comment

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

Suggested change
if len(offers) > 0:
if val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")
if offers and val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")

Cleaner that way :)If you have an empty recordset, it will automatically be cast to False

offers = super().create(vals_list)
offers.property_id.state = 'offer_received'
return offers
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 models, fields


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Tag of properties"
_order = "name asc"

name = fields.Char(required=True)
color = fields.Integer()

_unique_tag = models.Constraint(
'unique(name)',
'The tag name must be unique',
)
23 changes: 23 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from odoo import api, models, fields


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Type of properties"
_order = "name asc"

name = fields.Char(required=True)
property_ids = fields.One2many("estate.property", "property_type_id")
sequence = fields.Integer('Sequence', default=1)
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
offer_count = fields.Integer(compute="_compute_count_offer")

_unique_type = models.Constraint(
'unique(name)',
'The type name must be unique',
)

@api.depends("offer_ids")
def _compute_count_offer(self):
for record in self:
record.offer_count = len(record.offer_ids)
7 changes: 7 additions & 0 deletions estate/models/estate_property_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


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

property_ids = fields.One2many("estate.property", "salesperson_id", 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
estate.access_estate_property,access_estate_property,model_estate_property,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_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_menu_advertissements" name="Advertissements">
<menuitem id="estate_property_menu" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_menu_settings" name="Settings">
<menuitem id="estate_property_types_menu" action="estate_property_type_action"/>
<menuitem id="estate_property_tags_menu" action="estate_property_tag_action"/>
</menuitem>
</menuitem>
</odoo>
26 changes: 26 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<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 string="List View" editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='refused'">
<field name="price" width="200px"/>
<field name="partner_id" width="300px"/>
<field name="validity" width="100px"/>
<field name="date_deadline" width="100px"/>
<button name="accept_offer" type="object" string="Accept" icon="fa-check" width="50px" invisible="status in ('accepted', 'refused')"/>
<button name="refuse_offer" type="object" string="Refuse" icon="fa-times" width="50px" invisible="status in ('accepted', 'refused')"/>
<field name="property_type_id" optional="hide"/>
<field name="status" width="100px" optional="hide"/>
</list>
</field>
</record>

<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>
</odoo>
17 changes: 17 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_tag_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="List View" editable="bottom">
<field name="name"/>
</list>
</field>
</record>
<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</field>
</record>
</odoo>
57 changes: 57 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_type_view_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 string="List View">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="offer_ids" optional="hide"/>
<field name="offer_count" optional="hide"/>
</list>
</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 string="Estate Property Type">
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="%(estate.estate_property_offer_action)d"
type="action" icon="fa-money">
<div class="o_stat_info">
<span class="o_stat_text">
Offres
</span>
</div>
</button>
</div>
<div class="oe_title">
<h1><field name="name"/></h1>
</div>
<separator/>
<notebook>
<page name="Properties">
<field name="property_ids">
<list>
<field name="name" string="Title"/>
<field name="expected_price"/>
<field name="state"/>
</list>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<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>
</odoo>
18 changes: 18 additions & 0 deletions estate/views/estate_property_user_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="estate_property_users_view_form" model="ir.ui.view">
<field name="name">res.users.view.form.inherit.estate</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<notebook>
<page string="Properties">
<field name="property_ids"/>
</page>
</notebook>
</field>
</record>

</data>
</odoo>
Loading