-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[ADD] estate: implement estate module (setup, models, fields, security) #1226
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
sngohodoo
wants to merge
18
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-sngoh
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
18 commits
Select commit
Hold shift + click to select a range
affb170
[ADD] estate: create module structure
sngohodoo d14c317
[IMP] estate: create core property record
sngohodoo 1c4aa83
[IMP] estate: add property fields and constraints
sngohodoo 0ec7f66
[IMP] estate: grant basic access to properties
sngohodoo 43c0856
[FIX] estate: remove extra whitespace in manifest
sngohodoo 2c07a28
[IMP] estate: build initial user interface
sngohodoo 8c89e44
[IMP] estate: improve property views structure
sngohodoo bf55878
[IMP] estate: assign buyers and sales agents
sngohodoo 8dfced7
[IMP] estate: improve property type views
sngohodoo 4609a9f
[IMP] estate: track property tags and offers
sngohodoo a2b4944
[IMP] estate: calculate total property area
sngohodoo 838709c
[IMP] estate: sync offer validity and deadlines
sngohodoo 1ecb3e7
[LINT] estate: fix python style and whitespace
sngohodoo 648736d
[IMP] estate: process property sales and offers
sngohodoo f3e14e7
[FIX] estate: support batch actions on offers
sngohodoo eb3eb14
[IMP] estate: enforce valid prices and tags
sngohodoo 9b0fde4
[IMP] estate: enforce minimum selling price
sngohodoo 4579c0d
[CLN] estate: enforce minimum selling price
sngohodoo 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,4 @@ | ||
| { | ||
| "xml.symbols.enabled": false, | ||
| "python.languageServer": "None" | ||
| } |
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": "Estate", | ||
| "application": True, | ||
| "installable": True, | ||
| "author": "sngoh", | ||
| "depeneds": ["base"], | ||
| "license": "LGPL-3", | ||
| "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", | ||
| ], | ||
| } |
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_types | ||
| 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,107 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| 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( | ||
| copy=False, default=fields.Date.add(fields.Date.today(), months=3) | ||
| ) | ||
| 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)") | ||
| garden_orientation = fields.Selection( | ||
| string="Garden Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| active = fields.Boolean("Active", default=True) | ||
| state = fields.Selection( | ||
| string="Property State", | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| sales_man = fields.Many2one( | ||
| "res.users", string="Salesman", default=lambda self: self.env.user | ||
| ) | ||
| buyer = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| tag = fields.Many2many("estate.property.tag", string="Tags") | ||
| offer = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
| total_area = fields.Float(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for records in self: | ||
| records.total_area = records.living_area + records.garden_area | ||
|
|
||
| @api.depends("offer.price") | ||
| def _compute_best_price(self): | ||
| for records in self: | ||
| prices = records.mapped("offer.price") | ||
| records.best_price = max(prices) if prices else 0 | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "A property expected price must be strictly positive", | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "A property selling price must be positive", | ||
| ) | ||
|
|
||
| @api.constrains("state") | ||
| def on_state_change(self): | ||
| for record in self: | ||
| if record.state == "offer_accepted" or record.state == "sold": | ||
| if float_compare(record.selling_price, record.expected_price * 0.9, 3): | ||
| raise ValidationError("Selling price error") | ||
|
|
||
| @api.onchange("garden") | ||
| def _on_change_garden(self): | ||
| for records in self: | ||
| if records.garden: | ||
| records.garden_area = 10 | ||
| records.garden_orientation = "north" | ||
| else: | ||
| records.garden_area = False | ||
| records.garden_orientation = False | ||
|
|
||
| def sold_button(self): | ||
| for records in self: | ||
| if records.state == "cancelled": | ||
| raise UserError("Cancelled property cannot be sold.") | ||
| records.state = "sold" | ||
| records.selling_price = records.selling_price | ||
| return True | ||
|
|
||
| def cancel_button(self): | ||
| for records in self: | ||
| if records.state == "sold": | ||
| raise UserError("Sold property cannoy be cancelled.") | ||
| records.state = "cancelled" | ||
| records.state = False | ||
| 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,61 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Real E-state offer" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| string="Offer Status", | ||
| selection=[ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused"), | ||
| ], | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Partner", required=True) | ||
| property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date( | ||
| compute="_compute_date_deadline", inverse="_inverse_date_deadline" | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for records in self: | ||
| base_date = ( | ||
| records.create_date.date() | ||
| if records.create_date | ||
| else fields.Date.today() | ||
| ) | ||
| records.date_deadline = fields.Date.add(base_date, days=records.validity) | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "An offer price must be strictly positive", | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for records in self: | ||
| base_date = ( | ||
| records.create_date.date() | ||
| if records.create_date | ||
| else fields.Date.today() | ||
| ) | ||
| if records.date_deadline: | ||
| records.validity = (records.date_deadline - base_date).days | ||
|
|
||
| def accept_button(self): | ||
| for records in self: | ||
| records.status = "accepted" | ||
| records.property_id.buyer = records.partner_id | ||
| records.property_id.selling_price = records.price | ||
| records.property_id.state = "offer_accepted" | ||
|
|
||
| def reject_button(self): | ||
| for records in self: | ||
| records.status = "refused" | ||
| if records.property_id.buyer == records.partner_id: | ||
| records.property_id.buyer = False | ||
| records.property_id.selling_price = False | ||
| records.property_id.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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Real E-state Property Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _check_unique_tag = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "A property tag name 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 EstatePropertyTypes(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Real E-state Property Type" | ||
|
|
||
| name = fields.Char() | ||
|
|
||
| _check_unique_property_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "A property type should 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 | ||
| access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type,access_estate_property_type,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_estdate_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 @@ | ||
| <odoo> | ||
| <menuitem id="menu_root" name="E-state"> | ||
| <menuitem id="advertisement" name="Advertisements"> | ||
| <menuitem id="property_menu" action="estate_property_action" /> | ||
| </menuitem> | ||
| <menuitem id="settings" name="settings"> | ||
| <menuitem id="property_types" action="estate_property_type_action" /> | ||
| <menuitem id="property_tag" action="estate_property_tag_action" /> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> | ||
|
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. should be one empty line at the end of the file. |
||
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,38 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <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> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <button name="accept_button" title="Accept" type="object" icon="fa-check" /> | ||
| <button name="reject_button" title="Reject" type="object" icon="fa-times" /> | ||
| <field name="status" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_form" 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" /> | ||
| <field name="status" /> | ||
| </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,34 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tag</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_list_view" 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> | ||
| <field name="name" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_form_view" 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> | ||
| <sheet> | ||
| <group> | ||
| <field name="name" /> | ||
| </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,36 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_type_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Type</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,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> | ||
| <field name="name" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_form_view" model="ir.ui.view"> | ||
| <field name="name">etate.property.type.form</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <div class="oe_title"> | ||
| <h1> | ||
| <group> | ||
| <field name="name" /> | ||
| </group> | ||
| </h1> | ||
| </div> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| </odoo> | ||
|
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. should be one empty line at the end of the file. |
||
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.
unneccary diff.