-
Notifications
You must be signed in to change notification settings - Fork 2.8k
real estate module (ibmah) #1069
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
ibmah-odoo
wants to merge
14
commits into
odoo:master
Choose a base branch
from
odoo-dev:master-real-estate-ibmah
base: master
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
14 commits
Select commit
Hold shift + click to select a range
9f7d1ac
[ADD] estate: introduce structure for estate module
ibmah-odoo d5962a2
[IMP] estate: Add estate_property model
ibmah-odoo f2a9463
[IMP] estate: Add access right rules to estate module data
ibmah-odoo 709dd42
[IMP] estate: Implemet menus and new model customizations
ibmah-odoo 43dc52a
[IMP] estate: Add list, form, search views to real estate module
ibmah-odoo a2ae3a1
[IMP] estate: Add relations between real estate property models
ibmah-odoo bb41efb
[IMP] estate: introduce computed fields and use onchange effects for …
ibmah-odoo 97cb701
[IMP] estate: implement actions on properties and offers
ibmah-odoo 06fbf3b
[IMP] estate: add constraints on property and offer prices as well as…
ibmah-odoo 647d085
[IMP] estate: implement inline views, widgets and list ordering of mo…
ibmah-odoo 8970aba
[IMP] estate: inherit models and views from res.users
ibmah-odoo edcacf4
[IMP] estate: link real estate module with accounting to auto generat…
ibmah-odoo af7b03b
[IMP] estate: implement kanban view
ibmah-odoo 84b226d
[CLN] estate: address warnings from missing licenses and model names
ibmah-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 |
|---|---|---|
| @@ -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,22 @@ | ||
| { | ||
| "name": "estate", | ||
| "version": "1.0", | ||
| "depends": ["base"], | ||
| "author": "Odoo S.A.", | ||
| "category": "Real Estate", | ||
| "description": """ | ||
| Description text | ||
| """, | ||
| "application": True, | ||
| "installable": True, | ||
| "data": [ | ||
| "data/ir.model.access.csv", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_offer.xml", | ||
| "views/estate_property_type.xml", | ||
| "views/estate_property_tag.xml", | ||
| "views/estate_menus.xml", | ||
| "views/res_users.xml", | ||
| ], | ||
| 'license': 'AGPL-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 @@ | ||
| 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,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,125 @@ | ||
| from datetime import datetime | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import api, exceptions, fields, models, tools | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Estate Property data model" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| active = fields.Boolean(default=True) | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| copy=False, default=datetime.now() + relativedelta(month=3) | ||
| ) | ||
| 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( | ||
| [ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| help="Indicates the direction the garden is facing with respect to the house", | ||
| ) | ||
| state = fields.Selection( | ||
| [ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| help="State of the proprty listing lifecycle", | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer") | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", string="Salesman", 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") | ||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "The expected price for a property has to be positive", | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price > 0)", | ||
| "The selling price for a property has to be positive", | ||
| ) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.depends("offer_ids.price") | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| record.best_price = ( | ||
| max(record.offer_ids.mapped("price")) if record.offer_ids else 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 None | ||
|
|
||
| def sold_estate_property(self): | ||
| for record in self: | ||
| if record.state != "cancelled": | ||
| record.state = "sold" | ||
| else: | ||
| raise exceptions.UserError("can't sell a cancelled property") | ||
|
|
||
| def cancel_estate_property(self): | ||
| for record in self: | ||
| if record.state != "sold": | ||
| record.state = "cancelled" | ||
| else: | ||
| raise exceptions.UserError("can't cancel a sold property") | ||
amah-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def reject_other_offers(self, winning_offer): | ||
| for record in self: | ||
| for offer in record.offer_ids: | ||
| if offer != winning_offer: | ||
| offer.status = "refused" | ||
|
|
||
| @api.constrains("selling_price") | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if ( | ||
| record.selling_price | ||
| and tools.float_compare( | ||
| record.selling_price, (90 / 100) * record.expected_price, 2 | ||
| ) | ||
| == -1 | ||
| ): | ||
| raise exceptions.ValidationError( | ||
| "The selling price cannot be lower than 90% of the expected price" | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_cancelled(self): | ||
| if any(record.state not in ('new', 'cancelled') for record in self): | ||
| raise exceptions.UserError("Can't delete a property unless it's new or cancelled") | ||
|
|
||
| def lowball_offer(self, offer_price): | ||
| return any(offer_price < offer.price for offer in self.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,62 @@ | ||
| import datetime | ||
|
|
||
| from odoo import api, exceptions, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Real estate property offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| [("accepted", "Accepted"), ("refused", "Refused")], copy=False | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", required=True, string="Sales") | ||
| property_id = fields.Many2one("estate.property", required=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date( | ||
| compute="_compute_date_deadline", inverse="_inverse_date_deadline" | ||
| ) | ||
| property_type_id = fields.Integer( | ||
| related="property_id.property_type_id.id", store=True, string="Property Type id" | ||
| ) | ||
|
|
||
| _check_price = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "The offer price for a property has to be positive", | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = ( | ||
| record.create_date.date() | ||
| if record.create_date | ||
| else datetime.date.today() | ||
| ) + datetime.timedelta(days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_confirm(self): | ||
| for record in self: | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.state = "offer_accepted" | ||
| record.property_id.reject_other_offers(record) | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| prop = self.env['estate.property'].browse(vals['property_id']) | ||
| if prop.lowball_offer(vals['price']): | ||
| raise exceptions.UserError("Offer price can't be lower than lowest offer") | ||
| prop.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,19 @@ | ||
| from random import randint | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Real estate property tags" | ||
| _order = "name asc" | ||
|
|
||
| def _default_color(self): | ||
| return randint(1, 11) | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer(default=lambda self: self._default_color()) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "Unique(name)", "The property tag must have a unique name" | ||
| ) |
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,24 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Real Estate property type" | ||
| _order = "sequence asc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| sequence = fields.Integer( | ||
| "Sequence", default=1, help="Used to order property types, lower is better" | ||
| ) | ||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id") | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
|
||
| _unique_name = models.Constraint( | ||
| "Unique(name)", "The property type must have a unique name" | ||
| ) | ||
|
|
||
| @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,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _name = 'res.users' | ||
| _inherit = ["res.users"] | ||
|
|
||
| property_ids = fields.One2many("estate.property", "salesperson_id", domain=lambda self: [('salesperson_id', '=', self.id)]) |
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 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_property_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_property_first_level_menu" name="Advertisements"> | ||
| <menuitem id="estate_property_model_menu_action" action="estate_property_action" /> | ||
| </menuitem> | ||
| <menuitem id="estate_property_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> |
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">estate property offer action</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_view_list" 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="Properties" editable="bottom" decoration-danger="status == 'refused'" | ||
| decoration-success="status == 'accepted'"> | ||
| <field name="price" string="Price" /> | ||
| <field name="partner_id" string="Partner" /> | ||
| <field name="validity" string="Validity (days)" /> | ||
| <field name="date_deadline" string="Deadline" /> | ||
| <field name="property_type_id" string="property type" /> | ||
| <button name="action_confirm" title="Accept" type="object" icon="fa-check" | ||
| invisible="status" /> | ||
| <button name="action_cancel" title="Refuse" type="object" icon="fa-times" | ||
| invisible="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,30 @@ | ||
| <?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.property.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.list</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Tags" editable="bottom"> | ||
| <field name="name" string="Type" /> | ||
| <field name="color" widget="color_picker" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <field name="name" /> | ||
| <field name="color" widget="color_picker" /> | ||
| </form> | ||
| </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.