-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: added Estate Module #1107
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
japat-odoo
wants to merge
11
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-japat
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
a6ca236
[ADD] estate: created the model and Initalized it with the postgre db
japat-odoo 26ff004
[IMP] estate: done ui major search, list, form
japat-odoo dbcf3f0
[IMP] estate: improvement in the code structure
japat-odoo 833d4f5
[IMP] estate: add property offer model and relations
japat-odoo 7c49cc7
[IMP] estate: added computed fields
japat-odoo 37413c2
[IMP] estate: add onchange and fix parseError
japat-odoo 364860c
[IMP] estate: added property and offer state management
japat-odoo 217814f
[IMP] estate: add SQL and Python constraints
japat-odoo e49fcb1
[IMP] estate: improve UI/UX with widgets, ordering, and conditional a…
japat-odoo 115f009
[IMP] estate: add offer stat button on property types
japat-odoo 68148e2
[FIX] estate: add missing imports for UserError and translation
japat-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,20 @@ | ||
| { | ||
| "name": "Estate", | ||
| "version": "1.0", | ||
| "depends": ["base"], | ||
| "author": "japat", | ||
| "category": "Category", | ||
| "description": """ | ||
| Hello , Real Estate for everyone | ||
| """, | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_menus.xml", | ||
| "views/estate_property_offer.xml", | ||
| ], | ||
| "license": "LGPL-3", | ||
| "application": 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,4 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer |
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,120 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import api, fields, models, _ | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class Property(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( | ||
| copy=False, default=lambda self: fields.Date.today() + timedelta(days=90) | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer(string="Living Area(sqm)") | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer(string="Garden Area(sqm)", store=True) | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("west", "West"), | ||
| ("east", "East"), | ||
| ("south", "South"), | ||
| ] | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| copy=False, | ||
| required=True, | ||
| ) | ||
|
|
||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", string="Salesman", default=lambda self: self.env.user | ||
| ) | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False, readonly=True) | ||
| tag_ids = fields.Many2many("estate.property.tag", string="Property Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id") | ||
| total_area = fields.Float(string="Total Area(sqm)", compute="_compute_total_area") | ||
| best_price = fields.Float( | ||
| string="Best Offer", compute="_compute_best_offer", readonly=True, copy=False | ||
| ) | ||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price >= 0)", | ||
| "The expected price should be strictly positive", | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "The selling price should be strictly positive", | ||
| ) | ||
|
|
||
| @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") | ||
| def _compute_best_offer(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_price(self): | ||
| for record in self: | ||
| if float_is_zero(record.selling_price, precision_rounding=0.001): | ||
| continue | ||
| if ( | ||
| float_compare( | ||
| record.selling_price, | ||
| record.expected_price * 0.9, | ||
| precision_rounding=0.01, | ||
| ) | ||
| == -1 | ||
| ): | ||
| raise ValidationError( | ||
| "The selling price must be at least 90% of the expected price" | ||
| ) | ||
|
|
||
| def sold_button_action(self): | ||
| for record in self: | ||
| if self.filtered(lambda x: x.state == "cancelled"): | ||
| raise UserError(_("Cancelled Property cannot be sold.")) | ||
| else: | ||
| record.state = "sold" | ||
|
|
||
| def cancelled_button_action(self): | ||
| for record in self: | ||
| if record.state == "sold": | ||
| raise UserError(_("Sold Property cannot be Cancelled.")) | ||
| record.state = "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,74 @@ | ||
| from datetime import timedelta | ||
|
|
||
| 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() | ||
| status = fields.Selection( | ||
| 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, string="Validity(Days)") | ||
| date_deadline = fields.Date( | ||
| string="Deadline", | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
| disable_buttons = fields.Boolean(compute="_disable_offer_buttons", default=False) | ||
| property_type_id = fields.Many2one( | ||
| related="property_id.property_type_id", string="Property Type", store=True | ||
| ) | ||
| _check_offer_price = models.Constraint( | ||
| "CHECK(price>=0)", "Offer Price must be strictly positive" | ||
| ) | ||
|
|
||
| @api.depends("validity", "date_deadline") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| creation_date = record.create_date.date() | ||
| else: | ||
| creation_date = fields.Date.today() | ||
| record.date_deadline = timedelta(days=record.validity) + creation_date | ||
|
|
||
| @api.depends("property_id.offer_ids.status") | ||
| def _disable_offer_buttons(self): | ||
| for record in self: | ||
| record.disable_buttons = "accepted" in record.property_id.offer_ids.mapped( | ||
| "status" | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| creation_date = record.create_date.date() | ||
| else: | ||
| creation_date = fields.Date.today() | ||
| date_diff = record.date_deadline - creation_date | ||
| record.validity = date_diff.days | ||
|
|
||
| def action_refuse_offer(self): | ||
| for record in self: | ||
| if record.status == "accepted": | ||
| raise UserError(_("You cant refuse an already accepted offer")) | ||
| record.status = "refused" | ||
| return True | ||
|
|
||
| def action_accept_offer(self): | ||
| for record in self: | ||
| if "accepted" in record.property_id.offer_ids.mapped("status"): | ||
| raise UserError(_("An Offer has already been accepted for this offer")) | ||
|
|
||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = "offer_accepted" | ||
| record.property_id.buyer_id = record.partner_id | ||
| 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 EstatePropertyTags(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tags" | ||
| _tags_unique = models.Constraint("unique(name)", "Name already exist") | ||
| _order = "name asc" | ||
|
|
||
| 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 EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _type_unique = models.Constraint("unique(name)", "Name already Exist") | ||
| _order = "sequence, name asc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| sequence = fields.Integer() | ||
| 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,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,18 @@ | ||
| <odoo> | ||
| <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" | ||
| name="Properties" | ||
| parent="estate_first_level_menu" | ||
| action="estate_property_action" /> | ||
|
|
||
| <menuitem id="estate_property_type_setting" name="Setting" parent="estate_menu_root" /> | ||
|
|
||
| <menuitem id="estate_property_type_menu_action" name="Property Type" | ||
| parent="estate_property_type_setting" action="estate_property_type_action" /> | ||
|
|
||
| <menuitem id="estate_property_tag_menu" name="Property Tag" | ||
| parent="estate_property_type_setting" action="estate_property_tag_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,51 @@ | ||
| <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_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 editable="bottom" decoration-danger="status == 'refused'" | ||
| decoration-success="status == 'accepted'"> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <button name="action_refuse_offer" string="Reject" type="object" | ||
| icon="fa-times" | ||
| invisible="status != False or disable_buttons" /> | ||
| <button name="action_accept_offer" string="Accept" type="object" | ||
| icon="fa-check" | ||
| invisible="status != False or disable_buttons" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_form_view" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.form</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <sheet> | ||
| <group> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</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,18 @@ | ||
| <odoo> | ||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Properties Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_list" model="ir.ui.view"> | ||
| <field name="name">Properties Tags</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list name="Property tags" editable="bottom"> | ||
| <field name="name" /> | ||
| <field name="color" /> | ||
| </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.
Why is this field char() ?
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.
Because, Sir, here in Chapter 3, we are told to have this field as a Character
https://www.odoo.com/documentation/19.0/developer/tutorials/server_framework_101/03_basicmodel.html#types
I have done the other changes
Thank You.