-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: create the Estate Module #1097
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
abbhi-Odoo
wants to merge
12
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-estate-tutorial-abbhi
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
12 commits
Select commit
Hold shift + click to select a range
ac7ad92
[ADD] estate: created estate Property model and manifest file
abbhi-Odoo 04be844
[FIX] estate: fix model and ruff style issues
abbhi-Odoo 95af12b
[FIX] estate: fix model and ruff style issues
abbhi-Odoo 2111cd7
[ADD] estate: add actions, menus and default UI configuration
abbhi-Odoo 4934255
[ADD] estate: complete filters,group by with properties relations
abbhi-Odoo e50a962
[IMP] estate: complete relations between models
abbhi-Odoo 16bb220
[IMP] estate: add computed fields and onchange logic
abbhi-Odoo c427696
[IMP] estate: add property offer workflow
abbhi-Odoo 52a77f4
[IMP] estate: add SQL and Python constraints
abbhi-Odoo 2b76c19
[IMP] estate: improve property type views and offer button behavior
abbhi-Odoo df0dec6
[IMP] estate: enhance UI with views, widgets, and actions
abbhi-Odoo 8cc8cb0
[IMP] estate: implement model and view inheritance
abbhi-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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ pip-delete-this-directory.txt | |
| htmlcov/ | ||
| .tox/ | ||
| .nox/ | ||
| .idea/ | ||
| .coverage | ||
| .coverage.* | ||
| .cache | ||
|
|
||
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,18 @@ | ||
| { | ||
| 'name': 'Estate', | ||
| 'version': '1.0', | ||
| 'author': 'Abhi Bhingradiya(abbhi)', | ||
| 'description': 'Real state app', | ||
| 'license': 'LGPL-3', | ||
| 'application': True, | ||
| 'depends': ['base'], | ||
| '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' | ||
| ] | ||
| } |
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,143 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError, RedirectWarning | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real state Property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Integer() | ||
| date_availability = fields.Date( | ||
| default=lambda self: fields.Date.today() + relativedelta(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(string="Garden Area(sqm)") | ||
| garden_orientation = fields.Selection( | ||
| string="Garden Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.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", | ||
| string="Buyer", | ||
| copy=False, | ||
| ) | ||
| seller_id = fields.Many2one( | ||
| "res.users", | ||
| string="Seller", | ||
| default=lambda self: self.env.user | ||
| ) | ||
| tag_ids = fields.Many2many( | ||
| "estate.property.tag", | ||
| string="Tags" | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", | ||
| "property_id", | ||
| string="Offers", | ||
| ) | ||
| total_area = fields.Integer(compute="_compute_total_area", store=True) | ||
| best_price = fields.Float(compute="_compute_best_price", store=True) | ||
| offer_counts = fields.Integer(compute="_compute_offer_counts", store=True) | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'Expected price must be positive!', | ||
| ) | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if float_is_zero(record.selling_price, precision_digits=2): | ||
| continue | ||
| min_selling_price = record.expected_price * 0.9 | ||
| if float_compare(record.selling_price, min_selling_price, precision_digits=2) < 0: | ||
| raise ValidationError("The selling price must be at least 90% of the expected price.") | ||
|
|
||
| @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_price(self): | ||
| for record in self: | ||
| record.best_price = 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 = False | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_counts(self): | ||
| for record in self: | ||
| record.offer_counts = len(record.offer_ids) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_delete_property(self): | ||
| for record in self: | ||
| if record.state in ('offer_received', 'offer_accepted', 'sold'): | ||
| raise UserError('you can not delete a property!') | ||
|
|
||
| def action_cancelled(self): | ||
| for record in self: | ||
| sold_properties = record.filtered(lambda r: r.state == "sold") | ||
| if sold_properties: | ||
| raise RedirectWarning("A sold property cannot be cancelled", | ||
| self.env.ref('estate.estate_property_offer_action').id, | ||
| "go to offer page!") | ||
| record.state = "cancelled" | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| cancel_properties = record.filtered(lambda r: r.state == "cancelled") | ||
| if cancel_properties: | ||
| raise UserError("A cancelled property cannot be sold") | ||
| accepted_offer = record.offer_ids.filtered(lambda offer: offer.status == "accepted") | ||
| if not accepted_offer: | ||
| raise UserError("Property can not be sold without an accepted offer") | ||
| record.state = "sold" | ||
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,93 @@ | ||
| 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(string="Price") | ||
| status = fields.Selection([ | ||
| ("accepted", "Accepted"), | ||
| ("rejected", "Rejected"), | ||
| ], copy=False, readonly=True) | ||
| partner_id = fields.Many2one("res.partner", 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_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| store=True | ||
| ) | ||
| property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) | ||
|
|
||
| _check_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'Offer price must be positive', | ||
| ) | ||
|
|
||
| @api.model | ||
| def create(self, vals): | ||
| for val in vals: | ||
| property_id = val.get('property_id') | ||
| price = val.get('price') | ||
| if property_id and price: | ||
| property_rec = self.env['estate.property'].browse(property_id) | ||
| if property_rec.offer_ids: | ||
| if price < property_rec.best_price: | ||
| raise UserError( | ||
| "The offer must be higher than existing offers." | ||
| ) | ||
| offer = super().create(vals) | ||
| if offer.property_id and offer.property_id.state == 'new': | ||
| offer.property_id.state = 'offer_received' | ||
| return offer | ||
|
|
||
| @api.depends("validity", "create_date") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| record.date_deadline = record.create_date.date() + relativedelta(days=record.validity) | ||
| else: | ||
| record.date_deadline = fields.Date.today() + relativedelta(days=record.validity) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_delete_offer(self): | ||
| for record in self: | ||
| if record.status == "accepted": | ||
| raise UserError("You can not delete a property with accepted offer") | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date and record.date_deadline: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_accepted(self): | ||
| for record in self: | ||
| if record.property_id.selling_price or record.status == "accepted": | ||
| raise UserError("Offer is already accepted") | ||
| record.status = "accepted" | ||
| rejected_offers = record.property_id.offer_ids.filtered( | ||
| lambda offer: offer.id != record.id | ||
| ) | ||
| for ro in rejected_offers: | ||
| ro.status = "rejected" | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = "offer_accepted" | ||
|
|
||
| def action_rejected(self): | ||
| if self.status == "accepted": | ||
| self.property_id.selling_price = False | ||
| self.status = "rejected" |
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 EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| _order = "name asc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
|
|
||
| _check_name_unique = models.Constraint( | ||
| 'unique(name)', | ||
| 'The Property Tag 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,23 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class PropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer() | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
| offer_count = fields.Integer(compute='_compute_offer_count') | ||
|
|
||
| _check_name_unique = models.Constraint( | ||
| 'unique(name)', | ||
| 'The Property type must be unique.', | ||
| ) | ||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_offer_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 models, fields | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many( | ||
| 'estate.property', | ||
| 'seller_id', | ||
| string="Owned Properties", | ||
| domain=['|', ('state', '=', 'new'), ('state', '=', '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,35 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" | ||
| name="Real Estate"/> | ||
|
|
||
| <menuitem id="estate_menu_advertisements" | ||
| name="Advertisements" | ||
| parent="estate_menu_root" | ||
| sequence="15"/> | ||
|
|
||
| <menuitem id="estate_menu_advertisements_properties" | ||
| name="Properties" | ||
| parent="estate_menu_advertisements" | ||
| action="estate_property_action"/> | ||
|
|
||
| <menuitem id="estate_menu_settings" | ||
| name="Settings" | ||
| parent="estate_menu_root" | ||
| sequence="16"/> | ||
|
|
||
| <menuitem id="estate_menu_settings_property_type" | ||
| name="Property Types" | ||
| parent="estate_menu_settings" | ||
| action="estate_property_type_action"/> | ||
|
|
||
| <menuitem id="estate_menu_settings_property_tag" | ||
| name="Property Tags" | ||
| parent="estate_menu_settings" | ||
| action="estate_property_tag_action"/> | ||
|
|
||
| <menuitem id="estate_menu_settings_property_offer" | ||
| name="Property Offers" | ||
| parent="estate_menu_settings" | ||
| action="estate_property_offer_action"/> | ||
| </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,29 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_action_by_type" model="ir.actions.act_window"> | ||
| <field name="name">Property 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> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_list_view" 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 string="offers" editable="bottom" decoration-danger="status in ('rejected')" | ||
| decoration-success="status in ('accepted')"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| </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.