-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: create real estate module #1080
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
gicha-odoo
wants to merge
1
commit into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-Technical_Training-gicha
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
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from . import controllers | ||
| from . import controllers |
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 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.card"; | ||
| static props = { | ||
| title: String, | ||
| slots: { | ||
| type: Object, | ||
| shape: { | ||
| default: true | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.state = useState({ isOpen: true }); | ||
| } | ||
|
|
||
| toggleContent() { | ||
| this.state.isOpen = !this.state.isOpen; | ||
| } | ||
| } |
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 @@ | ||
| <?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"/> | ||
| <button class="btn btn-primary" t-on-click="toggleContent">Toggle</button> | ||
| </h5> | ||
| <p class="card-text" t-if="state.isOpen"> | ||
| <t t-slot="default"/> | ||
| </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,19 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Counter extends Component { | ||
| static template = "awesome_owl.counter"; | ||
| static props = { | ||
| onChange: { type: Function, optional: true } | ||
| }; | ||
|
|
||
| setup() { | ||
| this.state = useState({ value: 1 }); | ||
| } | ||
|
|
||
| increment() { | ||
| this.state.value++; | ||
| if (this.props.onChange) { | ||
| this.props.onChange(); | ||
| } | ||
| } | ||
| } |
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="m-2 p-2 border d-inline-block"> | ||
| <span class="me-2">Counter: <t t-esc="state.value"/></span> | ||
| <button class="btn btn-primary" 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
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,19 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { markup, Component, useState } from "@odoo/owl"; | ||
| import { Counter } from "./counter/counter"; | ||
| import { Card } from "./card/card"; | ||
| import { TodoList } from "./todo_list/todo_list"; | ||
|
|
||
| export class Playground extends Component { | ||
| static template = "awesome_owl.playground"; | ||
| static components = { Counter, Card, TodoList }; | ||
|
|
||
| setup() { | ||
| this.str1 = "<div class='text-primary'>some content</div>"; | ||
| this.str2 = markup("<div class='text-primary'>some content</div>"); | ||
| this.sum = useState({value: 2}); | ||
| } | ||
|
|
||
| incrementSum() { | ||
| this.sum.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
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 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class TodoItem extends Component { | ||
| static template = "awesome_owl.TodoItem"; | ||
| static props = { | ||
| todo: { | ||
| type: Object, | ||
| shape: { id: Number, description: String, isCompleted: Boolean }, | ||
| }, | ||
| toggleState: Function, | ||
| removeTodo: Function, | ||
| }; | ||
|
|
||
| onChange() { | ||
| this.props.toggleState(this.props.todo.id); | ||
| } | ||
|
|
||
| onRemove() { | ||
| this.props.removeTodo(this.props.todo.id); | ||
| } | ||
| } |
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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.TodoItem"> | ||
| <div class="m-2 p-2"> | ||
| <input class="form-check-input m-2" type="checkbox" t-att-id="props.todo.id" t-att-checked="props.todo.isCompleted" t-on-change="onChange"/> | ||
| <label class="m-2" t-att-class="props.todo.isCompleted ? 'text-decoration-line-through text-muted' : '' "> | ||
| <t t-esc="props.todo.id"/>. | ||
| <t t-esc="props.todo.description"/> | ||
| </label> | ||
| <span class="fa fa-remove cursor-pointer" t-on-click="onRemove"/> | ||
| </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,39 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
| import { TodoItem } from "./todo_item"; | ||
| import { useAutoFocus } from "../utils"; | ||
|
|
||
| export class TodoList extends Component { | ||
| static template = "awesome_owl.TodoList"; | ||
| static components = { TodoItem }; | ||
|
|
||
| setup() { | ||
| this.nextId = 0; | ||
| this.todos = useState([]); | ||
| useAutoFocus("input"); | ||
| } | ||
|
|
||
| addTodo(ev) { | ||
| if (ev.keyCode == 13 && ev.target.value != ""){ | ||
| this.todos.push({ | ||
| id: this.nextId++, | ||
| description: ev.target.value, | ||
| isCompleted: false | ||
| }); | ||
| ev.target.value = ""; | ||
| } | ||
| } | ||
|
|
||
| toggleTodo(todoId) { | ||
| const todo = this.todos.find((todo) => todo.id === todoId); | ||
| if (todo) { | ||
| todo.isCompleted = !todo.isCompleted; | ||
| } | ||
| } | ||
|
|
||
| removeTodo(todoId) { | ||
| const index = this.todos.findIndex((todo) => todo.id === todoId); | ||
| if (index >= 0) { | ||
| this.todos.splice(index, 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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.TodoList"> | ||
| <div class="d-inline-block border p-2 m-2"> | ||
| <input class="form-control mb-3" type="text" placeholder="Add a todo" t-on-keyup="addTodo" t-ref="input"/> | ||
| <t t-foreach="todos" t-as="todo" t-key="todo.id"> | ||
| <TodoItem todo="todo" toggleState.bind="toggleTodo" removeTodo.bind="removeTodo"/> | ||
| </t> | ||
| </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,8 @@ | ||
| import { useRef, onMounted } from "@odoo/owl"; | ||
|
|
||
| export function useAutoFocus(refName) { | ||
| const ref = useRef(refName); | ||
| onMounted(() => { | ||
| ref.el.focus(); | ||
| }); | ||
| } |
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,20 @@ | ||
| { | ||
| 'name': 'estate', | ||
| 'version': 1.0, | ||
| 'author': 'Odoo', | ||
| 'license': 'LGPL-3', | ||
| 'depends': [ | ||
| 'base', | ||
| ], | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_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,5 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| 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,120 @@ | ||
| 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 = 'Estate property' | ||
| _order = 'id desc' | ||
|
|
||
| name = fields.Char(required=True, string="Title") | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Datetime( | ||
| "Available From", copy=False, | ||
| default=lambda self: fields.Datetime.add(fields.Datetime.today(), months=3), | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
| 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"), | ||
| ], | ||
| ) | ||
| total_area = fields.Integer(compute="_compute_total_area", readonly=True) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| string="Status", | ||
| 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="Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", string="Salesperson", default=lambda self: self.env.uid, | ||
| ) | ||
| tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
|
|
||
| _check_positive_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "The expected price of a property must be strictly positive.", | ||
| ) | ||
|
|
||
| _check_positive_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", "The selling price of a property must be positive.", | ||
| ) | ||
|
|
||
| @api.constrains("selling_price") | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| if (float_compare(property.selling_price, (0.9 * property.expected_price), 2) == -1): | ||
| raise ValidationError(self.env._("The selling price must be at least 90% of the expected price. You may decrease the expected price if you want to accept this 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.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 = "" | ||
|
|
||
| def action_sold_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError(self.env._("Cancelled properties cannot be sold")) | ||
| property.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel_property(self): | ||
| for property in self: | ||
| if property.state == "sold": | ||
| raise UserError(self.env._("Sold properties cannot be cancelled")) | ||
| property.state = "cancelled" | ||
| return True | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _check_unlink(self): | ||
| for property in self: | ||
| if property.state != "new" and property.state != "cancelled": | ||
| raise UserError(self.env._("Only new and cancelled properties can be deleted!")) | ||
|
|
||
| @api.onchange("offer_ids") | ||
| def _onchange_offer_ids(self): | ||
| for property in self: | ||
| if len(property.offer_ids) == 0: | ||
| property.state = "new" | ||
| elif property.state != "offer_accepted": | ||
| property.state = "offer_received" |
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.