-
Notifications
You must be signed in to change notification settings - Fork 2.9k
CYMO - Technical training 19.0 #1172
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
MrRose765
wants to merge
14
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-training-cymo
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
14 commits
Select commit
Hold shift + click to select a range
18ca504
[ADD] estate: Create Real Estate module manifest
MrRose765 427542d
[IMP] estate: create estate_property model add basic fields. \n Chapt…
MrRose765 a1468e3
[IMP] estate: Create access rights for estate property.
MrRose765 cd2072a
[IMP] estate: Default menus and form view for estate properties.
MrRose765 808607a
[IMP] estate: Add list,form and search views for estate properties
MrRose765 36b521e
[IMP] estate: Add property types, tags and offers.
MrRose765 cce5435
[IMP] estate: Add total_area, best_price and validity date.
MrRose765 ad97a22
[IMP] estate: Add possibility to sold/cancel property and accept/refu…
MrRose765 140606d
[IMP] estate: Add constraints on prices and tag/property names.
MrRose765 b9b4573
[IMP] estate: add constraints and UI improvements
MrRose765 3b94c34
[IMP] estate: link users to properties and protect deletion
MrRose765 88da1d4
[ADD] estate_account: Add creation of invoice when a property is sold.
MrRose765 9231b81
[IMP] estate: Add kanban view for estate properties.
MrRose765 47e5510
[IMP] awesome_owl: Add counter and todolists components
MrRose765 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,18 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.Card"; | ||
| static props = { | ||
| title: { type: String, required: true }, | ||
| slots: Object, | ||
| } | ||
|
|
||
| setup() { | ||
| this.state = useState({isOpened: false}); | ||
| } | ||
|
|
||
| expand() { | ||
| this.state.isOpened = !this.state.isOpened; | ||
| } | ||
| } | ||
|
|
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 @@ | ||
| <?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 class="btn btn-primary" t-on-click="expand"> | ||
| <t t-if="state.isOpened">Collapse</t> | ||
| <t t-if="!state.isOpened">Expand</t> | ||
| </button> | ||
| </h5> | ||
| <p class="card-text" t-if="state.isOpened"> | ||
| <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,18 @@ | ||
| 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++; | ||
| 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,11 @@ | ||
| <?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-out="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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { Component, markup, 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.value1 = "<div class='text-danger'>Hello</div>"; | ||
| this.value2 = markup("<img src='x' onerror='alert(1)'/>"); | ||
| 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,22 @@ | ||
| 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, | ||
| }; | ||
|
|
||
| onChanged() { | ||
| this.props.toggleState(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,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.TodoItem"> | ||
| <div t-att-class="props.todo.isCompleted ? 'text-decoration-line-through' : ''"> | ||
| <input class="form-check-box" type="checkbox" t-att-checked="props.todo.isCompleted" t-on-change="onChanged"/> | ||
| <t t-out="props.todo.id"/>. | ||
| <t t-out="props.todo.description"/> | ||
| <span class="fa fa-remove" t-on-click="() => props.removeTodo(props.todo.id)"/> | ||
| </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.currId = 1; | ||
| this.todos = useState([]); | ||
| useAutoFocus("input_todo"); | ||
| } | ||
|
|
||
| addTodo(ev) { | ||
| if (ev.keyCode === 13 && ev.target.value !== "") { | ||
| this.todos.push({ | ||
| id: this.currId++, | ||
| description: ev.target.value, | ||
| isCompleted: false | ||
| }); | ||
| ev.target.value = ""; | ||
| } | ||
| } | ||
|
|
||
| toggleTodo(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 >= 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,12 @@ | ||
| <?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_todo"/> | ||
| <p t-if="todos.length === 0">No todos yet !</p> | ||
| <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 {onMounted, useRef} 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': 'Real Estate', | ||
| 'author': 'Odoo S.A.', | ||
| 'license': 'LGPL-3', | ||
| '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/res_users_views.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'auto_install': False, | ||
| } | ||
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_offer | ||
| from . import estate_property_tag | ||
| from . import estate_property_type | ||
| 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,98 @@ | ||
| 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 | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Handle real estate property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(string='Title', required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char(string='Postcode') | ||
MrRose765 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| date_availability = fields.Date(string='Available From', copy=False, default=fields.Date.today() + relativedelta(months=3)) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| 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( | ||
| selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| string='Status', | ||
| selection=[('new', 'New'), ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')], | ||
| required=True, | ||
| copy=False, | ||
| default='new', | ||
| ) | ||
|
|
||
| property_type_id = fields.Many2one('estate.property.type') | ||
| buyer_id = fields.Many2one('res.partner', copy=False) | ||
| salesman_id = fields.Many2one('res.users', default=lambda self: self.env.user) | ||
| tag_ids = fields.Many2many('estate.property.tag') | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id') | ||
|
|
||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Float(string='Best Offer', compute="_compute_best_price") | ||
|
|
||
| _expected_price_gt_zero = models.Constraint( | ||
| 'CHECK(expected_price > 0)', 'A property expected price must be strictly positive', | ||
| ) | ||
| _selling_price_gt_zero = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', 'A property 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: | ||
| property.best_price = max(property.offer_ids.mapped('price'), default=0) | ||
|
|
||
| @api.onchange('garden') | ||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = 'north' | ||
| else: | ||
| self.garden_area = False | ||
| self.garden_orientation = False | ||
|
|
||
| @api.constrains('expected_price', 'selling_price') | ||
| def _check_selling_price(self): | ||
| precision = 2 | ||
| for record in self: | ||
| if not float_is_zero(record.selling_price, precision_digits=precision) and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=precision) < 0: | ||
| raise ValidationError(_('The selling price cannot be lower than 90% of the expected price')) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| for record in self: | ||
| if record.state not in ['new', 'canceled']: | ||
| raise UserError(_("You cannot delete a property that is not new or cancelled.")) | ||
|
|
||
| def action_set_sold(self): | ||
| for record in self: | ||
| if record.state == 'canceled': | ||
| raise UserError(_("Canceled properties can't be sold.")) | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError(_("Canceled properties can't be canceled.")) | ||
| record.state = 'canceled' | ||
| 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.