Skip to content
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

romc - Technical Training #208

Open
wants to merge 25 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d98b856
[ADD] estate: start new module for training
romaincarlier4 Dec 16, 2024
6123ef7
[IMP] add fields for real estate table
romaincarlier4 Dec 16, 2024
7d89dad
[IMP] estate: add security access rules
romaincarlier4 Dec 16, 2024
42bf41b
[IMP] estate: add views and menu
romaincarlier4 Dec 16, 2024
973bf38
[IMP] estate: add list, form and search views
romaincarlier4 Dec 17, 2024
720e52a
[IMP] estate: relations between models
romaincarlier4 Dec 18, 2024
eb9b85a
[IMP] estate: add compute and onchange fields
romaincarlier4 Dec 18, 2024
66a5c8d
[IMP] estate: add sold/cancel and accept/refuse buttons
romaincarlier4 Dec 18, 2024
2120538
[FIX] estate: fix bug for accepting offers
romaincarlier4 Dec 18, 2024
99ca07a
[IMP] estate: coding guidelines improvements
romaincarlier4 Dec 18, 2024
4f294be
[IMP] estate: add SQL and python constraints
romaincarlier4 Dec 18, 2024
b0417e3
[IMP] estate: add the sprinkles ✨
romaincarlier4 Dec 19, 2024
63f631c
[IMP] estate: add inheritance
romaincarlier4 Dec 20, 2024
9c873c0
[IMP] estate: refactor code
romaincarlier4 Dec 20, 2024
d6db194
[IMP] estate: link sold properties to invoices
romaincarlier4 Dec 20, 2024
c745b80
[IMP] estate: add kanban view
romaincarlier4 Dec 20, 2024
b22d5d9
[FIX] estate: fix kanban warning
romaincarlier4 Dec 20, 2024
977f427
[IMP] estate: refactor code
romaincarlier4 Dec 20, 2024
dbcf657
[ADD] awesome owl: chapter 1
romaincarlier4 Dec 23, 2024
f1c5751
[IMP] estate: add tests
romaincarlier4 Dec 23, 2024
6704364
[ADD] awesome dashboard: chapter 2
romaincarlier4 Dec 26, 2024
2e5e8f1
[IMP] awesome owl: refactor code
romaincarlier4 Dec 26, 2024
ccfc291
[IMP] estate: follow coding guidelines
romaincarlier4 Dec 26, 2024
e34aacb
[IMP] estate: add demo data
romaincarlier4 Dec 26, 2024
488345e
[FIX] estate: fix demo data
romaincarlier4 Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.Card";
static props = {
title: { type: String },
slots: { type: Object }
};

setup() {
this.state = useState({ hidden: false });
}

toggle() {
this.state.hidden = !this.state.hidden;
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/card/card.xml
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-esc="props.title"/>
<button class="btn btn-primary" t-on-click="toggle">Toggle</button>
</h5>
<t t-slot="default" t-if="!state.hidden"/>
</div>
</div>
</t>
</templates>
23 changes: 23 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @odoo-module **/

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is surprising that this props may not exists. The best approach would be to figure out why it is not provided sometime, fix the issue and remove this if check.
If it is inevitable, here is an alternative syntax that you may (or not) want to use

Suggested change
if (this.props.onChange) {
this.props.onChange();
this.props.onChange?.();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what is expected. The counter component can optionnally have a callback prop, but can also very well be a simple counter with no callback needed. I changed with the better '?' syntax.

}
};
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
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>
<p>Counter:
<t t-esc="state.value"/>
</p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>
</templates>
18 changes: 17 additions & 1 deletion awesome_owl/static/src/playground.js
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 { Counter } from "./counter/counter"
import { Card } from "./card/card"
import { TodoList } from "./todolist/todolist";

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = { Counter, Card, TodoList };
html = "<b>This is bold</b>";
html_markup = markup("<b>This is bold</b>");

setup() {
this.state = useState({
sum: 0
});
};

incrementSum() {
this.state.sum++;
}
}
25 changes: 21 additions & 4 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<div style="margin: 20px;">
<div>
<h1>Counters</h1>
<div style="display: flex;">
<Counter onChange.bind="incrementSum"/>
<Counter onChange.bind="incrementSum"/>
</div>
<p> The sum is
<t t-esc="state.sum"/>
</p>
</div>
<div>
<h1>Cards</h1>
<Card title="'Embedded counter'">
<Counter onChange.bind="incrementSum"/>
</Card>
</div>
<div>
<h1>Todo list</h1>
<TodoList/>
</div>
</div>
</t>

</templates>
22 changes: 22 additions & 0 deletions awesome_owl/static/src/todolist/todoitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";

export class TodoItem extends Component {
static template = "awesome_owl.TodoItem";
static props = {
id: { type: Number },
description: { type: String },
isCompleted: { type: Boolean },
toggleState: { Function },
removeTodo: { Function }
};

toggleState() {
this.props.toggleState(this.props.id);
}

removeTodo() {
this.props.removeTodo(this.props.id);
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todolist/todoitem.xml
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="{'text-muted text-decoration-line-through': props.isCompleted}">
<input type="checkbox" t-att-checked="props.isCompleted" t-on-change="toggleState"/>
<t t-esc="props.id"/>.
<t t-esc="props.description"/>
<span class="fa fa-remove" t-on-click="removeTodo" style="margin-left: 5px"/>
</div>
</t>
</templates>
50 changes: 50 additions & 0 deletions awesome_owl/static/src/todolist/todolist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";
import { TodoItem } from "./todoitem";
import { useAutofocus } from "../utils";

export class TodoList extends Component {
static template = "awesome_owl.TodoList";
static components = { TodoItem }

setup() {
this.todos = useState([
{ id: 0, description: "Buy house", isCompleted: true },
{ id: 1, description: "Buy milk", isCompleted: false },
{ id: 2, description: "Buy chocolate", isCompleted: true },
{ id: 3, description: "Clean house", isCompleted: false },
{ id: 4, description: "Pay bills", isCompleted: false },
{ id: 5, description: "Call mom", isCompleted: true },
{ id: 6, description: "Go on holiday", isCompleted: false },
]);
this.id_counter = this.todos.length;
useAutofocus("todolist_input");
};

addTodo(ev) {
if (ev.keyCode === 13) {
let desc = ev.target.value;
if (desc) {
this.todos.push({
id: this.id_counter++,
description: desc,
isCompleted: false
});
ev.target.value = "";
}
}
};

toggleState(id) {
const index = this.todos.findIndex((elem) => elem.id === id);
this.todos[index].isCompleted = !this.todos[index].isCompleted;
}

removeTodo(id) {
const index = this.todos.findIndex((elem) => elem.id === id);
if (index >= 0) {
this.todos.splice(index, 1);
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todolist/todolist.xml
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">
<input t-ref="todolist_input" placeholder="Enter a new task." t-on-keyup="addTodo"/>
<t t-foreach="this.todos" t-as="i" t-key="i.id">
<p>
<TodoItem id="i.id" description="i.description" isCompleted="i.isCompleted" toggleState.bind="toggleState" removeTodo.bind="removeTodo"/>
</p>
</t>
</t>
</templates>
9 changes: 9 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useRef, useEffect } from "@odoo/owl"

export function useAutofocus(name) {
let ref = useRef(name);
useEffect(
(el) => el && el.focus(),
() => [ref.el]
)
}
5 changes: 2 additions & 3 deletions awesome_owl/views/templates.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<odoo>
<data>
<template id="awesome_owl.playground" name="Awesome T-Shirt thank you">
<template id="awesome_owl.playground" name="Awesome T-Shirt thank you">
<html>
<head>
<link type="image/x-icon" rel="shortcut icon" href="/web/static/img/favicon.ico"/>
<t t-call-assets="awesome_owl.assets_playground"/>
</head>

<body>
</body>
</html>
</template>
</template>
</data>
</odoo>
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Real Estate",
"depends": ["base"],
"application": True,
"installable": True,
"license": "LGPL-3",
"data": [
"security/ir.model.access.csv",
"views/estate_property_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_tag_views.xml",
"views/estate_property_offer_views.xml",
"views/res_users_views.xml",
"views/estate_menus.xml",
],
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
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
Loading