-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ADD] estate: a new module to manage estate properties #164
Open
ouou-odoo
wants to merge
2
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorial-ouou
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
'name': 'Real Estate', | ||
'depends': ['base'], | ||
'category': 'Tutorials', | ||
'application': True, | ||
'data': ['data/ir.model.access.csv', | ||
'views/res_users.xml', | ||
'views/estate_property_offer_views.xml', | ||
'views/estate_property_views.xml', | ||
'views/estate_property_type_views.xml', | ||
'views/estate_property_tag_views.xml', | ||
'views/estate_menus.xml', | ||
], | ||
'demo': [ | ||
"demo/demo.xml", | ||
], | ||
'license': 'AGPL-3' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_prop,access_estate_prop,model_estate_property,base.group_user,1,1,1,1 | ||
access_estate_prop_type,access_estate_prop_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
access_estate_prop_offer,access_estate_prop_offer,model_estate_property_offer,base.group_user,1,1,1,1 | ||
access_estate_prop_tag,access_estate_prop_tag,model_estate_property_tag,base.group_user,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<data> | ||
<record id="model_estate_property_action_cancel" model="ir.actions.server"> | ||
<field name="name">Mass cancel</field> | ||
<field name="model_id" ref="estate.model_estate_property"/> | ||
<field name="binding_model_id" ref="estate.model_estate_property"/> | ||
<field name="binding_view_types">list</field> | ||
<field name="state">code</field> | ||
<field name="code">action = records.action_cancel()</field> | ||
</record> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tools import float_compare | ||
from odoo.fields import Many2many, One2many | ||
|
||
from .helper import format_selection | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = 'estate.property' | ||
_description = 'Estate Property modelisation' | ||
_order = 'id desc' | ||
_sql_constraints = [ | ||
('expected_price_strictly_positive', 'CHECK(expected_price > 0)', 'Expected price must be stricly positive'), | ||
('selling_price_positive', 'CHECK(selling_price >= 0)', 'Selling price must be positive'), | ||
] | ||
|
||
name = fields.Char(required=True, string="Name") | ||
description = fields.Text(string="Description") | ||
postcode = fields.Char(string="Postal code") | ||
date_availability = fields.Date(default=lambda x: fields.Date.today() + relativedelta(months=3), copy=False, | ||
string='Availability date') | ||
expected_price = fields.Float(required=True, string='Expected price') | ||
selling_price = fields.Float(readonly=True, copy=False, string='Selling price') | ||
bedrooms = fields.Integer(default=2, string='Bedrooms') | ||
living_area = fields.Integer(string='Living area') | ||
facades = fields.Integer(string='Facades') | ||
garage = fields.Boolean(string='Garage') | ||
garden = fields.Boolean(string='Garden') | ||
garden_area = fields.Integer(string='Garden area') | ||
garden_orientation = fields.Selection(string='Orientation', | ||
selection=format_selection(['north', 'south', 'east', 'west']), | ||
) | ||
active = fields.Boolean(default=True, string='Active') | ||
state = fields.Selection(string='State', | ||
selection=format_selection( | ||
['new', 'offer received', 'offer accepted', 'sold', 'canceled']), | ||
default='new') | ||
|
||
property_type_id = fields.Many2one('estate.property.type', string='Property type') | ||
|
||
buyer_id = fields.Many2one('res.partner', copy=False, string='Buyer') | ||
salesperson_id = fields.Many2one('res.users', default=lambda self: self.env.user, string='Salesperson') | ||
|
||
tag_ids = Many2many('estate.property.tag', string='Tags') | ||
offer_ids = One2many('estate.property.offer', 'property_id', string='Offers') | ||
|
||
total_area = fields.Integer(compute='_compute_total_area', string='Total area') | ||
best_price = fields.Float(compute='_compute_best_price', string='Best offer price') | ||
|
||
@api.depends('living_area', 'garden_area') | ||
def _compute_total_area(self): | ||
for estate in self: | ||
estate.total_area = estate.living_area + estate.garden_area | ||
|
||
@api.depends('offer_ids') | ||
def _compute_best_price(self): | ||
for estate in self: | ||
estate.best_price = max(estate.offer_ids.mapped('price'), default=0) | ||
|
||
@api.onchange('garden') | ||
def _onchange_garden(self): | ||
self.garden = [0, 10][self.garden] | ||
self.garden_orientation = ['', 'north'][self.garden] | ||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow using a boolean as a list index is criminal ahah use 0 if self.garden else 10 at least ahaa |
||
|
||
@api.constrains('selling_price') | ||
def _check_price_offer_reasonable(self): | ||
if float_compare(self.selling_price, 0.9 * self.expected_price, 3) <= 0: | ||
raise ValidationError(_('The selling price must be at least 90% of the expected price.')) | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def _unlink_property_if_not_new_nor_canceled(self): | ||
self.ensure_one() | ||
if self.state not in ('new', 'canceled'): | ||
raise UserError(_('Only new and canceled properties can be deleted.')) | ||
|
||
def action_sold(self): | ||
self.ensure_one() | ||
if self.state == 'canceled': | ||
raise UserError(_('Canceled properties cannot be sold.')) | ||
self.state = 'sold' | ||
return True | ||
|
||
def action_cancel(self): | ||
self.ensure_one() | ||
if self.state == 'sold': | ||
raise UserError(_('Sold properties cannot be canceled.')) | ||
self.state = 'canceled' | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import UserError | ||
|
||
from .helper import format_selection | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = 'estate.property.offer' | ||
_order = 'price desc' | ||
_description = 'Offer modelisation' | ||
_sql_constraints = [('offer_price_strictly_positive', 'CHECK(price > 0)', 'Offer price must be stricly positive')] | ||
|
||
price = fields.Float(string='Price', required=True) | ||
status = fields.Selection(copy=False, selection=format_selection(['accepted', 'refused']), string='Status') | ||
partner_id = fields.Many2one('res.partner', required=True, string='Buyer') | ||
property_id = fields.Many2one('estate.property', required=True, string='Property') | ||
|
||
validity = fields.Integer(default=7, string="Validity") # in days | ||
date_deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline', string='Deadline') | ||
|
||
property_type_id = fields.Many2one(related='property_id.property_type_id', string='Property type') | ||
|
||
@api.depends('validity') | ||
def _compute_deadline(self): | ||
for offer in self: | ||
offer.date_deadline = fields.Date.today() + relativedelta(days=offer.validity) | ||
|
||
def _inverse_deadline(self): | ||
for offer in self: | ||
offer.validity = (offer.date_deadline - fields.Date.today()).days | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for vals in vals_list: | ||
property_id = self.env['estate.property'].browse(vals['property_id']) | ||
if any(vals['price'] < offer.price for offer in property_id.offer_ids): | ||
raise UserError(_('Offer price must be higher than existing offers.')) | ||
property_id.state = 'offer received' | ||
return super().create(vals_list) | ||
|
||
def action_accept(self): | ||
self.ensure_one() | ||
if self.property_id.state == 'sold': | ||
raise UserError(_('The house was already sold.')) | ||
self.status = 'accepted' | ||
self.property_id.state = 'offer accepted' | ||
self.property_id.buyer_id = self.partner_id | ||
self.property_id.se.selling_price): | ||
raise UserError(_('Customer or selling price was not set.')) | ||
'refused' | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = 'estate.property.tag' | ||
_order = 'name asc' | ||
_description = 'Tag modelisation' | ||
_sql_constraints = [('unique_name', 'unique(name)', 'Tag name must be unique')] | ||
|
||
name = fields.Char(required=True, string='Tag Name') | ||
color = fields.Integer(string='Color Index') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = 'estate.property.type' | ||
_description = 'Estate Property Type modelisation' | ||
_order = 'sequence asc, name asc' | ||
_sql_constraints = [('unique_name', 'unique(name)', 'Type name must be unique')] | ||
|
||
name = fields.Char(required=True, string='Name') | ||
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') | ||
sequence = fields.Integer(default=1) | ||
|
||
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') | ||
offer_count = fields.Integer(compute='_compute_offer_count', string='Offer Count') | ||
|
||
def _compute_offer_count(self): | ||
for record in self: | ||
record.offer_count = len(record.offer_ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def format_selection(l: list): | ||
return [(field, field.title()) for field in l] | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Criminel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class Users(models.Model): | ||
_inherit = 'res.users' | ||
|
||
property_ids = fields.One2many('estate.property', 'salesperson_id', | ||
domain=[('state', 'not in', ['sold', 'canceled'])]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<odoo> | ||
<menuitem id="root_menu" name="Real Estate"/> | ||
<menuitem id="ads_menu" name="Advertisements" parent="root_menu"/> | ||
<menuitem id="prop_settings_menu" name="Settings" parent="root_menu"/> | ||
<menuitem id="prop_menu" action="property_action" parent="ads_menu"/> | ||
<menuitem id="prop_type_menu" action="property_type_action" parent="prop_settings_menu"/> | ||
<menuitem id="prop_tag_menu" action="property_tag_action" parent="prop_settings_menu"/> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<odoo> | ||
<record id="property_offer_action" model="ir.actions.act_window"> | ||
<field name="name">Property Offers</field> | ||
<field name="res_model">estate.property.offer</field> | ||
<field name="domain">[('property_type_id', '=', active_id)]</field> | ||
<field name="view_mode">list</field> | ||
</record> | ||
|
||
|
||
<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 decoration-success="status == 'accepted'" | ||
decoration-danger="status == 'refused'"> | ||
<field name="price"/> | ||
<field name="partner_id"/> | ||
<field name="validity" string="Validity (days)"/> | ||
<field name="date_deadline" string="Deadline"/> | ||
<button name="action_accept" type="object" icon="fa-check" | ||
invisible="status"/> | ||
<button name="action_refuse" type="object" icon="fa-times" | ||
invisible="status"/> | ||
<field name="status" string="Status"/> | ||
</list> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<odoo> | ||
<record id="property_tag_action" model="ir.actions.act_window"> | ||
<field name="name">Properties Tags</field> | ||
<field name="res_model">estate.property.tag</field> | ||
<field name="view_mode">list</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<odoo> | ||
<record id="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="Property Type List"> | ||
<field name="sequence" widget="handle"/> | ||
<field name="name"/> | ||
</list> | ||
</field> | ||
</record> | ||
|
||
<record id="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="Property Form"> | ||
<sheet> | ||
<div name="button_box" position="inside"> | ||
<button class="oe_stat_button" name="%(action_property_offer)d" type="action" | ||
string="View Offers" | ||
icon="fa-money"> | ||
<field string="Offers" name="offer_count" widget="statinfo"/> | ||
</button> | ||
</div> | ||
<group> | ||
<field name="name"/> | ||
</group> | ||
|
||
<notebook> | ||
<page string="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="property_type_action" model="ir.actions.act_window"> | ||
<field name="name">Properties Types</field> | ||
<field name="res_model">estate.property.type</field> | ||
<field name="view_mode">list,form</field> | ||
</record> | ||
</odoo> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, just use
fields.Many2many
directly since it is already imported