Skip to content

[ADD] estate, estate_account, awesome_owl, awesome_dashboard: tutorial modules #875

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 3 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
22 changes: 22 additions & 0 deletions awesome_owl/static/src/card/card.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 Card extends Component {
static template = "awesome_owl.Card";
static props = {
"title": String,
"content": { type: String, optional: true },
"slots": { type: Object, optional: true },
};

setup() {
this.state = useState({
isVisible: true // Stato per controllare la visibilità dello slot
});
}

toggleCard() {
this.state.isVisible = !this.state.isVisible;
}
}
24 changes: 24 additions & 0 deletions awesome_owl/static/src/card/card.xml
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.Card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-title d-flex justify-content-between align-items-center p-3">
<h5 class="mb-0"><t t-esc="props.title"/></h5>
<button class="btn btn-sm btn-danger" t-on-click="toggleCard">Toggle</button>
</div>

<t t-if="state.isVisible">
<div class="card-body">
<t t-if="props.content">
<p class="card-text">
<t t-out="props.content"/>
</p>
</t>
<t t-slot="body"/>
</div>
</t>
</div>
</t>

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

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

export class Counter extends Component {
static template = "awesome_owl.Counter";
static props = {
// RICEVO: callback dal parent (opzionale)
onIncrement: { type: Function, optional: true }
};

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

increment() {
this.state.value++;

// INVIO: notifico il parent del nuovo valore
if (this.props.onIncrement) {
this.props.onIncrement(this.state.value);
}
}
}
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 class="p-3 border rounded mb-2">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
29 changes: 28 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, useState, markup } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todo/todo_list";

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = { Counter, Card, TodoList };
static props = {};

setup() {
this.state = useState({
counter1: 0,
counter2: 0,
counter3: 0,
});

// Properties needed by the template
this.normalString = "This is normal text with <b>HTML tags</b>";
this.markupString = markup("This is <em>markup</em> with <strong>HTML tags</strong>");
this.dangerousMarkup = markup("This could be dangerous content");
this.markup = markup;
}

get sum() {
return this.state.counter1 + this.state.counter2;
}

updateCounter(counterName, value) {
this.state[counterName] = value;
}
}
54 changes: 50 additions & 4 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<div class="container-fluid p-4">
<h1 class="mb-4">Hello World</h1>

<div class="mb-4">
<h2>Counter Sum Demo</h2>
<div class="alert alert-primary mb-3">
<strong>Sum: <t t-esc="sum"/></strong>
</div>
<Counter onIncrement="(value) => this.updateCounter('counter1', value)"/>
<Counter onIncrement="(value) => this.updateCounter('counter2', value)"/>
</div>

<div class="mb-4">
<h2>Todo List Demo</h2>
<TodoList/>
</div>

<div class="mb-4">
<h2>Cards - Demonstrating t-set-slot</h2>

<Card title="'Ciao!'">
<t t-set-slot="body">
<p>This is the body content for the first card.</p>
</t>
</Card>

<Card title="'Ciao!'">
<t t-set-slot="body">
<Counter onIncrement="(value) => this.updateCounter('counter3', value)"/>
</t>
</Card>
</div>


<div class="mb-4">
<h2>Template - Demonstrating t-esc vs t-out</h2>
<div class="alert alert-info">
<h5>Using t-esc (always escaped):</h5>
<p><t t-esc="normalString"/></p>
<p><t t-esc="markupString"/></p>
</div>

<div class="alert alert-warning">
<h5>Using t-out (respects markup):</h5>
<p><t t-out="normalString"/></p>
<p><t t-out="markupString"/></p>
</div>
</div>
</div>
</t>

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

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
}
},
onToggle: { type: Function, optional: true },
onRemove: { type: Function, optional: true }
};

toggleTodo() {
if (this.props.onToggle) {
this.props.onToggle(this.props.todo.id);
}
}

removeTodo() {
if (this.props.onRemove) {
this.props.onRemove(this.props.todo.id);
}
}
}
31 changes: 31 additions & 0 deletions awesome_owl/static/src/todo/todo_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.TodoItem">
<div
class="todo-item border rounded p-3 mb-2"
t-att-class="props.todo.isCompleted ? 'bg-light text-muted' : 'bg-white'"
>
<div class="d-flex align-items-center">
<span class="badge bg-secondary me-2"><t t-esc="props.todo.id"/></span>
<span
t-att-class="props.todo.isCompleted ? 'text-decoration-line-through' : ''"
style="flex-grow: 1; cursor: pointer;"
t-on-click="toggleTodo"
>
<t t-esc="props.todo.description"/>
</span>
<div class="ms-auto d-flex align-items-center">
<t t-if="props.todo.isCompleted">
<span class="text-success fs-5 me-2">✓</span>
</t>
<t t-else="">
<span class="text-muted fs-6 me-2">○</span>
</t>
<button class="btn btn-sm btn-danger" t-on-click="removeTodo">🗑️</button>
</div>
</div>
</div>
</t>

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

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

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

setup() {
this.todos = useState([
{ id: 1, description: "buy milk", isCompleted: false },
{ id: 2, description: "learn Owl.js", isCompleted: true },
{ id: 3, description: "build todo app", isCompleted: false }
]);

this.newTodoText = useState({ value: "" });
this.nextId = 4; // Contatore semplice per i nuovi ID
}

addTodo() {
const description = this.newTodoText.value.trim();
if (description) {
this.todos.push({
id: this.nextId++, // ID sempre crescente, mai riutilizzato
description: description,
isCompleted: false
});
this.newTodoText.value = "";
}
}

onKeyPress(event) {
if (event.key === 'Enter') {
this.addTodo();
}
}

toggleTodo(todoId) {
const todo = this.todos.find(t => t.id === todoId);
if (todo) {
todo.isCompleted = !todo.isCompleted;
}
}

removeTodo(todoId) {
const index = this.todos.findIndex(t => t.id === todoId);
if (index !== -1) {
this.todos.splice(index, 1);
}
}
}
57 changes: 57 additions & 0 deletions awesome_owl/static/src/todo/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.TodoList">
<div class="todo-list p-4">
<h3>Todo List</h3>

<!-- Add Todo Form -->
<div class="add-todo-form mb-4">
<div class="input-group">
<input
type="text"
class="form-control"
placeholder="Add a new todo..."
t-model="newTodoText.value"
t-on-keypress="onKeyPress"
/>
<button
class="btn btn-primary"
type="button"
t-on-click="addTodo"
>
Add Todo
</button>
</div>
</div>

<!-- Todo List -->
<div class="todos">
<t t-if="todos.length === 0">
<div class="alert alert-info">
No todos yet! Add one above.
</div>
</t>
<t t-else="">
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem
todo="todo"
onToggle.bind="toggleTodo"
onRemove.bind="removeTodo"
/>
</t>
</t>
</div>

<!-- Stats -->
<div class="todo-stats mt-3">
<small class="text-muted">
Total: <t t-esc="todos.length"/> |
Completed: <t t-esc="todos.filter(t => t.isCompleted).length"/> |
Remaining: <t t-esc="todos.filter(t => !t.isCompleted).length"/>
</small>
</div>
</div>
</t>

</templates>
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
20 changes: 20 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
'name': "Real Estate",
'summary': """,
'description': """,
'version': "0.1",
'application': True,
'category': "Tutorials/estate",
'installable': True,
'depends': ["web", "contacts"],
'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",
],
'license': "AGPL-3",
}
7 changes: 7 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import (
estate_property,
estate_property_offer,
estate_property_tag,
estate_property_type,
res_users,
)
Loading