-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19.0 real estate tutorial jakan #1109
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
jakan-odoo
wants to merge
19
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-real-estate-tutorial-jakan
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
19 commits
Select commit
Hold shift + click to select a range
71296e3
[ADD] estate: initialize module structure and model
jakan-odoo 3665d34
[ADD] estate: add security rules and fix style
jakan-odoo d8791e0
[ADD] estate: add basic user interface
jakan-odoo 378ed7c
[IMP] estate: create basic views and search
jakan-odoo f155702
[IMP] estate: add many2one model relation
jakan-odoo 1c69bbe
[IMP] estate: add one2many and many2many relations
jakan-odoo 9131c01
[IMP] estate: add computed fields and onchanges
jakan-odoo 2784e60
[IMP] estate: implement object-based actions
jakan-odoo 8c66cd9
[IMP] estate: add sql and python constraints
jakan-odoo dbb059f
[IMP] estate: add inline views, widgets, and order
jakan-odoo aee8aeb
[IMP] estate: add property maintenance requests
jakan-odoo 6dd7eec
[FIX] estate: improve maintenance cost validation
jakan-odoo ac29768
[IMP] estate: enhance views with UI improvements
jakan-odoo 54f03a6
[IMP] estate: apply python, model, and view inheritance
jakan-odoo cc37406
[ADD] estate: add translations, constraints, and UI updates
jakan-odoo 50ec57f
[IMP] estate_account: integrate estate with accounting
jakan-odoo 616598d
[IMP] estate: add investor profile and compute unsold value
jakan-odoo 5e71759
[IMP] estate: add kanban view and default grouping
jakan-odoo 9c162ab
[ADD] awesome_owl: add Owl component examples in playground
jakan-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 |
|---|---|---|
|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| i18n | ||
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
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,10 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component{ | ||
| static template = "awesome_owl.card"; | ||
|
|
||
| static props = { | ||
| title: String, | ||
| content: String, | ||
| }; | ||
| } |
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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.card"> | ||
| <div class="card d-inline-block m-2" style="width: 18rem;"> | ||
| <div class="card-body"> | ||
| <h5 class="card-title"><t t-esc="props.title"/></h5> | ||
| <p class="card-text"><t t-out="props.content"/></p> | ||
| </div> | ||
| </div> | ||
| </t> | ||
| </templates> |
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 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Counter extends Component { | ||
| static template = "awesome_owl.counter"; | ||
|
|
||
| setup() { | ||
| this.state = useState({ value: 0 }); | ||
| } | ||
|
|
||
| increment() { | ||
| this.state.value++; | ||
| } | ||
| } |
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,9 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.counter"> | ||
| <div class="border d-inline-block p-2 mt-2"> | ||
| Counter: <t t-esc="state.value"/> | ||
| <button class="btn btn-primary m-2" t-on-click="increment">Increment</button> | ||
| </div> | ||
| </t> | ||
| </templates> |
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 |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { Component, markup } from "@odoo/owl"; | ||
| import { Counter } from "./counter/counter"; | ||
| import { Card } from "./card/card"; | ||
|
|
||
| export class Playground extends Component { | ||
| static template = "awesome_owl.playground"; | ||
| static components = { Counter, Card }; | ||
|
|
||
| setup() { | ||
| this.htmlContent = markup("<div class='text-primary'>some content</div>"); | ||
| this.rawString = "<div class='text-primary'>some content</div>"; | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.playground"> | ||
| <div class="p-3"> | ||
| hello world | ||
| <Counter/> | ||
| <div class="d-flex flex-wrap"> | ||
| <Card title="'Card 1'" content="htmlContent"/> | ||
| <Card title="'Card 2'" content="rawString"/> | ||
| </div> | ||
| </div> | ||
| </t> | ||
|
|
||
| </templates> |
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,23 @@ | ||
| { | ||
| 'name': "Real Estate", | ||
| 'version': "1.0", | ||
| 'category': "Real Estate", | ||
| 'summary': "Manage real estate properties", | ||
| 'description': "This module allows managing properties", | ||
| 'depends': ['base'], | ||
| 'author': "jakan", | ||
| 'license': "LGPL-3", | ||
| 'application': True, | ||
| 'installable': True, | ||
| 'data': [ | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_property_maintenance_views.xml", | ||
| "views/estate_property_investor_views.xml", | ||
| 'views/res_users_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,7 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_property_maintenance | ||
| from . import estate_property_investor | ||
| from . import res_users |
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,145 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
| from odoo import _ | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Real Estate Property' | ||
| _order = 'id desc' | ||
|
|
||
| # Each field becomes a column in PostgreSQL table | ||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| default=lambda self: fields.Date.today() + relativedelta(months=3), | ||
| copy=False | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float( | ||
| readonly=True, | ||
| copy=False | ||
| ) | ||
| 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( | ||
| string="Direction", | ||
| selection=[ | ||
| ('north', "North"), | ||
| ('south', "South"), | ||
| ('east', "East"), | ||
| ('west', "West")]) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| [ | ||
| ('new', "New"), | ||
| ('offer_received', "Offer Received"), | ||
| ('offer_accepted', "Offer Accepted"), | ||
| ('sold', "Sold"), | ||
| ('cancelled', "Cancelled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| seller_id = fields.Many2one("res.users", string="Seller", default=lambda self: self.env.user) | ||
| tag_ids = fields.Many2many("estate.property.tag", string="Property Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Property Offers") | ||
| total_area = fields.Float(string="Total Area", compute="_compute_total_area", store=True) | ||
| best_price = fields.Float(string="Best Offer", compute="_compute_best_price") | ||
| maintenance_ids = fields.One2many("estate.property.maintenance", "property_id") | ||
| total_cost = fields.Float(string="Total Cost", compute="_compute_total_cost") | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'Expected price must be strictly positive.', | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price > 0)', | ||
| 'Selling price must be positive.', | ||
| ) | ||
|
|
||
| @api.depends('living_area', 'garden_area') | ||
| def _compute_total_area(self): | ||
| for property in self: | ||
| property.total_area = property.living_area + property.garden_area | ||
|
|
||
| @api.depends('offer_ids.price') | ||
| def _compute_best_price(self): | ||
| for property in self: | ||
| if property.offer_ids: | ||
| property.best_price = max(property.offer_ids.mapped('price')) | ||
| else: | ||
| property.best_price = 0 | ||
|
|
||
| @api.depends('maintenance_ids.cost') | ||
| def _compute_total_cost(self): | ||
| for maintenance in self: | ||
| maintenance.total_cost = sum(maintenance.maintenance_ids.mapped('cost')) | ||
|
|
||
| @api.constrains('expected_price', 'selling_price') | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| if float_is_zero(property.selling_price, precision_digits=2): | ||
| continue | ||
|
|
||
| minimum_price = property.expected_price * 0.9 | ||
|
|
||
| if float_compare(property.selling_price, minimum_price, precision_digits=2) < 0: | ||
| raise ValidationError("Selling price cannot be lower than 90% of the expected price.") | ||
|
|
||
| @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 _check_property_deletion(self): | ||
| for property in self: | ||
| if property.state not in ('new', 'cancelled'): | ||
| raise UserError("You can only delete properties in New or Cancelled state") | ||
|
|
||
| def action_sold(self): | ||
| for property in self: | ||
| if property.state == 'cancelled': | ||
| raise UserError(_("Sold property cannot be cancelled")) | ||
| if not property.buyer_id: | ||
| raise UserError(_("Without accept any offer we can't sold it")) | ||
| if property.maintenance_ids: | ||
| for maintenance in property.maintenance_ids: | ||
| if maintenance.status in ('new', 'cancle'): | ||
| raise UserError(_("Maintenance cost must be Approved or Done")) | ||
| property.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for property in self: | ||
| if property.state == 'sold': | ||
| raise UserError("Cancelled property cannot be sold") | ||
| property.state = 'cancelled' | ||
| return True | ||
|
|
||
| def offer_accepted(self): | ||
| for record in self: | ||
| if not record.offer_ids: | ||
| raise UserError("There are no offers to accept") | ||
|
|
||
| best_offer = max(record.offer_ids, key=lambda p:p.price) | ||
| best_offer.action_accept() | ||
|
|
||
| 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,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyInvestor(models.Model): | ||
| _name = 'estate.property.investor' | ||
| _description = 'Property Investor' | ||
| _inherits = {'res.partner': 'partner_id'} | ||
|
|
||
| partner_id = fields.Many2one('res.partner', required=True, ondelete='cascade') |
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 @@ | ||
| from odoo import fields, models | ||
| from odoo.exceptions import UserError | ||
| from odoo.tools.float_utils import float_is_zero | ||
|
|
||
|
|
||
| class EstatePropertyMaintenance(models.Model): | ||
| _name = 'estate.property.maintenance' | ||
| _description = 'Estate Property maintenance' | ||
|
|
||
| title = fields.Char(required=True) | ||
| cost = fields.Float(string="Cost") | ||
| status = fields.Selection( | ||
| [ | ||
| ('new', "New"), | ||
| ('approved', "Approved"), | ||
| ('done', "Done"), | ||
| ('cancle', "Cancle") | ||
| ], | ||
| required=True, | ||
| default="new", | ||
| ) | ||
|
|
||
| property_id = fields.Many2one('estate.property', required=True) | ||
|
|
||
| def maintenance_accept(self): | ||
| for maintenance in self: | ||
| if float_is_zero(maintenance.cost, precision_digits=2): | ||
| raise UserError("Maintenance cost must be greater than zero") | ||
|
|
||
| maintenance.status = "approved" | ||
| return True | ||
|
|
||
| def maintenance_refuse(self): | ||
| for maintenance in self: | ||
| maintenance.status = "cancle" | ||
| return True |
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.
Uh oh!
There was an error while loading. Please reload this page.