-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[WIP] Implementation of estate module #1372
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
Draft
amgom-odoo
wants to merge
15
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-real-estate-amgom
base: 19.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.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6152077
[IMP] estate: Initial setup with models, views, and access rights
amgom-odoo 5bd12fd
[IMP] estate: Finish chapter 5
amgom-odoo 8a2518a
[IMP] add ruff linter and formatter
amgom-odoo 8242bb9
[IMP] estate: finish chapter 6
amgom-odoo 9e501f5
[IMP] estate: Finish chapter 7
amgom-odoo b27f612
[IMP] estate: Finish chapter 8
amgom-odoo 7a5cd9b
[REF] estate: reorganize views files
amgom-odoo 1bb53b3
[IMP] estate: Finish chapter 9
amgom-odoo 2e1d59c
[IMP] estate: Finish chapter 10
amgom-odoo 72ea9c3
[IMP] estate: Finish chapter 11
amgom-odoo ae57e2b
[IMP] estate: Finish chapter 12
amgom-odoo be045c9
[IMP] estate: Finish chapter 13
amgom-odoo fdcf651
[IMP] estate: Finish chapter 14
amgom-odoo 518569f
[IMP] estate: address comments
amgom-odoo a9b3564
[IMP] estate: address comments
amgom-odoo 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 hidden or 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 hidden or 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,21 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "version": "1.0.0", | ||
| "depends": ["base"], | ||
| "author": "Odoo S.A.", | ||
| "license": "LGPL-3", | ||
| "category": "Real Estate", | ||
| "description": """ | ||
| This is a real estate management module that allows users to manage properties, agents, and clients. | ||
| """, | ||
| "application": True, | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_menus.xml", | ||
| "views/res_users_views.xml", | ||
| ], | ||
| } |
This file contains hidden or 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 | ||
| from . import estate_offer | ||
| from . import estate_tag | ||
| from . import estate_type | ||
| from . import res_users |
This file contains hidden or 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,130 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class Estate(models.Model): | ||
| _name = "estate.estate" | ||
| _description = "Real Estate" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| description = fields.Text(string="Description") | ||
| postcode = fields.Char(string="Postcode") | ||
| date_availability = fields.Date( | ||
| string="Available From", | ||
| default=fields.Date.today() + relativedelta(months=3), | ||
| copy=False, | ||
| ) | ||
| expected_price = fields.Float(string="Expected Price", required=True) | ||
| selling_price = fields.Float(string="Selling price", readonly=True, copy=False) | ||
| bedrooms = fields.Integer(string="Bedrooms", default=2) | ||
| 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="Garden Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ("south", "South"), | ||
| ], | ||
| ) | ||
| active = fields.Boolean(string="Active", default=True) | ||
| state = fields.Selection( | ||
| string="Status", | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| type_id = fields.Many2one( | ||
| string="Property Type", | ||
| comodel_name="estate.type", | ||
| ) | ||
| salesman_id = fields.Many2one( | ||
| string="Salesman", | ||
| comodel_name="res.users", | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| buyer_id = fields.Many2one(string="Buyer", comodel_name="res.partner", copy=False) | ||
| tag_ids = fields.Many2many(string="Tags", comodel_name="estate.tag") | ||
| offer_ids = fields.One2many( | ||
| string="Offers", | ||
| comodel_name="estate.offer", | ||
| inverse_name="property_id", | ||
| ) | ||
| total_area = fields.Float(string="Total Area", compute="_compute_total_area") | ||
| best_offer = fields.Float(string="Best Offer", compute="_compute_best_offer") | ||
|
|
||
| _positive_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "Expected price should be strictly positive", | ||
| ) | ||
| _positive_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "Selling price should 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: | ||
| record.best_offer = ( | ||
| max(record.offer_ids.mapped("price")) if len(record.offer_ids) else 0.0 | ||
| ) | ||
|
|
||
| @api.onchange("garden") | ||
| def _on_change_garden(self): | ||
| self.garden_area = 10 if self.garden else 0 | ||
| self.garden_orientation = "north" if self.garden else None | ||
|
|
||
| def action_sell_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError(self.env._("Cancelled properties cannot be sold")) | ||
| property.state = "sold" | ||
|
|
||
| def action_cancel_property(self): | ||
| for property in self: | ||
| if property.state == "sold": | ||
| raise UserError(self.env._("Sold properties cannot be cancelled")) | ||
| property.state = "cancelled" | ||
|
|
||
| @api.constrains("expected_price", "selling_price") | ||
| def _check_selling_price_limit(self): | ||
| for property in self: | ||
| if not float_is_zero(property.selling_price, precision_digits=5): | ||
| limit = 0.9 * property.expected_price | ||
| if ( | ||
| float_compare(property.selling_price, limit, precision_digits=5) | ||
| == -1 | ||
| ): | ||
| raise ValidationError( | ||
| self.env._( | ||
| "The selling price should not be less than 90% of the expected price of the property", | ||
| ), | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| for state in self.mapped("state"): | ||
| if state not in ["new", "cancelled"]: | ||
| raise UserError( | ||
| self.env._("New or cancelled estates only can be deleted"), | ||
| ) |
This file contains hidden or 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,88 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstateOFfer(models.Model): | ||
| _name = "estate.offer" | ||
| _description = "Offer made to some estate (property)" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float(string="Price") | ||
| status = fields.Selection( | ||
| string="Status", | ||
| selection=[("accepted", "Accepted"), ("refused", "Refused")], | ||
| copy=False, | ||
| ) | ||
| property_id = fields.Many2one( | ||
| string="Property", | ||
| comodel_name="estate.estate", | ||
| required=True, | ||
| ) | ||
| partner_id = fields.Many2one( | ||
| string="Partner", | ||
| comodel_name="res.partner", | ||
| required=True, | ||
| ) | ||
| validity = fields.Integer(string="Validity", default=7) | ||
| date_deadline = fields.Date( | ||
| string="Deadline", | ||
| compute="_compute_deadline", | ||
| inverse="_inverse_deadline", | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| string="Property Type", | ||
| comodel_name="estate.type", | ||
| related="property_id.type_id", | ||
| store=True, | ||
| ) | ||
|
|
||
| _positive_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "Offer price should be strictly positive", | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_deadline(self): | ||
| for offer in self: | ||
| curr_date = offer.create_date if offer.create_date else fields.Date.today() | ||
| offer.date_deadline = curr_date + relativedelta(days=offer.validity) | ||
|
|
||
| def _inverse_deadline(self): | ||
| for offer in self: | ||
| date_diff = offer.date_deadline - (offer.create_date.date()) | ||
| offer.validity = date_diff.days | ||
|
|
||
| def action_accept_offer(self): | ||
| # check if there is no other accepted offers | ||
| if "accepted" in self.property_id.offer_ids.mapped("status"): | ||
| raise UserError( | ||
| self.env._("Only one offer can be accepted for a given property!"), | ||
| ) | ||
|
|
||
| # update status, selling price, buyer | ||
| self.status = "accepted" | ||
| self.property_id.selling_price = self.price | ||
| self.property_id.buyer_id = self.partner_id | ||
|
amgom-odoo marked this conversation as resolved.
|
||
| self.property_id.state = "offer_accepted" | ||
|
|
||
| def action_refuse_offer(self): | ||
| self.status = "refused" | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| # check before saving if the offer price >= existing offer prices | ||
| for record in vals_list: | ||
| property = self.env["estate.estate"].browse(record["property_id"]) | ||
| max_offer_price = max(property.offer_ids.mapped("price"), default=0) | ||
| if record["price"] < max_offer_price: | ||
| raise UserError( | ||
| self.env._( | ||
| "Cannot create an offer with price lower than an existing offer", | ||
| ), | ||
| ) | ||
|
|
||
| # update state and save to the database | ||
| property.state = "offer_received" | ||
| return super().create(vals_list) | ||
This file contains hidden or 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,15 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstateTag(models.Model): | ||
| _name = "estate.tag" | ||
| _description = "A list of tags that categorize the properities" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| color = fields.Integer(string="Color") | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property tag names must be unique!", | ||
| ) |
This file contains hidden or 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,32 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstateType(models.Model): | ||
| _name = "estate.type" | ||
| _description = "The type of the property to be sold such as House, apartment, ..." | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| property_ids = fields.One2many( | ||
| string="Properties", | ||
| comodel_name="estate.estate", | ||
| inverse_name="type_id", | ||
| ) | ||
| sequence = fields.Integer(string="Sequence", default=1) | ||
|
|
||
| offer_ids = fields.One2many( | ||
| string="Property type offers", | ||
| comodel_name="estate.offer", | ||
| inverse_name="property_type_id", | ||
| ) | ||
| offer_count = fields.Integer(string="Offers count", compute="_compute_offers_count") | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property type names must be unique!", | ||
| ) | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offers_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
This file contains hidden or 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,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class Users(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| string="Properities", | ||
| comodel_name="estate.estate", | ||
| inverse_name="salesman_id", | ||
| domain=[("state", "in", ["new", "offer_received"])], | ||
| ) |
|
amgom-odoo marked this conversation as resolved.
|
This file contains hidden or 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_estate,access.estate.estate,model_estate_estate,base.group_user,1,1,1,1 | ||
| access_estate_offer,access.estate.offer,model_estate_offer,base.group_user,1,1,1,1 | ||
| access_estate_type,access.estate.type,model_estate_type,base.group_user,1,1,1,1 | ||
| access_estate_tag,access.estate.tag,model_estate_tag,base.group_user,1,1,1,1 |
This file contains hidden or 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,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <menuitem id="estate_root_menu" name="Real Estate"> | ||
| <menuitem id="estate_property_menu" name="Advertisements" action="estate_property_action"/> | ||
| <menuitem id="estate_property_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_menu" name="Property Types" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tag_menu" name="Property Tags" action="estate_property_tag_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> |
This file contains hidden or 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,38 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <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.offer</field> | ||
| <field name="type">form</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Create Offers"> | ||
| <sheet> | ||
| <group> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <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.offer</field> | ||
| <field name="type">list</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Offers"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or 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 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.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.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Tags" editable="bottom"> | ||
| <field name="name"/> | ||
| </list> | ||
| </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.
Uh oh!
There was an error while loading. Please reload this page.