-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[ADD] estate, estate_account: create Real Estate and Real Estate Account modules for managing real estate business. #1282
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
Open
abdelgad
wants to merge
1
commit into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-add-estate-abgad
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.
Open
Changes from all commits
Commits
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,16 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'application': True, | ||
| 'depends': [ | ||
| 'base', | ||
| ], | ||
| '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_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_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| 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,147 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "It's free real estate" | ||
|
|
||
| # Order attributes | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True,) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| default=lambda self: fields.Date.add(fields.Date.today(), months=3), | ||
| copy=False,) | ||
| 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( | ||
| 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'), | ||
| ('canceled', 'Cancelled'), | ||
| ], | ||
| default='new', | ||
| required=True, | ||
| copy=False, | ||
| ) | ||
|
|
||
| # Reserved fields | ||
| active = fields.Boolean(default=True, string='Active',) | ||
|
|
||
| # Relations | ||
| property_type_id = fields.Many2one("estate.property.type",) | ||
| property_tag_ids = fields.Many2many("estate.property.tag",) | ||
| salesperson_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user,) | ||
| buyer_id = fields.Many2one('res.partner', copy=False,) | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers",) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # COMPUTED FIELDS | ||
| # ------------------------------------------------------------------------- | ||
| total_area = fields.Integer( | ||
| string="Total Area (sqm)", | ||
| compute="_compute_total_area", | ||
| ) | ||
|
|
||
| best_price = fields.Float( | ||
| string="Best Offer", | ||
| compute="_compute_best_price", | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # SQL Constraints | ||
| # ------------------------------------------------------------------------- | ||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'A property expected price must be strictly positive.', | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| 'A property selling price must be positive.', | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # COMPUTE METHODS | ||
| # ------------------------------------------------------------------------- | ||
| @api.depends("living_area", "garden_area",) | ||
| def _compute_total_area(self,): | ||
| for property in self: | ||
| property.total_area = property.living_area + property.garden_area | ||
|
|
||
| @api.depends("offer_ids.price",) | ||
| def _compute_best_price(self,): | ||
| for property in self: | ||
| if property.offer_ids: | ||
| property.best_price = max(property.offer_ids.mapped("price"), default=0.0) | ||
| else: | ||
| property.best_price = 0.0 | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CONSTRAINTs METHODS | ||
| # ------------------------------------------------------------------------- | ||
| @api.constrains('expected_price', 'selling_price',) | ||
| def _check_selling_price(self,): | ||
| for property in self: | ||
| # Selling price = 0 => Do nothing | ||
| if float_is_zero(property.selling_price, precision_digits=2): | ||
| continue | ||
|
|
||
| minimum_price = property.expected_price * 0.90 | ||
|
|
||
| if float_compare(property.selling_price, minimum_price, precision_digits=2) < 0: | ||
| raise UserError(self.env._("The selling price cannot be lower than 90% of the expected price.")) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # ONCHANGE METHODS | ||
| # ------------------------------------------------------------------------- | ||
| @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 = False | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CRUD METHODS | ||
| # ------------------------------------------------------------------------- | ||
| @api.ondelete(at_uninstall=False,) | ||
| def _unlink_except_new_or_canceled(self,): | ||
| for property in self: | ||
| if property.state not in ('new', 'canceled',): | ||
| raise UserError(self.env._("You can only delete properties that are New or Canceled.")) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # ACTIONS | ||
| # ------------------------------------------------------------------------- | ||
| def action_sold(self,): | ||
| for property in self: | ||
| if property.state == 'canceled': | ||
| raise UserError(self.env._("You cannot sell a canceled property.")) | ||
| self.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel(self,): | ||
| for property in self: | ||
| if property.state == 'sold': | ||
| raise UserError(self.env._("You cannot cancel a sold property.")) | ||
| self.state = 'canceled' | ||
| return True | ||
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,98 @@ | ||
| from datetime import timedelta | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Real Estate Property Offer" | ||
|
|
||
| # Order attributes | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| selection=[ | ||
| ('accepted', 'Accepted'), | ||
| ('refused', 'Refused'), | ||
| ], | ||
| copy=False, | ||
| ) | ||
| validity = fields.Integer(default=7,) | ||
| date_deadline = fields.Date( | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", required=True,) | ||
| property_id = fields.Many2one("estate.property", required=True,) | ||
| property_type_id = fields.Many2one( | ||
| "estate.property.type", | ||
| related="property_id.property_type_id", | ||
| string="Property Type", | ||
| store=True, | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CONSTRAINTS | ||
| # ------------------------------------------------------------------------- | ||
| _check_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'An offer price must be strictly positive.', | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity",) | ||
| def _compute_date_deadline(self,): | ||
| for offer in self: | ||
| base_date = (offer.create_date or fields.Datetime.now()).date() | ||
| offer.date_deadline = base_date + timedelta(days=offer.validity,) | ||
|
|
||
| def _inverse_date_deadline(self,): | ||
| for offer in self: | ||
| base_date = (offer.create_date or fields.Datetime.now()).date() | ||
| if offer.date_deadline: | ||
| offer.validity = (offer.date_deadline - base_date).days | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CRUD methods | ||
| # ------------------------------------------------------------------------- | ||
| @api.model_create_multi | ||
| def create(self, vals_list,): | ||
| for vals in vals_list: | ||
| property_record = self.env['estate.property'].browse(vals['property_id']) | ||
|
|
||
| if property_record.offer_ids: | ||
| best_price = max(property_record.offer_ids.mapped('price')) | ||
| if vals.get('price', 0) < best_price: | ||
| raise UserError(self.env._("You cannot create an offer with a price lower than the current best offer.")) | ||
|
|
||
| property_record.state = 'offer_received' | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # ACTIONS | ||
| # ------------------------------------------------------------------------- | ||
| def action_accept(self,): | ||
| for offer in self: | ||
| if offer.property_id.state in ('sold', 'canceled',): | ||
| raise UserError(self.env._("You cannot accept an offer on a sold or canceled property.")) | ||
|
|
||
| if offer.property_id.offer_ids.filtered(lambda o: o.status == "accepted"): | ||
| raise UserError(self.env._("An offer has already been accepted for this property.")) | ||
|
|
||
| offer.status = 'accepted' | ||
| offer.property_id.selling_price = offer.price | ||
| offer.property_id.buyer_id = offer.partner_id | ||
|
|
||
| other_offers = offer.property_id.offer_ids - offer | ||
| other_offers.status = 'refused' | ||
|
|
||
| return True | ||
|
|
||
| def action_refuse(self,): | ||
| for offer in self: | ||
| if offer.property_id.state in ('sold', 'canceled',): | ||
| raise UserError(self.env._("You cannot refuse an offer on a sold or canceled property.")) | ||
|
|
||
| self.status = 'refused' | ||
|
|
||
| return True |
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,19 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Property's tag" | ||
|
|
||
| # Order attributes | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True,) | ||
| color = fields.Integer(string="Color",) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CONSTRAINTS | ||
| # ------------------------------------------------------------------------- | ||
| _unique_tag_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'A property tag name 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,48 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Property's type" | ||
|
|
||
| # Order attributes | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(required=True,) | ||
|
|
||
| sequence = fields.Integer(string="Sequence", default=1, help="Used to order stages. Lower is better.",) | ||
|
|
||
| # Relations | ||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "property_type_id", | ||
| string="Properties", | ||
| ) | ||
|
|
||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", | ||
| "property_type_id", | ||
| string="Offers", | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # COMPUTED FIELDS | ||
| # ------------------------------------------------------------------------- | ||
| offer_count = fields.Integer( | ||
| string="Offers Count", | ||
| compute="_compute_offer_count", | ||
| ) | ||
|
|
||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # CONSTRAINTS | ||
| # ------------------------------------------------------------------------- | ||
| _unique_type_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'A property type name must be unique.', | ||
| ) | ||
|
|
||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_offer_count(self): | ||
| for property_type in self: | ||
| property_type.offer_count = len(property_type.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,11 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| string="Properties", | ||
| domain=[('state', 'in', ['new', 'offer_received'])] | ||
| ) |
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 | ||
| estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,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,12 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_advertisements_menu" name="Advertisements"> | ||
| <menuitem id="estate_model_menu_action" action="estate_property_action" name="Properties"/> | ||
| </menuitem> | ||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_model_menu_action" action="estate_property_type_action" name="Property Types"/> | ||
| <menuitem id="estate_property_tag_model_menu_action" action="estate_property_tag_action" name="Property Tags"/> | ||
| </menuitem> | ||
| </menuitem> | ||
| </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.