-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[ADD] estate{_account}: added estate{_account} moduels - MOALN #1003
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
Mohamed-Khaled308
wants to merge
23
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-onboarding-moaln
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
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0a1b5d4
[ADD] estate: Create the app
Mohamed-Khaled308 7c751ec
[IMP] estate: change the module's author name to my name
Mohamed-Khaled308 ea0ef15
[IMP] estate: added the estate property model
Mohamed-Khaled308 86659eb
[IMP] estate: added access rights
Mohamed-Khaled308 405330c
[IMP] estate: created menus, actions and customized model fields
Mohamed-Khaled308 e7792be
[IMP] estate: added list, menu and search views
Mohamed-Khaled308 37a5c08
[FIX] estate: added the missing name field in the form view
Mohamed-Khaled308 fc50878
[IMP] estate: added Many2one, Many2many and One2many relations
Mohamed-Khaled308 9fd3584
[IMP] estate: added computed fields and onchanges
Mohamed-Khaled308 872c4a7
[FIX] estate: fix style errors
Mohamed-Khaled308 b9d83dd
[IMP] estate: added action buttons
Mohamed-Khaled308 d269a85
[IMP] estate: added sql and python constraints
Mohamed-Khaled308 44e19e2
[CLN] estate: removed unnessary spaces, empty lines and redundant fie…
Mohamed-Khaled308 17c0fe0
[IMP] estate: added the sprinkles
Mohamed-Khaled308 6073b19
[FIX] estate: fix style and dependency errors
Mohamed-Khaled308 44589e3
[IMP] estate: added inheritance
Mohamed-Khaled308 ae88eeb
[FIX] estate: fix style errors
Mohamed-Khaled308 335c155
[CLN] estate: formatted the code with pycharm
Mohamed-Khaled308 4e0128a
[IMP] estate{_account}: added integrartion with account module
Mohamed-Khaled308 bbccccd
[CLN] estate: removed unused imports
Mohamed-Khaled308 5b9a690
[IMP] estate: added kanban view
Mohamed-Khaled308 750a886
[CLN] estate: cleaned the code
Mohamed-Khaled308 e6b35b9
[CLN] estate{_account}: applied suggested review comments
Mohamed-Khaled308 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'description': 'A tutorial module for real estate management', | ||
| 'version': '1.0', | ||
| 'depends': ['base'], | ||
| 'category': 'Real Estate', | ||
| 'summary': 'A basic real estate module', | ||
| '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/res_users_views.xml', | ||
| 'views/estate_menus.xml' | ||
| ], | ||
| 'application': True, | ||
| 'author': 'Odoo Sa', | ||
| 'license': 'LGPL-3', | ||
| } |
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_offer | ||
| from . import estate_property_tag | ||
| from . import estate_property_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,115 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| 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 = "estate property model" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| copy=False, default=fields.Date.today() + relativedelta(months=+3) | ||
| ) | ||
| expected_price = fields.Float(required=True, default=1) | ||
| 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"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| buyer_id = fields.Many2one("res.partner", copy=False) | ||
| salesperson_id = fields.Many2one("res.users", default=lambda self: self.env.user) | ||
| property_tag_ids = fields.Many2many("estate.property.tag", string="Propert Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
| total_area = fields.Float(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
| _check_positive_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "The Expected Price of a Property must be strictly positive", | ||
| ) | ||
| _check_positive_selling_price = models.Constraint( | ||
| "CHECK(selling_price > 0)", | ||
| "The Selling Price of a Property must be strictly positive", | ||
| ) | ||
|
|
||
| @api.constrains("expected_price", "selling_price") | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| percentage = property.selling_price / property.expected_price | ||
| if ( | ||
| not float_is_zero(property.selling_price, precision_digits=2) | ||
| and float_compare(percentage, 0.9, precision_digits=2) == -1 | ||
| ): | ||
| raise UserError( | ||
| "selling price cannot be lower than 90% of the expected price" | ||
| ) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| self.ensure_one() | ||
| for property in self: | ||
| property.total_area = property.living_area + property.garden_area | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_best_price(self): | ||
| self.ensure_one() | ||
| for property in self: | ||
| property.best_price = max(property.offer_ids.mapped("price") or [0]) | ||
|
|
||
| @api.onchange("garden") | ||
| def _onchange_garden(self): | ||
| self.garden_area = 10 if self.garden else 0 | ||
| self.garden_orientation = "north" if self.garden else "" | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled_state(self): | ||
| if any( | ||
| not (property.state == "new" or property.state == "cancelled") | ||
| for property in self | ||
| ): | ||
| raise UserError("You can only delete new or cancelled properties") | ||
|
|
||
| def action_sold(self): | ||
| self.ensure_one() | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError("You cannot sell a cancelled property") | ||
| property.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| self.ensure_one() | ||
| for property in self: | ||
| if property.state == "sold": | ||
| raise UserError("You cannot cancel a sold property") | ||
| property.state = "cancelled" | ||
| 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,78 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "estate property offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| selection=[("accepted", "Accepted"), ("refused", "Refused")], copy=False | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Partner", required=True) | ||
| property_id = fields.Many2one( | ||
| "estate.property", string="Property", required=True, ondelete="cascade" | ||
| ) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date( | ||
| compute="_compute_date_deadline", inverse="_inverse_date_deadline" | ||
| ) | ||
| property_state = fields.Selection(related="property_id.state") | ||
| property_type_id = fields.Many2one( | ||
| related="property_id.property_type_id", store=True | ||
| ) | ||
| _check_positive_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", "The Offer Price must be strictly positive" | ||
| ) | ||
|
|
||
| @api.depends("validity", "create_date") | ||
| def _compute_date_deadline(self): | ||
| self.ensure_one() | ||
| for offer in self: | ||
| offer.date_deadline = ( | ||
| offer.create_date or fields.Date.today() | ||
| ) + relativedelta(days=+offer.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| self.ensure_one() | ||
| for offer in self: | ||
| offer.validity = ( | ||
| offer.date_deadline - (offer.create_date or fields.Date.today()).date() | ||
| ).days | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| EstateProperties = self.env["estate.property"].with_prefetch( | ||
| [vals["property_id"] for vals in vals_list] | ||
| ) | ||
| for offer in vals_list: | ||
| property = EstateProperties.browse(offer["property_id"]) | ||
| property.state = "offer_received" | ||
| if offer["price"] < property.best_price: | ||
| raise UserError(f"The offer must be higher than {property.best_price}") | ||
| return super().create(vals_list) | ||
|
|
||
| def action_accept_offer(self): | ||
| self.ensure_one() | ||
| for offer in self: | ||
| if offer.status == "refused": | ||
| raise UserError("You cannot accept a refused offer") | ||
| if offer.property_id.buyer_id: | ||
| raise UserError("Only one offer can be accepted") | ||
| offer.property_id.buyer_id = offer.partner_id | ||
| offer.property_id.selling_price = offer.price | ||
| offer.property_id.state = "offer_accepted" | ||
| offer.status = "accepted" | ||
| return True | ||
|
|
||
| def action_refuse_offer(self): | ||
| self.ensure_one() | ||
| for offer in self: | ||
| if offer.status == "accepted": | ||
| raise UserError("You cannot refuse an accepted offer") | ||
| offer.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,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "estate property tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
| _check_unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "The 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,26 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "estate property type" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer(default=1) | ||
| estate_property_ids = fields.One2many( | ||
| "estate.property", "property_type_id", string="Properties" | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", "property_type_id", string="Offers" | ||
| ) | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
| _check_unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "The name must be unique", | ||
| ) | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_count(self): | ||
| for type in self: | ||
| type.offer_count = len(type.offer_ids or []) | ||
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 ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
| _description = "user with properties model" | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| string="Estate 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 | ||
| 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 |
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,40 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem | ||
| id="estate_property_menu_root" | ||
| name="Real Estate" | ||
| /> | ||
| <menuitem | ||
| id="estate_property_menu_advertisements" | ||
| name="Advertisements" | ||
| parent="estate_property_menu_root" | ||
| sequence="1" | ||
| /> | ||
| <menuitem | ||
| id="estate_property_menu_properties" | ||
| name="Properties" | ||
| parent="estate_property_menu_advertisements" | ||
| action="estate_property_action" | ||
| sequence="1" | ||
| /> | ||
| <menuitem | ||
| id="estate_property_menu_settings" | ||
| name="Settings" | ||
| parent="estate_property_menu_root" | ||
| sequence="2" | ||
| /> | ||
| <menuitem | ||
| id="estate_property_menu_property_type" | ||
| name="Property Types" | ||
| parent="estate_property_menu_settings" | ||
| action="estate_property_type_action" | ||
| sequence="1" | ||
| /> | ||
| <menuitem | ||
| id="estate_property_menu_property_tag" | ||
| name="Property Tags" | ||
| parent="estate_property_menu_settings" | ||
| action="estate_property_tag_action" | ||
| sequence="2" | ||
| /> | ||
| </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.
[] shouldn't be necessary as offer_ids will always be a list even if there is no records.