-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[ADD] estate: created a new module #1013
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
pimai-odoo
wants to merge
7
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorial-pimai
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
7 commits
Select commit
Hold shift + click to select a range
f6b793d
[ADD] estate: created a new module
pimai-odoo c86ae0a
[IMP] estate: update fields and menus in real estate
pimai-odoo 3e951c1
[IMP] estate: add list/form/search views with group by in Real Estate
pimai-odoo 17de643
[IMP] estate: added property type,tags,buyer,salesperson & offers in …
pimai-odoo ff2dc3a
[IMP] estate: add computed fields,inverse funcs, onchange & Sold/Canc…
pimai-odoo 6f8f97b
[IMP] estate: added Accept,Refuse buttons & related functionality in …
pimai-odoo 50a5546
[IMP] estate: add SQL & Python constraints for price & uniqueness in …
pimai-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,16 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'depends': ['base'], | ||
| '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_property_offer_views.xml', | ||
| 'views/estate_menus.xml' | ||
| ], | ||
| 'application': True, | ||
| 'installable': True, | ||
| 'author': 'Odoo S.A.', | ||
| '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,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,108 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError | ||
| from odoo.exceptions import ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real Estate Property" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date("Availability Date", default=fields.Date.today() + relativedelta(months=3)) | ||
| expected_price = fields.Float("Expected Price", required=True) | ||
| selling_price = fields.Float("Selling Price", readonly=True) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer("Living Area(sqm)") | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer("Garden Area(sqm)") | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| string="Garden Orientation", | ||
| ) | ||
| state = fields.Selection( | ||
| [ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| "Status", | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| property_type_id = fields.Many2one("estate.property.type", "Property Type") | ||
| buyer_id = fields.Many2one("res.partner", "Buyer", copy=False) | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", string="Salesperson") | ||
| tag_ids = fields.Many2many("estate.property.tag", "Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", "Offers") | ||
| total_area = fields.Integer("Total Area(sqm)", compute="_compute_total_area") | ||
| best_price = fields.Float("Best Offer", compute="_compute_best_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: | ||
| if record.offer_ids: | ||
| record.best_price = max(record.offer_ids.mapped("price")) | ||
| else: | ||
| record.best_price = 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 | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError("A sold property cannot be cancelled") | ||
| else: | ||
| self.state = 'cancelled' | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise UserError("A cancelled property cannot be set as sold") | ||
| else: | ||
| self.state = 'sold' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The expected price of a property must be strictly positive.' | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price > 0)', | ||
| 'The selling price of a property must be positive.' | ||
| ) | ||
|
|
||
| @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) < 0: | ||
| raise ValidationError("The selling price cannot be lower than 90% of the expected price.") | ||
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,50 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Real Estate Property Offer" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| [("accepted", "Accepted"), ("refused", "Refused")], | ||
| 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(string="Validity(days)", default=7) | ||
| date_deadline = fields.Date(string="Deadline Date", compute="_compute_date_deadline", inverse="_inverse_date_deadline") | ||
|
|
||
| @api.depends('validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| creation_date = record.create_date or fields.Date.today() | ||
| record.date_deadline = relativedelta(days=record.validity) + creation_date | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| creation_date = record.create_date or fields.Date.today() | ||
| record.validity = (record.date_deadline - fields.Date.to_date(creation_date)).days | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| if record.property_id.buyer_id: | ||
| raise UserError("Property already accepted") | ||
| else: | ||
| record.status = 'accepted' | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = 'offer_accepted' | ||
| record.property_id.buyer_id= record.partner_id | ||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| record.status = 'refused' | ||
| return True | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The price of an offer must be strictly positive.' | ||
| ) |
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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Real Estate Property Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _check_tag_name_unique = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'The name of the property tag 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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Real Estate Property Type" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _check_type_name_unique = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'The name of the property type 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,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,estate.property.tag.access,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,estate.property.offer.access,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,26 @@ | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate" /> | ||
|
|
||
| <menuitem id="menu_estate_advertisements" | ||
| name="Advertisements" | ||
| parent="estate_menu_root" /> | ||
|
|
||
| <menuitem id="menu_estate_property_action" | ||
| name="Properties" | ||
| parent="menu_estate_advertisements" | ||
| action="action_estate_property" /> | ||
|
|
||
| <menuitem id="menu_estate_settings" | ||
| name="Settings" | ||
| parent="estate_menu_root" /> | ||
|
|
||
| <menuitem id="menu_estate_property_type_action_settings" | ||
| name="Property Types" | ||
| parent="menu_estate_settings" | ||
| action="estate_property_type_action" /> | ||
|
|
||
| <menuitem id="menu_estate_property_tag_action_settings" | ||
| name="Property Tags" | ||
| parent="menu_estate_settings" | ||
| action="action_estate_property_tag" /> | ||
| </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,35 @@ | ||
| <odoo> | ||
| <record id="estate_property_offer_tree_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> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="status" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <button name="action_accept" type="object" string="Accept" icon="fa-check"/> | ||
| <button name="action_refuse" type="object" string="Refuse" icon="fa-times"/> | ||
| </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="status" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| </group> | ||
| </sheet> | ||
| </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,7 @@ | ||
| <odoo> | ||
| <record id="action_estate_property_tag" 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,7 @@ | ||
| <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> | ||
| </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.
It will throw an error if multiple records are in self.