-
Notifications
You must be signed in to change notification settings - Fork 2.3k
leol - Technical Training #724
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
leclerc-leo
wants to merge
17
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-leol
base: 18.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
17 commits
Select commit
Hold shift + click to select a range
d135332
[ADD] Chapter 2: A New Application
leclerc-leo 26444e0
[IMP] Chapter 3: Models And Basic Fields
leclerc-leo a0927fe
[IMP] Chapter 4: Security - A Brief Introduction
leclerc-leo 636c48f
[IMP] Chapter 5: Finally, Some UI To Play With
leclerc-leo 71cbb29
[IMP] Chapter 6: Basic Views
leclerc-leo 80ed9c6
[IMP] Chapter 7: Relations Between Models
leclerc-leo 6d62204
[REF] refactor _names for the models and split the views in multiples…
leclerc-leo b5ec785
[IMP] Chapter 8: Computed Fields And Onchanges
leclerc-leo 6bb0af7
[IMP] Chapter 9: Ready For Some Action?
leclerc-leo 7dbc038
[IMP] Chapter 10: Constraints
leclerc-leo ad7a4e5
[IMP] estate: Chapter 11: Add The Sprinkles
leclerc-leo 633af64
[FIX] estate: reorder manifest to prevent crash when installing due t…
leclerc-leo 432bfd6
[IMP] estate: Chapter 12: Inheritance
leclerc-leo 3a34a97
[IMP] estate,estate_account: Chapter 13: Interact With Other Modules
leclerc-leo 9589b31
[IMP] estate: Chapter 14: A Brief History Of QWeb
leclerc-leo ad217c7
[FIX] estate,estate_ccount: fixes following second review
leclerc-leo 001dce8
[IMP] awesome_owl: Chapter 1: Owl components
leclerc-leo 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,19 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Card extends Component { | ||
static template = "awesome_owl.card"; | ||
|
||
static props = { | ||
title: { type: String }, | ||
slots: { type: Object, optional: true }, | ||
// content: { type: String }, removed following 13. Generic Card with slots | ||
}; | ||
|
||
setup() { | ||
this.state = useState({ opened: true }); | ||
} | ||
|
||
toggleOpened() { | ||
this.state.opened = !this.state.opened; | ||
} | ||
} |
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 @@ | ||
<?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"> | ||
<p><t t-esc="props.title" /></p> | ||
<button t-on-click="toggleOpened">Toggle</button> | ||
</h5> | ||
<p class="card-text" t-if="state.opened"> | ||
<!-- <t t-out="props.content" removed following 13. Generic Card with slots/> --> | ||
<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: 0 }); | ||
} | ||
|
||
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.counter"> | ||
<div class="card d-inline-block m-2" style="width: 18rem;"> | ||
<div class="card-body"> | ||
<p>Counter: <t t-esc="state.value" /></p> | ||
<button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
</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 |
---|---|---|
@@ -1,7 +1,23 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { Component, markup, useState } from "@odoo/owl"; | ||
import { Card } from "./card/card"; | ||
import { Counter } from "./counter/counter"; | ||
import { TodoList } from "./todolist/todolist"; | ||
|
||
export class Playground extends Component { | ||
static components = { Counter, Card, TodoList }; | ||
|
||
static template = "awesome_owl.playground"; | ||
|
||
static props = {}; | ||
|
||
html1 = '<div style="background-color: red">some content</div>'; | ||
html2 = markup('<div style="background-color: red">some content</div>'); | ||
|
||
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
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,25 @@ | ||
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, | ||
}, | ||
}, | ||
removeTodo: { type: Function }, | ||
}; | ||
|
||
toggleState(ev) { | ||
if (!ev.target) { | ||
return; | ||
} | ||
|
||
this.props.todo.isCompleted = ev.target.checked; | ||
} | ||
} |
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.todoitem"> | ||
<input | ||
type="checkbox" | ||
t-att-checked="props.todo.isCompleted" | ||
t-on-change="toggleState" | ||
style="display: inline-block; margin-right: 5px;" /> | ||
<div | ||
t-att-class="{ | ||
'text-decoration-line-through' : props.todo.isCompleted, | ||
'text-muted': props.todo.isCompleted, | ||
}" | ||
style="display: inline-block;" > | ||
<t t-esc="props.todo.id" />. <t t-esc="props.todo.description" /> | ||
</div> | ||
<span | ||
class="fa fa-remove" | ||
t-on-click="() => props.removeTodo(props.todo.id)" | ||
style="display: inline-block; margin-left: 5px; color: red;" /> | ||
</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,55 @@ | ||
import { Component, useRef, useState } from "@odoo/owl"; | ||
import { useAutofocus } from "../utils"; | ||
import { TodoItem } from "./todoitem"; | ||
|
||
export class TodoList extends Component { | ||
static components = { TodoItem }; | ||
|
||
static template = "awesome_owl.todolist"; | ||
|
||
static props = {}; | ||
|
||
setup() { | ||
this.id = 1; // could be calculated every iteration but would get very slow with a lot of todos | ||
this.todos = useState([ | ||
// removed following 9. Adding a todo | ||
// { id: 2, description: "write tutorial", isCompleted: true }, | ||
// { id: 3, description: "buy milk", isCompleted: false }, | ||
]); | ||
this.inputRef = useRef("addTask"); | ||
useAutofocus("addTask"); | ||
} | ||
|
||
addTodo(ev) { | ||
if (ev.keyCode != 13 || !this.inputRef.el) { | ||
return; | ||
} | ||
|
||
const desc = this.inputRef.el.value; | ||
|
||
if (desc === "") { | ||
return; | ||
} | ||
|
||
this.todos.push({ | ||
id: this.id, | ||
description: desc, | ||
isCompleted: false, | ||
}); | ||
|
||
this.inputRef.el.value = ""; | ||
this.id++; | ||
} | ||
|
||
removeTodo(elemId) { | ||
if (elemId < 0 || elemId >= this.id) { | ||
return; | ||
} | ||
|
||
const index = this.todos.findIndex((elem) => elem.id === elemId); | ||
if (index >= 0) { | ||
// remove the element at index from list | ||
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.todolist"> | ||
<div class="card d-inline-block m-2" style="width: 18rem;"> | ||
<div class="card-body"> | ||
<input type="text" class="" placeholder="Enter a new task" t-on-keyup="addTodo" t-ref="addTask"/> | ||
<div t-foreach="todos" t-as="todo" t-key="todo.id" style="margin: 2px;"> | ||
<TodoItem todo="todo" removeTodo.bind="removeTodo" /> | ||
</div> | ||
</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,9 @@ | ||
import { useEffect, useRef } from "@odoo/owl"; | ||
|
||
export function useAutofocus(name) { | ||
const ref = useRef(name); | ||
useEffect( | ||
(el) => el && el.focus(), | ||
() => [ref.el], | ||
); | ||
} |
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,26 @@ | ||
{ | ||
'name': 'Real Estate', | ||
'summary': """ | ||
Starting module for "Server framework 101" | ||
""", | ||
'description': """ | ||
Starting module for "Server framework 101" | ||
""", | ||
'author': 'Odoo', | ||
'website': 'https://www.odoo.com', | ||
'license': 'LGPL-3', | ||
'category': 'Tutorials/Real Estate', | ||
'version': '0.1', | ||
'application': True, | ||
'installable': True, | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/estate_property_views.xml', | ||
'views/estate_property_tag_views.xml', | ||
'views/estate_property_offer_views.xml', | ||
'views/estate_property_type_views.xml', | ||
'views/estate_menus.xml', | ||
'views/res_users_views.xml', | ||
], | ||
'depends': ['base'], | ||
} |
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,104 @@ | ||
from dateutil import relativedelta | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tools import float_utils | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = 'estate.property' | ||
_description = 'Estate property' | ||
_order = 'id desc' | ||
|
||
name = fields.Char(string='Name of the Property', required=True) | ||
description = fields.Text(string='Description') | ||
postcode = fields.Char(string='Postcode') | ||
date_availability = fields.Date( | ||
string='Available From', | ||
copy=False, | ||
default=fields.Date.today() + relativedelta.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='Number 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=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], | ||
) | ||
active = fields.Boolean(default=True) | ||
state = fields.Selection( | ||
string='State', | ||
selection=[ | ||
('new', 'New'), | ||
('received', 'Offer Received'), | ||
('accepted', 'Offer Accepted'), | ||
('sold', 'Sold'), | ||
('cancelled', 'Cancelled'), | ||
], | ||
required=True, | ||
copy=False, | ||
default='new', | ||
) | ||
property_type_id = fields.Many2one('estate.property.type', string='Property Type') | ||
users_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user) | ||
partner_id = fields.Many2one('res.partner', string='Buyer', readonly=True) | ||
tag_ids = fields.Many2many('estate.property.tag', string='Property 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_price = fields.Float(string='Best Offer', compute='_compute_price') | ||
|
||
_sql_constraints = [ | ||
('check_expected_price', 'CHECK(expected_price > 0)', 'The expected price must strictly be positive.'), | ||
('check_selling_price', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'), | ||
] | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def prevent_delete_based_on_state(self): | ||
if any(record.state in {'new', 'cancelled'} for record in self): | ||
raise UserError(_('A new or cancelled property cannot be deleted.')) | ||
|
||
@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_price(self): | ||
for record in self: | ||
record.write({'best_price': max(record.offer_ids.mapped('price'), default=0)}) | ||
|
||
@api.onchange('garden') | ||
def _onchange_garden(self): | ||
if not self.garden: | ||
self.write({'garden_orientation': False, 'garden_area': 0}) | ||
return | ||
|
||
self.write({'garden_area': 10, 'garden_orientation': self.garden_orientation or 'north'}) | ||
|
||
def action_sell(self): | ||
if 'cancelled' in self.mapped('state'): | ||
raise UserError(_('A property cancelled cannot be set as sold.')) | ||
|
||
self.write({'state': 'sold'}) | ||
return True | ||
|
||
def action_cancel(self): | ||
if 'sold' in self.mapped('state'): | ||
raise UserError(_('A property sold cannot be set as cancelled.')) | ||
|
||
self.write({'state': 'cancelled'}) | ||
return True | ||
|
||
@api.constrains('selling_price') | ||
def _check_price(self): | ||
for record in self: | ||
if not record.selling_price: | ||
continue | ||
|
||
if float_utils.float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=3) == -1: | ||
leclerc-leo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValidationError(_('The selling cannot be lower than 90% of the expected price.')) |
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.