-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: real estate module (web server framework 101) #1073
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
magai2002
wants to merge
1
commit into
odoo:master
Choose a base branch
from
odoo-dev:master-onboarding-almag
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
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,24 @@ | ||
| { | ||
| 'name': "Estate", | ||
| 'summary': """ | ||
| App module created specifically for the Server Framework 101 tutorial. | ||
| """, | ||
| 'description': """ | ||
| App module created specifically for the Server Framework 101 tutorial. | ||
| """, | ||
| 'author': "Odoo ALMAG", | ||
| 'website': "https://www.odoo.com", | ||
| 'category': 'Tutorials', | ||
| 'depends': ['base', 'web'], | ||
| 'application': True, | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/res_users_views.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| '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_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,112 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
| from datetime import date | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class EstatePropertyModel(models.Model): | ||
| _name = 'estate.property' | ||
| _description = "Real Estate property database" | ||
| _order = 'id desc' | ||
| _expected_price_check = models.Constraint('CHECK(expected_price > 0)', "The expected price must be strictly positive.") | ||
| _selling_price_check = models.Constraint('CHECK(selling_price >= 0)', "The selling price must be positive.") | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date(copy=False, default=lambda self: date.today() + relativedelta(months=3)) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| bedrooms = fields.Integer(default=2) | ||
| active = fields.Boolean(default=True) | ||
| living_area = fields.Integer() | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ('north', "North"), | ||
| ('east', "East"), | ||
| ('south', "South"), | ||
| ('west', "West"), | ||
| ], | ||
| string="Garden Orientation", | ||
| default='south', | ||
| ) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ('new', "New"), | ||
| ('offer_received', "Offer Received"), | ||
| ('offer_accepted', "Offer Accepted"), | ||
| ('sold', "Sold"), | ||
| ('cancel', "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) | ||
| salesperson_id = fields.Many2one( | ||
| 'res.users', | ||
| string="Salesperson", | ||
| 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', string="Total Area (sqm)") | ||
| best_price = fields.Float(compute='_compute_best_price', string="Best Offer") | ||
|
|
||
| @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: | ||
| prices = record.offer_ids.mapped('price') | ||
| if prices: | ||
| record.best_price = max(prices) | ||
| else: | ||
| record.best_price = 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.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if not float_is_zero(record.selling_price, precision_digits=2): | ||
| if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1: | ||
| raise ValidationError(self.env._("The selling price cannot be lower than 90% of the expected price!")) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _ondelete_property(self): | ||
| for record in self: | ||
| if record.state not in ['new', 'cancel']: | ||
| raise UserError(self.env._("Only new or cancelled properties can be deleted!")) | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == "cancel": | ||
| raise UserError(self.env._("Canceled properties cannot be sold.")) | ||
| record.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == "sold": | ||
| raise UserError(self.env._("Sold properties cannot be canceled.")) | ||
| record.state = "cancel" | ||
| 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,59 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = "Property Offer" | ||
| _order = 'price desc' | ||
| _price_check = models.Constraint('CHECK(price > 0)', "The offer price must be strictly positive.") | ||
|
|
||
| price = fields.Float() | ||
| partner_id = fields.Many2one('res.partner', string="Partner", required=True) | ||
| property_id = fields.Many2one('estate.property', string="Property", required=True) | ||
| property_type_id = fields.Many2one(related='property_id.property_type_id', string="Property Type", store=True) | ||
| validity = fields.Integer(string="Validity (days)", default=7) | ||
| date_deadline = fields.Date(string="Deadline", compute='_compute_date_deadline', inverse='_inverse_date_deadline') | ||
| status = fields.Selection( | ||
| selection=[('accepted', "Accepted"), ('refused', "Refused")], | ||
| copy=False | ||
| ) | ||
|
|
||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| start_date = record.create_date if record.create_date else fields.Date.today() | ||
| record.date_deadline = fields.Date.add(start_date, days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| property_ids = [vals['property_id'] for vals in vals_list if vals.get('property_id')] | ||
| properties = self.env['estate.property'].browse(property_ids) | ||
| property_map = {prop.id: prop for prop in properties} | ||
|
|
||
| for vals in vals_list: | ||
| prop = property_map.get(vals.get('property_id')) | ||
| if prop: | ||
| if prop.offer_ids: | ||
| max_offer = max(prop.offer_ids.mapped('price'), default=0) | ||
| if vals.get('price', 0) < max_offer: | ||
| raise UserError(self.env._("The offer must be higher than existing offers!")) | ||
| prop.state = 'offer_received' | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| record.status = 'accepted' | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| record.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,11 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = "Property Tag" | ||
| _order = 'name' | ||
| _name_check = models.Constraint('UNIQUE(name)', "The name must be unique.") | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() |
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 api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTypeModel(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = "Real Estate property types database" | ||
| _order = 'sequence, name' | ||
| _name_check = models.Constraint('UNIQUE(name)', "The name must be unique.") | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") | ||
| 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') | ||
|
|
||
| @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 fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| string="Real Estate 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 | ||
| 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 | ||
| 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,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <data> | ||
| <menuitem id="estate_menu_root" name="Real Estate"/> | ||
| <menuitem id="estate_first_level_menu" name="Advertisements" parent="estate_menu_root"/> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action" parent="estate_first_level_menu"/> | ||
| <menuitem id="estate_menu_config" name="Settings" parent="estate_menu_root"/> | ||
| <menuitem id="estate_property_type_menu_action" action="estate_property_type_action" parent="estate_menu_config"/> | ||
| <menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action" parent="estate_menu_config"/> | ||
| </data> | ||
| </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,27 @@ | ||
| <?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> | ||
| <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="Offers" editable="bottom" | ||
| decoration-success="status == 'accepted'" | ||
| decoration-danger="status == 'refused'"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept" type="object" icon="fa-check" title="Accept"/> | ||
| <button name="action_refuse" type="object" icon="fa-times" title="Refuse"/> | ||
| <field name="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,25 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <record id="estate_property_tag_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.view.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Tag"> | ||
| <sheet> | ||
| <div class="oe_title"> | ||
| <h1 class="mb32"> | ||
| <field name="name" class="mb16" /> | ||
| </h1> | ||
| </div> | ||
| <field name="color" /> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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> | ||
| </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,55 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <record id="estate_property_type_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Types</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.form</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Type"> | ||
| <sheet> | ||
| <div class="oe_button_box" name="button_box"> | ||
| <button name="%(estate.estate_property_offer_action)d" | ||
| type="action" | ||
| class="oe_stat_button" | ||
| icon="oi-view-list" | ||
| context="{'search_default_property_type_id': id}" | ||
| invisible="offer_count == 0"> | ||
| <div class="o_stat_info"> | ||
| <field name="offer_count" class="o_stat_value"/> | ||
| <span class="o_stat_text">Offers</span> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| <h1><field name="name"/></h1> | ||
| <notebook> | ||
| <page string="Properties"> | ||
| <field name="property_ids" readonly="True"> | ||
| <list> | ||
| <field name="name"/> | ||
| <field name="expected_price"/> | ||
| <field name="state"/> | ||
| </list> | ||
| </field> | ||
| </page> | ||
| </notebook> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.view.list</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <list> | ||
| <field name="sequence" widget="handle" /> | ||
| <field name="name" /> | ||
| </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.
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.
Try to name your parameters whenever it is possible so it is easier to read 😄