-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19.0 real estate tutorial jakan #1109
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
jakan-odoo
wants to merge
18
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-real-estate-tutorial-jakan
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
18 commits
Select commit
Hold shift + click to select a range
71296e3
[ADD] estate: initialize module structure and model
jakan-odoo 3665d34
[ADD] estate: add security rules and fix style
jakan-odoo d8791e0
[ADD] estate: add basic user interface
jakan-odoo 378ed7c
[IMP] estate: create basic views and search
jakan-odoo f155702
[IMP] estate: add many2one model relation
jakan-odoo 1c69bbe
[IMP] estate: add one2many and many2many relations
jakan-odoo 9131c01
[IMP] estate: add computed fields and onchanges
jakan-odoo 2784e60
[IMP] estate: implement object-based actions
jakan-odoo 8c66cd9
[IMP] estate: add sql and python constraints
jakan-odoo dbb059f
[IMP] estate: add inline views, widgets, and order
jakan-odoo aee8aeb
[IMP] estate: add property maintenance requests
jakan-odoo 6dd7eec
[FIX] estate: improve maintenance cost validation
jakan-odoo ac29768
[IMP] estate: enhance views with UI improvements
jakan-odoo 54f03a6
[IMP] estate: apply python, model, and view inheritance
jakan-odoo cc37406
[ADD] estate: add translations, constraints, and UI updates
jakan-odoo 50ec57f
[IMP] estate_account: integrate estate with accounting
jakan-odoo 616598d
[IMP] estate: add investor profile and compute unsold value
jakan-odoo 5e71759
[IMP] estate: add kanban view and default grouping
jakan-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 |
|---|---|---|
|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| i18n | ||
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,23 @@ | ||
| { | ||
| 'name': "Real Estate", | ||
| 'version': "1.0", | ||
| 'category': "Real Estate", | ||
| 'summary': "Manage real estate properties", | ||
| 'description': "This module allows managing properties", | ||
| 'depends': ['base'], | ||
| 'author': "jakan", | ||
| 'license': "LGPL-3", | ||
| 'application': True, | ||
| 'installable': True, | ||
| '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/estate_property_maintenance_views.xml", | ||
| "views/estate_property_investor_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,7 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_property_maintenance | ||
| from . import estate_property_investor | ||
| 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,135 @@ | ||
| 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 | ||
| from odoo import _ | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Real Estate Property' | ||
| _order = 'id desc' | ||
|
|
||
| # Each field becomes a column in PostgreSQL table | ||
| name = fields.Char(required=True, default="Unknown") | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| 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() | ||
| garden_orientation = fields.Selection( | ||
| string="Direction", | ||
| 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="Property Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Property Offers") | ||
| total_area = fields.Float(string="Total Area", compute="_compute_total_area", store=True) | ||
| best_price = fields.Float(string="Best Offer", compute="_compute_best_price") | ||
| maintenance_ids = fields.One2many("estate.property.maintenance", "property_id") | ||
| total_cost = fields.Float(string="Total Cost", compute="_compute_total_cost") | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'Expected price must be strictly positive.', | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price > 0)', | ||
| 'Selling price must be positive.', | ||
| ) | ||
|
|
||
| @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')) | ||
| else: | ||
| property.best_price = 0 | ||
|
|
||
| @api.depends('maintenance_ids.cost') | ||
| def _compute_total_cost(self): | ||
| for maintenance in self: | ||
| maintenance.total_cost = sum(maintenance.maintenance_ids.mapped('cost')) | ||
|
|
||
| @api.constrains('expected_price', 'selling_price') | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| if float_is_zero(property.selling_price, precision_digits=2): | ||
| continue | ||
|
|
||
| minimum_price = property.expected_price * 0.9 | ||
|
|
||
| if float_compare(property.selling_price, minimum_price, precision_digits=2) < 0: | ||
| raise ValidationError("Selling price cannot be lower than 90% of the expected price.") | ||
|
|
||
| @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.ondelete(at_uninstall=False) | ||
| def _check_property_deletion(self): | ||
| for property in self: | ||
| if property.state not in ('new', 'cancelled'): | ||
| raise UserError("You can only delete properties in New or Cancelled state") | ||
|
|
||
| def action_sold(self): | ||
| for property in self: | ||
| if property.state == 'cancelled': | ||
| raise UserError(_("Sold property cannot be cancelled")) | ||
| if not property.buyer_id: | ||
| raise UserError(_("Without accept any offer we can't sold it")) | ||
| if property.maintenance_ids: | ||
| for maintenance in property.maintenance_ids: | ||
| if maintenance.status in ('new', 'cancle'): | ||
| raise UserError(_("Maintenance cost must be Approved or Done")) | ||
| property.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for property in self: | ||
| if property.state == 'sold': | ||
| raise UserError("Cancelled property cannot be sold") | ||
| 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,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyInvestor(models.Model): | ||
| _name = 'estate.property.investor' | ||
| _description = 'Property Investor' | ||
| _inherits = {'res.partner': 'partner_id'} | ||
|
|
||
| partner_id = fields.Many2one('res.partner', required=True, ondelete='cascade') |
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,36 @@ | ||
| from odoo import fields, models | ||
| from odoo.exceptions import UserError | ||
| from odoo.tools.float_utils import float_is_zero | ||
|
|
||
|
|
||
| class EstatePropertyMaintenance(models.Model): | ||
| _name = 'estate.property.maintenance' | ||
| _description = 'Estate Property maintenance' | ||
|
|
||
| title = fields.Char(required=True) | ||
| cost = fields.Float(string="Cost") | ||
| status = fields.Selection( | ||
| [ | ||
| ('new', "New"), | ||
| ('approved', "Approved"), | ||
| ('done', "Done"), | ||
| ('cancle', "Cancle") | ||
| ], | ||
| required=True, | ||
| default="new", | ||
| ) | ||
|
|
||
| property_id = fields.Many2one('estate.property', required=True) | ||
|
|
||
| def maintenance_accept(self): | ||
| for maintenance in self: | ||
| if float_is_zero(maintenance.cost, precision_digits=2): | ||
| raise UserError("Maintenance cost must be greater than zero") | ||
|
|
||
| maintenance.status = "approved" | ||
| return True | ||
|
|
||
| def maintenance_refuse(self): | ||
| for maintenance in self: | ||
| maintenance.status = "cancle" | ||
| 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,99 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| 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'), | ||
| ('refused', 'Refused'), | ||
| ], | ||
| string="Status", | ||
| copy=False | ||
| ) | ||
| partner_id = fields.Many2one('res.partner', string="Partner", required=True) | ||
| property_id = fields.Many2one('estate.property', string="Property", required=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date( | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| store=True | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id", store=True, readonly=True) | ||
|
|
||
| _check_offer_price_positive = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'Offer price must be positive.', | ||
| ) | ||
|
|
||
| @api.depends("validity", "create_date") | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| if offer.create_date: | ||
| offer.date_deadline = ( | ||
| offer.create_date.date() | ||
| + relativedelta(days=offer.validity) | ||
| ) | ||
| else: | ||
| offer.date_deadline = fields.Date.today() + relativedelta(days=offer.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for offer in self: | ||
| if offer.create_date and offer.date_deadline: | ||
| offer.validity = ( | ||
| offer.date_deadline | ||
| - offer.create_date.date() | ||
| ).days | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| property_id = vals.get("property_id") | ||
| price = vals.get("price") | ||
| property_rec = self.env["estate.property"].browse(property_id) | ||
|
|
||
| # Prevent lower offer | ||
| existing_prices = property_rec.offer_ids.mapped("price") | ||
| if existing_prices and price < max(existing_prices): | ||
| raise UserError("You cannot create an offer lower than an existing offer") | ||
|
|
||
| # Set property state | ||
| property_rec.state = "offer_received" | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| @api.constrains('property_id') | ||
| def _check_property_state(self): | ||
| for offer in self: | ||
| if offer.property_id.state in ('sold', 'cancelled'): | ||
| raise ValidationError("You cannot add an offer on a Sold or Cancelled property") | ||
|
|
||
| def action_accept(self): | ||
| for offer in self: | ||
| property_rec = offer.property_id | ||
|
|
||
| if property_rec.buyer_id: | ||
| raise UserError("Property already accepted") | ||
|
|
||
| other_offer = property_rec.offer_ids - offer | ||
| other_offer.write({'status': 'refused'}) | ||
|
|
||
| offer.status = "accepted" | ||
| property_rec.write({ | ||
| 'buyer_id': offer.partner_id.id, | ||
| 'selling_price': offer.price, | ||
| 'active': False, | ||
| }) | ||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| for offer in self: | ||
| 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,15 @@ | ||
| 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() | ||
|
|
||
| _unique_property_tag_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| '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,23 @@ | ||
| from odoo import fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Estate Property Type' | ||
| _order = 'sequence, name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer(default=1) | ||
| property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id") | ||
| offer_count = fields.Integer(string="Offers", compute="_compute_offer_count") | ||
|
|
||
| _unique_property_type_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'Property type name 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,21 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| 'estate.property', | ||
| 'seller_id', | ||
| ) | ||
| total_expected = fields.Float(compute="_compute_total_expected") | ||
|
|
||
| @api.depends('property_ids.expected_price', 'property_ids.state') | ||
| def _compute_total_expected(self): | ||
| sum_expected = dict(self.env['estate.property']._read_group( | ||
| domain=[('state', '!=', 'sold'), ('seller_id', 'in', self.ids)], | ||
| aggregates=['expected_price:sum'], | ||
| groupby=['seller_id'] | ||
| )) | ||
| for record in self: | ||
| record.total_expected = sum_expected.get(record, 0.0) |
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,7 @@ | ||
| 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 | ||
| access_estate_property_maintenance,access_estate_property_maintenance,model_estate_property_maintenance,base.group_user,1,1,1,1 | ||
| access_estate_property_investor,access_estate_property_investor,model_estate_property_investor,base.group_user,1,1,1,1 |
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.