-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add Estate Property Model #1229
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
radhr-odoo
wants to merge
31
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-radhr
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
31 commits
Select commit
Hold shift + click to select a range
d2a042c
[ADD] estate: added estate module
radhr-odoo 3ffb953
[IMP] estate: added model to estate module
radhr-odoo fe7d4dc
[IMP] estate: added estate_property model to module
radhr-odoo 3850148
[IMP] estate: improved module by adding security
radhr-odoo b3e3a0f
[IMP] estate: improved security feature
radhr-odoo bc40317
[IMP] estate: added action in estate
radhr-odoo 04229c3
[IMP] estate: added menu XML
radhr-odoo 25407f8
[IMP] estate: added active and state for better visibility
radhr-odoo 22b6c56
[IMP] estate: added list view to property module
radhr-odoo ea3c8ce
[IMP] estate: added form view to property module
radhr-odoo 8db7e88
[IMP] estate: added search view to property module
radhr-odoo fc48f23
[IMP] estate: module link
radhr-odoo d64021b
[IMP] estate: added property tags many2many
radhr-odoo 3e626b7
[IMP] estate: add page for property offer
radhr-odoo a79d97d
[IMP] estate: computed field total area added
radhr-odoo 2d76721
[IMP] estate: added garden onchange feature
radhr-odoo 217b4f7
[IMP] estate: computed field best price added
radhr-odoo 89f31b4
[IMP] estate: added inverse for validity and deadline
radhr-odoo 37dc1c1
[IMP] estate: confirm and reject added in offer list view
radhr-odoo 45c4529
[IMP] estate: save and cancel restricting feature added
radhr-odoo a8dc03b
[IMP] estate: added constraint using SQL
radhr-odoo 0e27beb
[IMP] estate: added python constraint
radhr-odoo 56a6568
[IMP] estate: added inline view, status bar and order
radhr-odoo fa6668f
[IMP] estate: add invisible attribute
radhr-odoo 371019c
[IMP] estate: stat button added
radhr-odoo 0724a0f
[IMP] estate: stat button added for property count
radhr-odoo 2fe10e0
[IMP] estate: handling offer creation and prices
radhr-odoo b4848d4
[IMP] estate: view and architectural inheritance
radhr-odoo d43058b
[ADD] estate account: get automatic invoices
radhr-odoo eac3b2b
[IMP] estate_account: invoice feature introduced
radhr-odoo 4b4de22
[IMP] estate: property Management with Kanban View & Smart Fields
radhr-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,18 @@ | ||
| { | ||
| "name": "estate", | ||
| "depends": ["base"], | ||
| "category": "tutorials", | ||
| "installable": True, | ||
| "application": True, | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_view.xml", | ||
| "views/estate_property_offer_view.xml", | ||
| "views/estate_property_type_view.xml", | ||
| "views/estate_property_tag_view.xml", | ||
| "views/estate_menu.xml", | ||
| "views/user_res_view.xml", | ||
| ], | ||
| "author": "RADHR", | ||
| "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 inherited_model |
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,133 @@ | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Estate Property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| date_availability = fields.Date( | ||
| string="Available From", | ||
| copy=False, | ||
| default=lambda self: fields.Date.add(fields.Date.today(), months=3), | ||
| ) | ||
| postcode = fields.Char(required=True) | ||
| expected_price = fields.Float() | ||
| selling_price = fields.Float(readonly=True) | ||
| 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( | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ("south", "South"), | ||
| ], | ||
| ) | ||
| active = fields.Boolean("Active", default=True) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("accepted", "Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| copy=False, | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property type") | ||
| buyer_id = fields.Many2one( | ||
| comodel_name="res.partner", | ||
| string="Buyer", | ||
| copy=False, | ||
| default=lambda self: self.env.user.partner_id, | ||
| ) | ||
| sales_person = fields.Many2one( | ||
| comodel_name="res.users", | ||
| string="Sales person", | ||
| index=True, | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| property_tag = fields.Many2many( | ||
| comodel_name="estate.property.tag", | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| comodel_name="estate.property.offer", | ||
| inverse_name="property_id", | ||
| ) | ||
| total_area = fields.Integer( | ||
| string="total_area", name="Total area", compute="_compute_total" | ||
| ) | ||
| best_price = fields.Integer( | ||
| compute="_compute_best_price", | ||
| store=True, | ||
| ) | ||
|
|
||
| @api.depends("garden_area", "living_area") | ||
| def _compute_total(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.depends("offer_ids.price") | ||
| def _compute_best_price(self): | ||
|
|
||
| for record in self: | ||
| prices = record.mapped("offer_ids.price") | ||
| record.best_price = max(prices) if prices else 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.ondelete(at_uninstall=False) | ||
| def _ondelete_property(self): | ||
| for record in self: | ||
| if record.state != "new" or record.state != "cancelled": | ||
| raise UserError( | ||
| "You can't delete the record which is not new or cancelled" | ||
| ) | ||
|
|
||
| def action_cancel_offer(self): | ||
| for record in self: | ||
| if record.state == "sold": | ||
| raise UserError("Saved properties can't be cancelled") | ||
| else: | ||
| record.state = "cancelled" | ||
|
|
||
| def action_sold_offer(self): | ||
| for record in self: | ||
| if record.state == "cancelled": | ||
| raise UserError("Cancelled properties can't be saved") | ||
| else: | ||
| record.state = "sold" | ||
|
|
||
| def action_approve_best(self): | ||
| self.offer_ids[0].status = "accepted" | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0 and selling_price > 0)", | ||
| "Expected price and selling price must be positive", | ||
| ) | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def _check_selling_expected_price(self): | ||
| for record in self: | ||
| base = record.expected_price * 0.9 | ||
| # value = str(base) | ||
| if record.selling_price and record.selling_price < base: | ||
| raise ValidationError( | ||
| f"Selling Price must be greater than 90 percent of expected price and atleast {base}" | ||
| ) | ||
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,80 @@ | ||
| from odoo import fields, models, api | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Estate Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| name = fields.Char(string="Property Offer", required=True) | ||
| price = fields.Integer(string="Price", required=True) | ||
| status = fields.Selection( | ||
| string="Status", | ||
| 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", default=7) | ||
| date_deadline = fields.Date( | ||
| string="Deadline", | ||
| compute="_compute_deadline", | ||
|
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. can you followe the coding guidelines for naming? |
||
| inverse="_inverse_deadline", | ||
| readonly=False, | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| related="property_id.property_type_id", store=True | ||
| ) | ||
|
|
||
| @api.model | ||
| def create(self, vals): | ||
| for val in vals: | ||
| property = self.env["estate.property"].browse(val["property_id"]) | ||
| if property.best_price > val.get("price", 0): | ||
| raise UserError("Better offer than this already exist") | ||
| property.state = "offer_received" | ||
| return super().create(vals) | ||
|
|
||
| # It gets changed on each changes because it works based on cache | ||
| @api.depends("create_date", "validity") | ||
| def _compute_deadline(self): | ||
| for records in self: | ||
| default_date = ( | ||
| records.create_date.date() | ||
| if records.create_date | ||
| else fields.Date.today() | ||
| ) | ||
| records.date_deadline = fields.Date.add(default_date, days=records.validity) | ||
|
|
||
| # Inverse is triggered when the computed field is written (usually during save),not during live editing. | ||
| def _inverse_deadline(self): | ||
| for records in self: | ||
| default_date = ( | ||
| records.create_date.date() | ||
| if records.create_date | ||
| else fields.Date.today() | ||
| ) | ||
| if records.date_deadline: | ||
| records.validity = (records.date_deadline - default_date).days | ||
|
|
||
| def save_offer(self): | ||
|
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. Can you followe the coding guidelines for naming? |
||
| for record in self: | ||
| if record.status == "accepted": | ||
| raise UserError("Property is already accepted") | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.state = "accepted" | ||
|
|
||
| def cancel_offer(self): | ||
| for record in self: | ||
| if record.status != "accepted" or record.status != "refused": | ||
| record.status = "refused" | ||
| if record.property_id.buyer_id == record.partner_id: | ||
| record.property_id.selling_price = False | ||
| record.property_id.state = False | ||
|
|
||
| _check_price = models.Constraint( | ||
| "CHECK(price >= 0)", "Price filled must be 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,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(string="name", required=True) | ||
| color = fields.Integer(string="color") | ||
|
|
||
| _check_name = models.Constraint( | ||
| "UNIQUE (name)", "Please give different tag as it is taken" | ||
| ) |
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 fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(string="name", required=True) | ||
| property_ids = fields.One2many( | ||
| comodel_name="estate.property", | ||
| inverse_name="property_type_id", | ||
| string="Property Type", | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", inverse_name="property_type_id" | ||
| ) | ||
| offer_count = fields.Integer(string="Total Offer", compute="_compute_offer_count") | ||
| sequence = fields.Integer("Sequence", default=1) | ||
|
|
||
| _name_check = models.Constraint("UNIQUE (name)", "Please add unique type") | ||
|
|
||
| @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,7 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many("estate.property", inverse_name="sales_person") |
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,acess_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_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 @@ | ||
| <odoo> | ||
| <menuitem id="estate_property_menu_root" name="Estate"> | ||
| <menuitem id="estate_property_first_level_menu" name="first_level_menu"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_property_settings" name="Settings"> | ||
| <menuitem id="estate_property_setting_property_type" action="estate_property_type_action" name="Property Type"/> | ||
| <menuitem id="estate_property_setting_property_tag" action="estate_property_tags_action" name="Property Tag"/> | ||
| </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,39 @@ | ||
| <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_view" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.list.view</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <list decoration-success="status=='accepted'" decoration-danger="status=='refused'"> | ||
| <field name="name"/> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <button name="save_offer" string="Confirm" type="object" icon="fa-check" invisible="status in ('accepted', 'refused')"/> | ||
| <button name="cancel_offer" string="Cancel" type="object" icon="fa-times" invisible="status in ('accepted', 'refused')"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| <record id="estate_property_offer_form_view" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.form.view</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <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="estate_property_tags_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> |
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.
Can you followe the coding guidelines?
https://www.odoo.com/documentation/19.0/contributing/development/coding_guidelines.html#symbols-and-conventions