-
Notifications
You must be signed in to change notification settings - Fork 2.8k
19.0 Estate tutorial (VIKRI) #1078
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
Open
vikri-odoo
wants to merge
12
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-fix-onboarding-vikri
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
36e0588
[ADD] new addon for real estate onboarding project
vikri-odoo 528b3cf
[ADD] add the new model for property types
vikri-odoo abc57b5
[LINT] format the code using ruff
vikri-odoo 247d7ca
[REF] address the PR comments and resole it
vikri-odoo 66c0381
[REF] update the default availability method to lamda
vikri-odoo d00c06f
[ADD] created new model for estate offers
vikri-odoo 484f590
[ADD] chapter 9: action added for buttons
vikri-odoo 477c360
[LINT] format the code to fix the ci\style issue
vikri-odoo b0bf8ef
[FIX] typo fix the string parameter to lower case for property_type i…
vikri-odoo ad8f8af
[ADD] constrains added for selling and expected prices
vikri-odoo caaffd2
[ADD] complete the chapter 11
vikri-odoo bc20c35
[REM] unused print statement removed
vikri-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 Application", | ||
| "summary": "This is a custom real estate application for understanding Odoo", | ||
| "description": "This is a custom real estate application for understanding Odoo", | ||
| "author": "Odoo S.A.", | ||
| "website": "https://www.odoo.com", | ||
| "category": "Tutorials", | ||
| "version": "0.1", | ||
| "application": True, | ||
| "data": [ | ||
| "data/res_estate_data.xml", | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_templates.xml", | ||
| "views/estate_property_offers_templates.xml", | ||
| "views/estate_property_type_templates.xml", | ||
| "views/estate_property_tags_templates.xml", | ||
| "views/estate_menu.xml", | ||
| ], | ||
| "assets": {}, | ||
| "license": "AGPL-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,103 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <data noupdate="1"> | ||
| <record id="type_1" model="estate.property.type"> | ||
| <field name="name">House</field> | ||
| </record> | ||
| <record id="type_2" model="estate.property.type"> | ||
| <field name="name">Apartment</field> | ||
| </record> | ||
| <record id="type_3" model="estate.property.type"> | ||
| <field name="name">Castle</field> | ||
| </record> | ||
| <record id="property_1" model="estate.property"> | ||
| <field name="name">Property 1</field> | ||
| <field name="description">Description 1</field> | ||
| <field name="postcode">1000</field> | ||
| <field name="expected_price">10000</field> | ||
| <field name="selling_price">0</field> | ||
| <field name="active">True</field> | ||
| <field name="bedrooms">2</field> | ||
| <field name="living_area">2</field> | ||
| <field name="facades">2</field> | ||
| <field name="garage">True</field> | ||
| <field name="garden">True</field> | ||
| <field name="garden_area">22</field> | ||
| <field name="state">new</field> | ||
| <field name="garden_orientation">north</field> | ||
| <field name="property_type" ref="type_1"/> | ||
| <!-- <field name="tags">--> | ||
| <!-- <record id="tag_1" model="estate.property.tags">--> | ||
| <!-- <field name="name">cozy</field>--> | ||
| <!-- </record>--> | ||
| <!-- <record id="tag_2" model="estate.property.tags">--> | ||
| <!-- <field name="name">small</field>--> | ||
| <!-- </record>--> | ||
| <!-- </field>--> | ||
| <field name="offer_ids"> | ||
| <record id="offer_1" model="estate.property.offers"> | ||
| <field name="price">20000.00</field> | ||
| <field name="partner_id" ref="base.partner_admin"/> | ||
| </record> | ||
| <record id="offer_2" model="estate.property.offers"> | ||
| <field name="price">10000.00</field> | ||
| <field name="partner_id" ref="base.partner_admin"/> | ||
| </record> | ||
| </field> | ||
| </record> | ||
| <record id="property_2" model="estate.property"> | ||
| <field name="name">Property 2</field> | ||
| <field name="description">Description 2</field> | ||
| <field name="postcode">2000</field> | ||
| <field name="expected_price">10000</field> | ||
| <field name="selling_price">0</field> | ||
| <field name="active">True</field> | ||
| <field name="bedrooms">2</field> | ||
| <field name="living_area">2</field> | ||
| <field name="facades">2</field> | ||
| <field name="garage">True</field> | ||
| <field name="garden">True</field> | ||
| <field name="garden_area">22</field> | ||
| <field name="state">new</field> | ||
| <field name="garden_orientation">north</field> | ||
| <field name="property_type" ref="type_2"/> | ||
| <!-- <field name="tags">--> | ||
| <!-- <record id="tag_3" model="estate.property.tags">--> | ||
| <!-- <field name="name">big</field>--> | ||
| <!-- </record>--> | ||
| <!-- </field>--> | ||
| <field name="offer_ids"> | ||
| <record id="offer_3" model="estate.property.offers"> | ||
| <field name="price">20000.00</field> | ||
| <field name="partner_id" ref="base.partner_admin"/> | ||
| </record> | ||
| <record id="offer_4" model="estate.property.offers"> | ||
| <field name="price">10000.00</field> | ||
| <field name="partner_id" ref="base.partner_admin"/> | ||
| </record> | ||
| </field> | ||
| </record> | ||
| <record id="property_3" model="estate.property"> | ||
| <field name="name">Property 3</field> | ||
| <field name="description">Description 3</field> | ||
| <field name="postcode">1040</field> | ||
| <field name="expected_price">10000</field> | ||
| <field name="selling_price">0</field> | ||
| <field name="active">True</field> | ||
| <field name="bedrooms">2</field> | ||
| <field name="living_area">2</field> | ||
| <field name="facades">2</field> | ||
| <field name="garage">True</field> | ||
| <field name="garden">True</field> | ||
| <field name="garden_area">22</field> | ||
| <field name="state">new</field> | ||
| <field name="garden_orientation">north</field> | ||
| <field name="property_type" ref="type_3"/> | ||
| <!-- <field name="tags">--> | ||
| <!-- <record id="tag_4" model="estate.property.tags">--> | ||
| <!-- <field name="name">expensive</field>--> | ||
| <!-- </record>--> | ||
| <!-- </field>--> | ||
| </record> | ||
| </data> | ||
| </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,4 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tags | ||
| from . import estate_property_offers |
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,116 @@ | ||
| from datetime import date | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class Estate(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Real_Estate_Property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| description = fields.Text(string="Description") | ||
| postcode = fields.Char(string="Postcode") | ||
| date_availability = fields.Date( | ||
| string="Date Availability", | ||
| default=lambda self: date.today() + relativedelta(months=3), | ||
| copy=False, | ||
| ) | ||
| expected_price = fields.Float(string="Expected Price", required=True) | ||
| selling_price = fields.Float(string="Selling Price", readonly=True, copy=False) | ||
| active = fields.Boolean(string="Active", default=True) | ||
| bedrooms = fields.Integer(string="Bedrooms", default=2) | ||
| living_area = fields.Integer(string="Living Area") | ||
| facades = fields.Integer(string="Facades") | ||
| garage = fields.Boolean(string="Garage") | ||
| garden = fields.Boolean(string="Garden") | ||
| garden_area = fields.Integer(string="Garden Area") | ||
| state = fields.Selection( | ||
| string="State", | ||
| selection=[ | ||
| ('new', "New"), | ||
| ('offered', "Offer Received"), | ||
| ('accepted', "Offer Accepted"), | ||
| ('sold', "Sold"), | ||
| ('cancelled', "Cancelled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| ) | ||
| garden_orientation = fields.Selection( | ||
| [ | ||
| ('north', "North"), | ||
| ('south', "South"), | ||
| ('east', "East"), | ||
| ('west', "West"), | ||
| ] | ||
| ) | ||
| sales_person = fields.Many2one( | ||
| 'res.users', | ||
| string="Sales Person", | ||
| copy=False, | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| buyer = fields.Many2one('res.partner', string="Buyer") | ||
| property_type = fields.Many2one( | ||
| comodel_name="estate.property.type", | ||
| string="Property Type", | ||
| ) | ||
| tags = fields.Many2many('estate.property.tags', string="Tags") | ||
| offer_ids = fields.One2many('estate.property.offers', 'property_id', string="Offers") | ||
| total_area = fields.Integer(compute='_compute_total_area') | ||
| best_offer = fields.Float(compute='_compute_best_offer') | ||
|
|
||
| @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: | ||
| offers = record.offer_ids.mapped('price') | ||
| if offers: | ||
| record.best_offer = max(offers) | ||
| else: | ||
| record.best_offer = 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 = 0 | ||
|
|
||
| def action_set_sold(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise UserError("This property cannot be sold.") | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| def action_set_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError("This property is sold.") | ||
| record.state = 'cancelled' | ||
| return True | ||
|
|
||
| @api.constrains('expected_price') | ||
| def _check_expected_price(self): | ||
| for record in self: | ||
| if record.expected_price <= 0: | ||
| raise ValidationError("Expected price cannot be negative.") | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if record.selling_price < 0: | ||
| raise ValidationError("Selling price cannot be negative.") | ||
| if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1: | ||
| 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,49 @@ | ||
| from datetime import date | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError | ||
|
|
||
|
|
||
| class EstatePropertyOffers(models.Model): | ||
| _name = "estate.property.offers" | ||
| _description = "Real Estate Property Offers" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float(string="Price") | ||
| status = fields.Selection( | ||
| string="Status", | ||
| selection=[('accepted', "Accepted"), ('rejected', "Rejected")], | ||
| copy=False, | ||
| readonly=True, | ||
| ) | ||
| partner_id = fields.Many2one(comodel_name='res.partner', required=True) | ||
| property_id = fields.Many2one(comodel_name='estate.property', required=True) | ||
| property_type_id = fields.Many2one(related='property_id.property_type', store=True) | ||
| validity = fields.Integer(string="Validity", default=7) | ||
| date_deadline = fields.Date(compute='_compute_date_deadline') | ||
|
|
||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| start_date = record.create_date if record.create_date else date.today() | ||
| record.date_deadline = start_date + relativedelta(days=record.validity) | ||
|
|
||
| def action_accept_offer(self): | ||
| for record in self: | ||
| record.status = 'accepted' | ||
| record.property_id.state = 'accepted' | ||
| record.property_id.buyer = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| return True | ||
|
|
||
| def action_reject_offer(self): | ||
| for record in self: | ||
| record.status = 'rejected' | ||
| return True | ||
|
|
||
| @api.constrains('price') | ||
| def _check_price(self): | ||
| for record in self: | ||
| if record.price <= 0: | ||
| raise ValidationError("Offer price cannot be negative.") |
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 fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTags(models.Model): | ||
| _name = "estate.property.tags" | ||
| _description = "Real Estate Property Tags" | ||
| _order = "name asc" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| color = fields.Integer(string="Color") | ||
|
|
||
| _name_uniq = models.Constraint( | ||
| 'unique (name)', | ||
| "This tag is already available", | ||
| ) | ||
|
Comment on lines
+12
to
+15
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. Probably fits a single line |
||
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 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
|
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. These are tech strings 😉 |
||
| _description = "Real Estate Property Type" | ||
|
|
||
| name = fields.Char(string="Name", required=True) | ||
| property_ids = fields.One2many('estate.property', 'property_type') | ||
| offer_ids = fields.One2many(comodel_name="estate.property.offers", inverse_name="property_type_id", string="Offers") | ||
| 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 | ||
| 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_tags,access.estate.property.tags,model_estate_property_tags,base.group_user,1,1,1,1 | ||
| access_estate_property_offers,access.estate.property.offers,model_estate_property_offers,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,7 @@ | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"/> | ||
| <menuitem id="estate_menu_action" action="test_model_action" parent="estate_menu_root" sequence="1"/> | ||
| <menuitem id="estate_menu_config" name="Settings" parent="estate_menu_root"/> | ||
| <menuitem id="estate_property_type_menu_action" action="property_type_action" parent="estate_menu_config"/> | ||
| <menuitem id="estate_property_tag_menu_action" action="property_tag_action" parent="estate_menu_config"/> | ||
| </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,22 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offers</field> | ||
| <field name="view_mode">list,form</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| </record> | ||
| <record id="property_offers_view_tree" model="ir.ui.view"> | ||
| <field name="name">estate.property.offers.list</field> | ||
| <field name="model">estate.property.offers</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Offer" editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='rejected'"> | ||
| <field name="price"/> | ||
| <field name="partner_id" string="Partner"/> | ||
| <field name="property_type_id" string="Type"/> | ||
| <button name="action_accept_offer" string="Accept" type="object" icon="fa-check" invisible="status"/> | ||
| <button name="action_reject_offer" string="Reject" type="object" icon="fa-times" invisible="status"/> | ||
| </list> | ||
| </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 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tags</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| <record id="property_type_tag_tree" model="ir.ui.view"> | ||
| <field name="name">estate.property.tags.list</field> | ||
| <field name="model">estate.property.tags</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Estate" editable="bottom"> | ||
| <field name="name"/> | ||
| </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.
Mark your strings as translatable using
self.env._method