Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
3 changes: 3 additions & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

Comment on lines +1 to +2

Choose a reason for hiding this comment

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

The odoo license in every file is not needed anymore. You can remove it!

from . import models
24 changes: 24 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
'name': "Real Estate",
'version': '1.0',
'depends': ['base'],
'author': "taskv",
'category': 'Tutorials',
'description': """
Tutorial Project
""",
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_menus.xml',
'views/res_users_views.xml',
],
'demo': [
],
Comment on lines +19 to +20

Choose a reason for hiding this comment

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

you don't need to specify demo if it's empty

'installable': True,
'application': True,
'license': 'LGPL-3',
}
7 changes: 7 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

Comment on lines +1 to +2

Choose a reason for hiding this comment

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

Also you can remove that license, it's not needed anymore for any new odoo files

from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
Comment on lines +3 to +7

Choose a reason for hiding this comment

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

You just need to sort all imports by alphabetical order like here
https://www.odoo.com/documentation/19.0/contributing/development/coding_guidelines.html#imports
Screenshot 2025-11-21 at 10 39 33

106 changes: 106 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models, api, exceptions
from odoo.tools.float_utils import float_is_zero, float_compare


class EstateProperty(models.Model):
_name = 'estate.property'
_description = 'Estate Property'
_order = "id desc"

name = fields.Char('Title', required=True, default='Unknown', translate='True')
active = fields.Boolean('Active', default=True)
description = fields.Text('Description')
postcode = fields.Char('Postcode')
date_availability = fields.Date('Available From', copy=False, default=fields.Date.add(fields.Date.today(), months=3))
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')]
)
Comment on lines +25 to +30

Choose a reason for hiding this comment

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

This indentation is a little bit strange, I would do something like this

Suggested change
garden_orientation = fields.Selection(string='Garden orientation',
selection=[('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West')]
)
garden_orientation = fields.Selection(
string='Garden orientation',
selection=[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West'),
],
)

state = fields.Selection(string='State',
selection=[('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled')],
default='new', required=True, copy=False)
Comment on lines +31 to +37

Choose a reason for hiding this comment

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

Same, the indent is a little bit weird, it looks better to just have one argument per line here

Suggested change
state = fields.Selection(string='State',
selection=[('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled')],
default='new', required=True, copy=False)
state = fields.Selection(
string='State',
selection=[
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled'),
],
default='new',
required=True,
copy=False,
)

property_type_id = fields.Many2one('estate.property.type', string='Property Type')
property_tag_ids = fields.Many2many('estate.property.tag', string='Property Tag')
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False,
domain=[('is_company', '=', False)])
salesperson_id = fields.Many2one('res.users', string='Salesperson',
default=lambda self: self.env.user)
offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers')
total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area')
best_offer = fields.Float('Best Offer', compute='_compute_best_offer')

_check_expected_price = models.Constraint(
'CHECK(expected_price > 0)',
'The expected price must be strictly positive',
)

_check_selling_price = models.Constraint(
'CHECK(selling_price >= 0)',
'The selling price must be positive',
)

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, 4) and float_compare(record.selling_price, record.expected_price * 0.9, 4) < 0:
raise exceptions.ValidationError("The selling price must be at least 90% of the expected price.")

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

@api.depends('offer_ids.price')
def _compute_best_offer(self):
for record in self:
if record.offer_ids:
record.best_offer = max(record.offer_ids.mapped('price'))
else:
record.best_offer = 0
Comment on lines +66 to +69

Choose a reason for hiding this comment

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

you can just do this

Suggested change
if record.offer_ids:
record.best_offer = max(record.offer_ids.mapped('price'))
else:
record.best_offer = 0
record.best_offer = max(record.offer_ids.mapped('price'), default=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 = ''

@api.ondelete(at_uninstall=False)
def _unlink_check_state(self):
for record in self:
if record.state not in ('new', 'cancelled'):
raise exceptions.UserError("Only new and cancelled properties can be deleted.")

def property_sold(self):
for record in self:
if record.state != 'cancelled':
record.state = 'sold'
else:
raise exceptions.UserError("Cancelled properties cannot be sold.")
return True

def property_cancelled(self):
for record in self:
if record.state != 'sold':
record.state = 'cancelled'
else:
raise exceptions.UserError("Sold properties cannot be cancelled.")
return True
59 changes: 59 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

Choose a reason for hiding this comment

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

Same, you don't need to put the odoo license in every file anymore


from odoo import fields, models, api, exceptions
from datetime import date, timedelta


class EstatePropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = 'Estate Property Offer'
_order = "price desc"

price = fields.Float(string='Price')
status = fields.Selection(string='Status', copy=False,
selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
Comment on lines +13 to +14

Choose a reason for hiding this comment

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

Same, this indentation looks a little bit strange. When you have multiline arguments IMO it's better to do one argument per line

Suggested change
status = fields.Selection(string='Status', copy=False,
selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
status = fields.Selection(
string='Status',
copy=False,
selection=[('accepted', 'Accepted'), ('refused', 'Refused')]
)

partner_id = fields.Many2one('res.partner', string='Customer', required=True)
property_id = fields.Many2one('estate.property', string='Property', required=True)
validity = fields.Integer(string='Validity (days)', default=7)
date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_inverse_deadline')
property_type_id = fields.Many2one('estate.property.type', string='Property Type', related="property_id.property_type_id", store=True)

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

@api.model

Choose a reason for hiding this comment

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

You already support a list of dicts, you can add @api.model_create_multi decorator

def create(self, vals_list):
for vals in vals_list:
if 'property_id' in vals and vals.get('property_id'):

Choose a reason for hiding this comment

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

You are checking almost the same condition twice

Suggested change
if 'property_id' in vals and vals.get('property_id'):
if vals.get('property_id'):

current_property = self.env['estate.property'].browse(vals['property_id'])
if 'price' in vals and current_property.best_offer > vals.get('price', 0):
raise exceptions.ValidationError(f'The offer must be higher than {current_property.best_offer}')

Choose a reason for hiding this comment

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

Not a problem for the tutorial, but with an actual module, we usually don't use fstrings for errors, as you cannot translate these

Here is an example of how we usually format translated strings with parameters
https://github.com/odoo/odoo/blob/fc658b2e3d9c5afbfa5d00b579bf8928a90dab87/addons/barcodes/models/barcode_rule.py#L41

if current_property.state == 'new':
current_property.state = 'offer_received'
return super().create(vals_list)

@api.depends('validity')
def _compute_deadline(self):
for record in self:
record.date_deadline = (record.create_date if record.create_date else date.today()) + timedelta(days=record.validity)

def _inverse_deadline(self):
for record in self:
record.validity = (record.date_deadline - (record.create_date.date() if record.create_date else date.today())).days

def action_accept(self):
for record in self:
if record.property_id.state in ('new', 'offer_received'):
record.property_id.state = 'offer_accepted'
record.status = 'accepted'
record.property_id.selling_price = record.price
record.property_id.buyer_id = record.partner_id
return True

def action_refuse(self):
for record in self:
if not record.status:
record.status = 'refused'
return True
17 changes: 17 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

Choose a reason for hiding this comment

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

No need license


from odoo import fields, models


class EstatePropertyTag(models.Model):
_name = 'estate.property.tag'
_description = 'Estate Property Tag'
_order = "name"
Comment on lines +8 to +9

Choose a reason for hiding this comment

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

little nitpick, although not everybody respects that at odoo, we have somewhat of a convention for using single vs double quotes. Everything that is user-facing (e.i. everything an end-user will see) is usually double-quoted. Everything else is single quoted (so mostly technical strings).

Suggested change
_description = 'Estate Property Tag'
_order = "name"
_description = "Estate Property Tag"
_order = 'name'


name = fields.Char(string='Property Tag', required=True)
color = fields.Integer()

_tag_name_uniq = models.Constraint(
'unique(name)',
"The property tag name must be unique",
)
25 changes: 25 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models, api


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

name = fields.Char('Property Type', required=True)
property_ids = fields.One2many('estate.property', 'property_type_id', 'Properties')
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', 'Offers')
offer_count = fields.Integer(compute='_compute_offer_count')
sequence = fields.Integer()

_type_name_uniq = models.Constraint(
'unique(name)',
"The property type name must be unique",
)

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
10 changes: 10 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class Users(models.Model):
_inherit = 'res.users'

property_ids = fields.One2many('estate.property', 'salesperson_id', string='Estate Property',
domain=[('date_availability', '<=', fields.Date.today())])
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
29 changes: 29 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<odoo>
<menuitem
id="estate_menu_root"
name="Real Estate"/>
<menuitem
id="properties_menu"
name="Properties"
parent="estate_menu_root"
action="estate_property_action"
sequence="1"/>
<menuitem
id="settings_menu"
name="Settings"
parent="estate_menu_root"
sequence="2"/>
<menuitem
id="properties_type_menu"
name="Property Types"
parent="settings_menu"
action="estate_property_type_action"
sequence="1"/>
<menuitem
id="properties_tag_menu"
name="Property Tags"
parent="settings_menu"
action="estate_property_tag_action"
sequence="2"/>
</odoo>
49 changes: 49 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_offer_view_form" model="ir.ui.view">
<field name="name">estate.property.offer.view.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<form string="Estate Property Offer">
<sheet>
<group>
<group>
<field name="price"/>
<field name="partner_id"/>
</group>
<group>
<field name="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</group>
</group>
</sheet>
</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="Estate Property Offer" editable="bottom"
decoration-success="status == 'accepted'"
decoration-danger="status == 'refused'">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_accept" title="Accept" type="object" icon="fa-check" invisible="status"/>
<button name="action_refuse" title="Refuse" type="object" icon="fa-close" invisible="status"/>
Comment on lines +36 to +37

Choose a reason for hiding this comment

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

these invisibles don't seem correct. I think it should be status in ('accepted', 'refused')

</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,form</field>
<field name="domain">[('property_type_id','=',active_id)]</field>

Choose a reason for hiding this comment

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

Suggested change
<field name="domain">[('property_type_id','=',active_id)]</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>

</record>

</odoo>
35 changes: 35 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_tag_view_form" model="ir.ui.view">
<field name="name">estate.property.tag.view.form</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<form string="Estate Property Tag">
<sheet>
<group>
<field name="name"/>
<field name="color" widget="color_picker"/>
</group>
</sheet>
</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="Estate Property Tag" editable="bottom">
<field name="name"/>
<field name="color" widget="color_picker"/>
</list>
</field>
</record>

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

</odoo>
Loading