-
Notifications
You must be signed in to change notification settings - Fork 2.9k
ahham - Technical Training Estate module #1171
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
ahmedhamila
wants to merge
14
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-training-ahham
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
14 commits
Select commit
Hold shift + click to select a range
2be8a14
[ADD] estate: add estate property module declaration
4d165da
[IMP] estate: add estate_property model
426e4bc
[IMP] estate: add access control to estate_property model
f0f5d26
[IMP] estate: add menus and action for estate_property
f37f977
[IMP] estate: add list,form and search custom views for estate_property
332eef4
[IMP] estate: add property type,tag and offers and defined their rela…
02cf3dc
[IMP] estate: add computed fields and set onchange method
3245306
[IMP] estate: add actions for property offers and property state
60becd9
[IMP] estate: add sql and python constraints to estate models
ef6a1a9
[IMP] estate: add inline editing, widgets and stat_button
6f34f69
[IMP] estate: override CRUD methods and extend user model to have pro…
5510c98
[ADD] estate_account: override sold action to create invoice for buyer
d4b9b47
[IMP] estate: add kanban view for estate_property
8bfdeb3
[IMP] Discover the javascript framework chapter
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
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 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.Card"; | ||
| static props = { | ||
| title: String, | ||
| slots: Object, | ||
ahmedhamila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| setup() { | ||
| this.state = useState({ isOpen: true }); | ||
| } | ||
| toggleOpen() { | ||
| 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,14 @@ | ||
| <?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-out="props.title"/> | ||
| <button t-on-click="toggleOpen" class="btn">Toggle</button> | ||
| </h5> | ||
| <t t-slot="default" t-if="this.state.isOpen"/> | ||
| </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: 0 }); | ||
| } | ||
|
|
||
| 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,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.Counter"> | ||
| <div class="d-flex gap-2 border border-dark align-items-center p-2"> | ||
| <span>Counter: <t t-out="state.value"/> | ||
| </span> | ||
| <button t-on-click="increment" class="btn btn-primary">Increment</button> | ||
| </div> | ||
| </t> | ||
|
|
||
| </templates> |
17 changes: 17 additions & 0 deletions
17
awesome_owl/static/src/components/todoo/todo_item/todo_item.js
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 @@ | ||
| 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, | ||
| }; | ||
| } |
13 changes: 13 additions & 0 deletions
13
awesome_owl/static/src/components/todoo/todo_item/todo_item.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,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.TodoItem"> | ||
| <div class="d-flex align-items-center gap-2"> | ||
| <input type="checkbox" t-on-change="props.toggleState"/> | ||
| <t t-out="props.todo.id"/> | ||
| . <span t-att-class="{'text-decoration-line-through text-muted':props.todo.isCompleted}"> | ||
| <t t-out="props.todo.description" /> | ||
| </span> | ||
| <span role="button" class="fa fa-remove ms-3 text-danger" t-on-click="props.removeTodo"/> | ||
| </div> | ||
| </t> | ||
| </templates> |
36 changes: 36 additions & 0 deletions
36
awesome_owl/static/src/components/todoo/todo_list/todo_list.js
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 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
| import { TodoItem } from "../todo_item/todo_item"; | ||
| import { useAutofocus } from "../../../utils"; | ||
| export class TodoList extends Component { | ||
| static template = "awesome_owl.TodoList"; | ||
| static components = { TodoItem }; | ||
| setup() { | ||
| this.todos = useState([]); | ||
| useAutofocus("todo_input"); | ||
| } | ||
| addTodo(event) { | ||
| if (event.keyCode === 13 && event.target.value.length) { | ||
| this.todos.push({ | ||
| id: this.todos.length | ||
| ? this.todos[this.todos.length - 1].id + 1 | ||
| : 1, | ||
ahmedhamila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description: event.target.value, | ||
| isCompleted: false, | ||
| }); | ||
| event.target.value = ""; | ||
| } | ||
| } | ||
| toggleState(id) { | ||
| const todo = this.todos.find((todo) => todo.id === id); | ||
| if (todo) { | ||
| todo.isCompleted = !todo.isCompleted; | ||
| } | ||
| } | ||
|
|
||
| removeTodo(id) { | ||
| const index = this.todos.findIndex((todo) => todo.id === id); | ||
| if (index !== -1) { | ||
| this.todos.splice(index, 1); | ||
| } | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
awesome_owl/static/src/components/todoo/todo_list/todo_list.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,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.TodoList"> | ||
| <div class="d-flex flex-column"> | ||
| <input placeholder="Add a todo" t-on-keyup="addTodo" t-ref="todo_input"/> | ||
| <t t-foreach="this.todos" t-as="todo" t-key="todo.id"> | ||
| <TodoItem todo="todo" toggleState.bind="()=>this.toggleState(todo.id)" removeTodo.bind="()=>this.removeTodo(todo.id)"/> | ||
| </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 |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| import { Component, useState } from "@odoo/owl"; | ||
| import { Counter } from "./components/counter/counter"; | ||
| import { Card } from "./components/card/card"; | ||
| import { TodoList } from "./components/todoo/todo_list/todo_list"; | ||
| export class Playground extends Component { | ||
| static template = "awesome_owl.playground"; | ||
| static template = "awesome_owl.Playground"; | ||
| static components = { Counter, Card, TodoList }; | ||
|
|
||
| setup() { | ||
| this.sum = useState({ value: 0 }); | ||
| } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,28 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.playground"> | ||
| <t t-name="awesome_owl.Playground"> | ||
| <div class="d-flex gap-2"> | ||
| <div class="p-3"> | ||
| hello world | ||
| </div> | ||
| <Counter onChange.bind="incrementSum"/> | ||
| <Counter onChange.bind="incrementSum"/> | ||
|
|
||
| </div> | ||
| <div class="p-3"> | ||
| hello world | ||
| Sum: <t t-out="this.sum.value"/> | ||
| </div> | ||
| <div class="d-flex gap-4"> | ||
| <Card title="'Card 1'"> | ||
| Card 1 content | ||
| </Card> | ||
| <Card title="'Card 2'"> | ||
| <Counter /> | ||
| </Card> | ||
| </div> | ||
| <h1>Todo List</h1> | ||
| <TodoList/> | ||
| </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,7 @@ | ||
| import { useRef, onMounted } from "@odoo/owl"; | ||
| export const useAutofocus = (ref) => { | ||
| const inputRef = useRef(ref); | ||
| onMounted(() => { | ||
| inputRef.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': '0.0', | ||
| 'summary': 'Real Estate Management', | ||
| 'depends': [ | ||
| 'base', | ||
| ], | ||
| '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_menus.xml', | ||
| 'views/res_users_views.xml' | ||
| ], | ||
| 'application': True, | ||
| 'author': 'Odoo S.A.', | ||
| '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 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,117 @@ | ||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.date_utils import relativedelta | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| GARDEN_ORIENTATION = [("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")] | ||
| PROPERTY_STATE = [("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")] | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Private attributes | ||
| # ------------------------------------------------------------------------- | ||
| _name = "estate.property" | ||
| _description = "Real Estate Property" | ||
| _order = "id desc" | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Field declarations | ||
| # ------------------------------------------------------------------------- | ||
| name = fields.Char(string="Title", required=True) | ||
| description = fields.Text(string="Description") | ||
ahmedhamila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| postcode = fields.Char(string="Postcode") | ||
| date_availability = fields.Date(string="Date Availability", copy=False, default=lambda self: fields.Date.context_today(self) + relativedelta(months=3)) | ||
| expected_price = fields.Float(string="Expected Price", required=True) | ||
| selling_price = fields.Float(string="Selling Price", readonly=True, copy=False) | ||
| bedrooms = fields.Integer(string="Bedrooms", default=2) | ||
| living_area = fields.Integer(string="Living Area (sqm)") | ||
| facades = fields.Integer(string="Facades") | ||
| garage = fields.Boolean(string="Garage") | ||
| garden = fields.Boolean(string="Garden") | ||
| garden_area = fields.Integer(string="Garden Area (sqm)") | ||
| garden_orientation = fields.Selection(string="Garden Orientation", selection=GARDEN_ORIENTATION) | ||
| active = fields.Boolean(string="Active", default=True) | ||
| state = fields.Selection(string="Status", selection=PROPERTY_STATE, 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") | ||
| salesman_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) | ||
| property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
|
|
||
| total_area = fields.Integer(string="Total Area (sqm)", compute="_compute_total_area") | ||
| best_offer = fields.Float(string="Best Offer", compute="_compute_best_offer") | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # SQL constraints | ||
| # ------------------------------------------------------------------------- | ||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| "The expected price must be strictly positive." | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| "The selling price must be positive." | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Compute methods | ||
| # ------------------------------------------------------------------------- | ||
| @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_offer(self): | ||
| for property in self: | ||
| property.best_offer = max(property.offer_ids.mapped("price"), default=0) | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Constraints and onchange methods | ||
| # ------------------------------------------------------------------------- | ||
| @api.constrains("selling_price") | ||
| def _check_selling_price_minimum_ratio(self): | ||
| for property in self: | ||
| if float_is_zero(property.selling_price, precision_digits=2): | ||
| continue | ||
| if float_compare(property.selling_price, property.expected_price * 0.9, precision_digits=2) < 0: | ||
| raise ValidationError("The selling price must be at least 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 | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # ORM methods | ||
| # ------------------------------------------------------------------------- | ||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_new_cancelled_property(self): | ||
| for property in self: | ||
| if property.state not in ["new", "cancelled"]: | ||
| raise UserError("Only new and canceled properties can be deleted") | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Action methods | ||
| # ------------------------------------------------------------------------- | ||
| def action_cancel_property(self): | ||
| for property in self: | ||
| if property.state == "sold": | ||
| raise UserError("Sold properties cannot be cancelled") | ||
| property.state = "cancelled" | ||
| return True | ||
|
|
||
| def action_sold_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| raise UserError("Cancelled properties cannot be sold") | ||
| property.state = "sold" | ||
| 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.