Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.insertFinalNewline": true
}

Choose a reason for hiding this comment

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

Ironically, this is missing the newline :x

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
103 changes: 103 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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 = "Estate Property"
_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_price", 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_price(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()
if self.state == "cancelled":
raise UserError("Error - You cannot sell a cancelled property !")
offers = self.offer_ids.search([('property_id', '=', self.id)])
if len(offers.filtered(lambda offer: offer.status == 'accepted')) == 0:
raise UserError("Error - No offer created for this property !")
self.state = "sold"
return True

def cancel_property(self):
self.ensure_one()
if self.state == "sold":
raise UserError("Error - You cannot cancel a sold property !")
self.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 :)

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


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Estate Property Offer"
_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:
if self.env['estate.property'].browse(val['property_id']).state == 'sold':
raise UserError("You cannot create an offer for a sold property !")
offers = self.env['estate.property.offer'].search([('property_id', '=', val['property_id'])])
if offers and val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")
offers = super().create(vals_list)
offers.property_id.state = 'offer_received'
return offers
Comment on lines +48 to +58

Choose a reason for hiding this comment

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

Suggested change
@api.model_create_multi
def create(self, vals_list):
for val in vals_list:
if self.env['estate.property'].browse(val['property_id']).state == 'sold':
raise UserError("You cannot create an offer for a sold property !")
offers = self.env['estate.property.offer'].search([('property_id', '=', val['property_id'])])
if offers and val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")
offers = super().create(vals_list)
offers.property_id.state = 'offer_received'
return offers
@api.model_create_multi
def create(self, vals_list):
if self.env['estate.property'].search_count([('id', 'in', [val.get('property_id') for val in vals_list]), ('state', '=', 'sold')]): # If the number of corresponding object != 0...
raise UserError("You cannot create an offer for a sold property !")
for val in vals_list:
offers = self.env['estate.property.offer'].search([('property_id', '=', val['property_id'])])
if offers and val['price'] < max(offers.mapped('price')):
raise UserError("You cannot create an offer with a lower amount than an existing offer !")
offers = super().create(vals_list)
offers.property_id.state = 'offer_received'
return offers

Doing browse in a loop is a BIG nono. It means you will do 1 SQL request per element of the recordset, which is extremely bad for performance. Prefer doing checks like this ouside of the loop, with things like this
Also this is a CRUD method so it should go hisher in the ordering

Choose a reason for hiding this comment

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

Also you should use float compare here.
In reality you'd have a currency attached to your price, and you'd use that for comparison.

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 = "Estate Property Tag"
_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 = "Estate Property Type"
_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)
8 changes: 8 additions & 0 deletions estate/models/estate_property_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


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

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
1 change: 1 addition & 0 deletions estate/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_property
77 changes: 77 additions & 0 deletions estate/tests/test_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
from odoo.tests import tagged, Form


@tagged('post_install', '-at_install')
class EstatePropertySoldTestCase(TransactionCase):

@classmethod
def setUpClass(cls):

super().setUpClass()

cls.property = cls.env['estate.property'].create(
[{
'name': 'Beautiful House',
'expected_price': 100000,
}]
)

def test_sell_offer(self):

# (1) Try to sell a property with no offer.
with self.assertRaises(UserError):
self.property.sell_property()

partner = self.env['res.partner'].create(
[{
'name': 'My Favorite Partner'
}]
)
Comment on lines +27 to +31

Choose a reason for hiding this comment

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

Create this guy in the setUp. means the tests will run faster if you need a partner somewhere else in the tests

offer = self.env['estate.property.offer'].create(
[{
'price': 95000,
'partner_id': partner.id,
'property_id': self.property.id
}]
)

# (2) After creating an offer, try to sell the property with no accepted offer.
with self.assertRaises(UserError):
self.property.sell_property()

offer.status = 'accepted'
self.property.sell_property()

# (3) After selling it, verify the state of the property.
self.assertEqual(self.property.state, 'sold')

# (4) Lastly, verify that we cannot create an offer for a sold property.
with self.assertRaises(UserError):
self.env['estate.property.offer'].create({
'partner_id': partner.id,
'property_id': self.property.id,
})

def test_garden_checkbox(self):

property_form = Form(self.property)
property_form.garden = True

# (1) Verify the default values of the garden area and orientation.
self.assertEqual(property_form.garden_area, 10)
self.assertEqual(property_form.garden_orientation, "north")

property_form.garden_area = 120
property_form.garden_orientation = "south"

# (2) Reset the garden to False and check the default values.
property_form.garden = False
self.assertEqual(property_form.garden_area, 0)
self.assertIsNot(property_form.garden_orientation, True)

# (3) Reset the garden to True and verify the default values of the garden area and orientation.
property_form.garden = True
self.assertEqual(property_form.garden_area, 10)
self.assertEqual(property_form.garden_orientation, "north")
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>
Loading