Skip to content

18.0 training aele #232

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
wants to merge 12 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Odoo tutorials

This repository hosts the code for the bases of the modules used in the
[official Odoo tutorials](https://www.odoo.com/documentation/latest/developer/tutorials.html).
This repository hosts the code for the bases and solutions of the
[official Odoo tutorials](https://www.odoo.com/documentation/17.0/developer/tutorials.html).

It has 3 branches for each Odoo version: one for the bases, one for the
[Discover the JS framework](https://www.odoo.com/documentation/latest/developer/tutorials/discover_js_framework.html)
tutorial's solutions, and one for the
[Master the Odoo web framework](https://www.odoo.com/documentation/latest/developer/tutorials/master_odoo_web_framework.html)
tutorial's solutions. For example, `17.0`, `17.0-discover-js-framework-solutions` and
`17.0-master-odoo-web-framework-solutions`.
It has 3 branches for each Odoo version: one for the bases, one for
[Discover the JS framework](https://www.odoo.com/documentation/17.0/developer/tutorials/discover_js_framework.html) solutions and one for [Master the Odoo web framework](https://www.odoo.com/documentation/17.0/developer/tutorials/master_odoo_web_framework.html) solutions. For example, `17.0`, `17.0-discover-js-framework-solutions` and `17.0-master-odoo-web-framework-solutions`.
The first contains the code of the modules that serve as base for the tutorials,
and the others contains the code of each chapter with the complete
solution.
8 changes: 4 additions & 4 deletions awesome_owl/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
'name': "Awesome Owl",

'summary': """
Starting module for "Discover the JS framework, chapter 1: Owl components"
Companion addon for the Odoo Smartclass 2024 on the JS Framework
""",

'description': """
Starting module for "Discover the JS framework, chapter 1: Owl components"
Companion addon for the Odoo Smartclass 2024 on the JS Framework
""",

'author': "Odoo",
Expand All @@ -16,8 +16,8 @@
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Tutorials/AwesomeOwl',
'version': '0.1',
'category': 'Tutorials',
'version': '0.2',

# any module necessary for this one to work correctly
'depends': ['base', 'web'],
Expand Down
25 changes: 25 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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;
}

}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/card/card.xml
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-out="props.title"/>
<button class="btn" t-on-click="toggleContent">Toggle</button>
</h5>
<p class="card-text" t-if="state.isOpen">
<t t-slot="default"/>
</p>
</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 @@
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.state.value + 1;

if (this.props.onChange) {
this.props.onChange();
}

}
}
9 changes: 9 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
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>
3 changes: 2 additions & 1 deletion awesome_owl/static/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Playground } from "./playground";

const config = {
dev: true,
name: "Owl Tutorial",
name: "Owl Tutorial"
};

// Mount the Playground component when the document.body is ready
whenReady(() => mountComponent(Playground, document.body, config));

19 changes: 17 additions & 2 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/** @odoo-module **/
import { Component, markup, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import {TodoList} from "./todo_list/todo_list";
import { Card } from "./card/card";

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

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++;
}


}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
<t t-name="awesome_owl.playground">
<div class="p-3">
hello world

<Counter onChange.bind="incrementSum" />
<Counter onChange.bind="incrementSum" />
<div>The sum is: <t t-esc="sum.value"/></div>

</div>

<div>
<Card title="'card 1'">
content of card 1
</Card>
<Card title="'card 2'">
<Counter />
</Card>
</div>

<TodoList />
</t>

</templates>
26 changes: 26 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, markup, useState } 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)
}


}
19 changes: 19 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<templates xml:space="preserve">

<t t-name="awesome_owl.TodoItem">
<div class="form-check">

<input class="form-check-input" type="checkbox" t-att-id="props.todo.id" t-att-checked="props.todo.isCompleted" t-on-change="onChange"/>

<label t-att-for="props.todo.id" 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 role="button" class="fa fa-trash ms-3 text-danger" t-on-click="onRemove"/>


</div>

</t>
</templates>
44 changes: 44 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, markup, 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 = 1;
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 todoIndex = this.todos.findIndex((todo) => todo.id === todoId);
if (todoIndex >= 0) {
this.todos.splice(todoIndex, 1);
}
}




}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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>
8 changes: 8 additions & 0 deletions awesome_owl/static/src/utils.js
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();
});
}
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
24 changes: 24 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
'name': "Real Estate",
'version': '1.0',
'depends': ['base'],
'author': "Ahmed Elamery AELE",
'category': 'Training',

'data' :[
'security/ir.model.access.csv',

# views
'views/estate_property_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',


# menu
'views/estate_menus.xml',

],
'installable': True,
'application': True,
}
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