-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: Create the Estate Module #1047
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
shsak-odoo
wants to merge
11
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-estate-tutorial-shsak
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
11 commits
Select commit
Hold shift + click to select a range
b97bbe1
[ADD] estate: added init file and manifest file to make it a module
shsak-odoo 3c98f61
[IMP] estate: Create estate property model with more field set
shsak-odoo 9a90538
[IMP] estate: Grant base users full access to estate property by sec…
shsak-odoo 5a8d5d3
[IMP] estate: Added menus, actions, and views for the UI
shsak-odoo b31e223
[IMP] estate: Added form, search, filters, groups views
shsak-odoo 502ebb0
[IMP] estate: Implement relations between modules
shsak-odoo 859c071
[IMP] estate: Add compute fields and onchanges for offer and garden
shsak-odoo d46ed71
[IMP] estate: Added Action button in Property and Offer Model
shsak-odoo 3caeedd
[IMP] estate: Apply constrain to form fields
shsak-odoo d7f849d
[IMP] estate: Adds inline views, widget, decorations, Stat button
shsak-odoo 7d95cad
[IMP] estate: Modify the res.user to add property_ids by inheritance
shsak-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
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,21 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'version': '1.0', | ||
| 'depends': ['base'], | ||
| 'author': 'Shivam Saksham(shsak)', | ||
| 'category': 'Sales', | ||
| 'description': """ | ||
| An Real Estate App to buy, sell, and rent properties. | ||
| """, | ||
| 'application': True, | ||
| 'license': 'LGPL-3', | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_type_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,110 @@ | ||
| from odoo import models, fields, api, exceptions, _ | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate_property' | ||
| _description = 'Estate Property details' | ||
| _order = 'id desc' | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| default=lambda self: fields.Date.add(fields.Date.today(), 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='Garden Orientation', | ||
| selection=[ | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West') | ||
| ] | ||
| ) | ||
| state = fields.Selection( | ||
| string='Status', | ||
| selection=[ | ||
| ('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled') | ||
| ], | ||
| default='new', | ||
| required=True, | ||
| copy=False | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| property_type_id = fields.Many2one('estate.property.type', string='Type') | ||
| buyer = fields.Many2one('res.partner', copy=False) | ||
| salesperson = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user) | ||
| tag_ids = fields.Many2many('estate.property.tag', string='Tag') | ||
| 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 cannot be 0 or less then 0' | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| 'The Selling price cannot be less then 0' | ||
| ) | ||
|
|
||
| @api.constrains('selling_price', 'buyer', 'expected_price') | ||
| def _check_selling_price_90p(self): | ||
| for record in self: | ||
| if record.selling_price == 0: | ||
| return False | ||
| if float_compare((record.selling_price / record.expected_price) * 100, 90, precision_digits=2) < 0: | ||
| raise exceptions.ValidationError(_('Selling Price should be 90% or more of 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') or [0]) | ||
|
|
||
| @api.onchange('garden') | ||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_orientation = 'north' | ||
| self.garden_area = 10 | ||
| else: | ||
| self.garden_orientation = None | ||
| self.garden_area = 0 | ||
|
|
||
| def action_cancel_property(self): | ||
| if self.filtered(lambda x: x.state == 'sold'): | ||
| raise exceptions.UserError(_('A sold property cannot be cancelled')) | ||
|
|
||
| self.state = 'cancelled' | ||
| return True | ||
|
|
||
| def action_property_sold(self): | ||
| if self.filtered(lambda x: x.state == 'cancelled'): | ||
| raise exceptions.UserError(_('A cancelled property cannot be sold')) | ||
|
|
||
| self.state = 'sold' | ||
| return True | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_sold(self): | ||
| if self.filtered(lambda x: x.state not in ('new', 'cancelled')): | ||
| raise exceptions.UserError(_('Cannot delete property which is not yer sold or cancelled')) |
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 @@ | ||
| from odoo import models, fields, api, exceptions, _ | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = 'Offer to buy the property' | ||
| _order = 'price desc' | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| string='Status', | ||
| selection=[('accepted', 'Accepted'), ('refused', 'Refused')], | ||
| copy=False, | ||
| ) | ||
| partner_id = fields.Many2one('res.partner', required=True) | ||
| property_id = fields.Many2one('estate_property', required=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date(compute='_compute_offer_date_deadline', inverse='_inverse_offer_date_deadline') | ||
| property_type_id = fields.Many2one(related='property_id.property_type_id') | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'Offer Price cannot be 0 or below 0' | ||
| ) | ||
|
|
||
| @api.depends('validity') | ||
| def _compute_offer_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| record.date_deadline = fields.Date.add(record.create_date.date(), days=record.validity) | ||
| else: | ||
| record.date_deadline = fields.Date.add(fields.Date.today(), days=record.validity) | ||
|
|
||
| def _inverse_offer_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_offer_accepted(self): | ||
| for record in self: | ||
| if record.property_id.buyer: | ||
| raise exceptions.UserError(_('An another offer is already accepted')) | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer = record.partner_id | ||
| record.property_id.state = 'offer_accepted' | ||
| record.status = 'accepted' | ||
| return True | ||
|
|
||
| def action_offer_refused(self): | ||
| for record in self: | ||
| record.status = 'refused' | ||
| return True | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| if len(vals_list) > 0: | ||
| prop = self.env['estate_property'].browse(vals_list[0]['property_id']) | ||
| if prop.best_price > vals_list[0]['price']: | ||
| raise exceptions.UserError(_('An offer with high price already exists.')) | ||
|
|
||
| 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,15 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = 'Tag for the property' | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| 'unique(name)', | ||
| 'A tag with the same name already exists.' | ||
| ) |
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 models, fields, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Defines the type of Real Estate Property' | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many('estate_property', 'property_type_id', string='Properties') | ||
| sequence = fields.Integer( | ||
| default=1, | ||
| help='used to order the type based on the number of time it is used' | ||
| ) | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') | ||
| offer_count = fields.Integer(compute='_compute_offers_count') | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| 'unique(name)', | ||
| 'A tag with the same name already exists.' | ||
| ) | ||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_offers_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,11 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many( | ||
| 'estate_property', | ||
| 'salesperson', | ||
| 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 | ||
| 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,14 @@ | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_first_level_menu" name="Advertisement"> | ||
| <menuitem id="estate_property_model_menu_action" action="estate_property_action" /> | ||
| </menuitem> | ||
|
|
||
| <menuitem id="estate_first_level_setting_menu" name="Settings"> | ||
shsak-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <menuitem id="estate_property_type_model_menu_action" | ||
| action="estate_property_type_action" /> | ||
| <menuitem id="estate_property_tag_model_menu_action" | ||
| action="estate_property_tag_action" /> | ||
| </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,43 @@ | ||
| <odoo> | ||
| <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-success="status == 'accepted'" decoration-danger="status == 'refused'"> | ||
| <field name="price" /> | ||
| <field name="partner_id" string="Partner" /> | ||
| <field name="validity" string="Validity (days)" /> | ||
| <field name="date_deadline" /> | ||
| <button name="action_offer_accepted" string="Accept" type="object" icon="fa-check" | ||
| invisible="status" /> | ||
| <button name="action_offer_refused" string="Refuse" type="object" icon="fa-close" | ||
| invisible="status" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_form_view" model="ir.ui.view"> | ||
| <field name="name">Property Offer List</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Offer"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price" /> | ||
| <field name="partner_id" string="Partener" /> | ||
| <field name="validity" string="Validity (days)" /> | ||
| <field name="date_deadline" /> | ||
| <field name="status" /> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estaet_property_offer_view_action" model="ir.actions.act_window"> | ||
| <field name="name">Estate Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</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,17 @@ | ||
| <odoo> | ||
| <record id="estate_property_tag_list_view" model="ir.ui.view"> | ||
| <field name="name">Tags</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list editable="bottom"> | ||
| <field name="name" /> | ||
| </list> | ||
| </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,56 @@ | ||
| <odoo> | ||
| <record id="estate_property_type_properties_view" 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="Properties"> | ||
| <sheet> | ||
| <div class="oe_button_box" name="button_box"> | ||
| <button class="oe_stat_button" name="estate.estaet_property_offer_view_action" | ||
| type="action" > | ||
| <div class="o_stat_info"> | ||
| <span class="o_stat_value"> | ||
| <field name="offer_count" /> | ||
| </span> | ||
| <span class="o_stat_text"> | ||
| Offers | ||
| </span> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| <h1> | ||
| <field name="name" /> | ||
| </h1> | ||
| <notebook> | ||
| <page string="Properties"> | ||
| <field name="property_ids"> | ||
| <list> | ||
| <field name="name" string="Title" /> | ||
| <field name="expected_price" /> | ||
| <field name="state" string="Status" /> | ||
| </list> | ||
| </field> | ||
| </page> | ||
| </notebook> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_list_view" model="ir.ui.view"> | ||
| <field name="name">estate_property_type_list</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Types"> | ||
| <field name="sequence" widget="handle" /> | ||
| <field name="name" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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> | ||
| </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.