Skip to content

18.0 gato tutorials #657

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 6 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
26 changes: 26 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, markup } from '@odoo/owl';

export class Card extends Component {
static template = 'card.card';
static props = {
title: {
type: 'String',
optional: 'true',
},
ace: {
type: 'Function',
optional: 'true',
},
slots: {
type: 'Object',
optional: 'true',
},
};

setup() {
this.title = this.props.title ? this.props.title : 'No Title';
if (this.props.ace) {
this.props.ace(this);
}
}
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="card.card">
<div class="card" t-on-click="() => {console.log(this.props)}">
<h5><t t-out="title"/></h5>
<t t-slot="default"/>
</div>
</t>

</templates>
16 changes: 16 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = 'counter.counter';
static props = {
onChange: {type: 'Function', optional: 'true',},
}
setup() {
this.counter = useState({value: 0});
}

increment() {
this.counter.value++;
this.props.onChange('Prout!');
}
}
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="counter.counter">
<div class="p-3" style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
<p>COUNTER : <t t-esc="counter.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
18 changes: 16 additions & 2 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
/** @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 './todo_list/todo_list';

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

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


updateTotal(str) {
this.counter.value++;
}
}
57 changes: 52 additions & 5 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
</div>
</t>
<t t-name="awesome_owl.playground">
<style>
.card {
display: flex;
flex-direction: column;
justify-content: center;
width: 50%;
border-style: none;
border-thickness: 2px;
border-color: black;
border-radius: 25px;
margin: 1em auto;
padding: 2em;
transition: background-color ease-in-out 1s;
}
.card:hover {
background-color: #f2f2f2;
}
.todolist {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 2em;
}
.completed {
background-color: lightgreen;
}

.notcompleted {
background-color: tomato;
}
</style>
<div class="p-3">
<Card title="'Really cool title.'">
<p>I told you it was really cool!</p>
</Card>
<Card />
<Card title="'Card with cards inside!!!'">
<Card title="'Card with counters'">
<Counter onChange.bind="updateTotal"/>
<Counter onChange.bind="updateTotal"/>
<p>Total : <t t-esc="counter.value"/></p>
</Card>
<Card title="'Card with more counters'">
<Counter onChange.bind="updateTotal"/>
<Counter onChange.bind="updateTotal"/>
</Card>
</Card>
<TodoList />
</div>
</t>

</templates>
31 changes: 31 additions & 0 deletions awesome_owl/static/src/todo_item/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component, useState } from '@odoo/owl';

export class TodoItem extends Component {
static template = 'todo_item.todo_item';
static props = {
id: {type: 'Number',},
title: {type: 'String', optional: 'true',},
description: {type: 'String', optional: 'true',},
isCompleted: {type: 'Boolean', optional: 'true',},
update: {type: 'Function',},
remove: {type: 'Function',},
}
setup() {
this.contents = useState({
id: this.props.id,
title: this.props.title ? this.props.title : 'No Title.',
description: this.props.description ? this.props.description : 'No Description.',
isCompleted: this.props.isCompleted,
});

}

click() {
this.contents.isCompleted = !this.contents.isCompleted;
this.props.update(this.contents);
}

rubbish_bin() {
this.props.remove(this.contents);
}
}
12 changes: 12 additions & 0 deletions awesome_owl/static/src/todo_item/todo_item.xml
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="todo_item.todo_item">
<div class="card" t-on-click="click" t-att-class="contents.isCompleted ? 'text-muted text-decoration-line-through completed' : 'notcompleted'">
<h5><t t-esc="contents.title"/></h5>
<p><t t-esc="contents.description"/></p>
<button t-on-click="rubbish_bin">delete</button>
</div>
</t>

</templates>
59 changes: 59 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,59 @@
import { Component, useState, markup } from '@odoo/owl';
import { TodoItem } from '../todo_item/todo_item'

export class TodoList extends Component {
static template = 'todo_list.todo_list';
static props = {};
static components = {TodoItem};

setup() {
this.list = useState({items: []});

this.list.items = JSON.parse(window.localStorage.getItem('todo'));
}

update(item) {
for (let i = 0;i < this.list.items.length;i++) {
if (this.list.items[i].id == item.id) {
this.list.items[i].title = item.title;
this.list.items[i].description = item.description;
this.list.items[i].isCompleted = item.isCompleted;
}
}

window.localStorage.setItem('todo', JSON.stringify(this.list.items));
}

create_task(e) {
if (e.keyCode != 13) return;
let newTask = {
id: 0,
title: document.getElementById('title').value,
description: document.getElementById('description').value,
isCompleted: false,
}

if (newTask.title == '' || newTask.description == '') return;

for (let i = 0;i < this.list.items.length;i++) {
if (this.list.items[i].id >= newTask.id) {
newTask.id = this.list.items[i].id;
}
}
newTask.id++;
this.list.items = [...this.list.items, newTask];
window.localStorage.setItem('todo', JSON.stringify(this.list.items));
document.getElementById('title').value = '';
document.getElementById('description').value = '';
}

remove(item) {
const index = this.list.items.findIndex((elt) => elt.id == item.id);
if (index >= 0) {
this.list.items.splice(index, 1);
}


window.localStorage.setItem('todo', JSON.stringify(this.list.items));
}
}
17 changes: 17 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,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="todo_list.todo_list">
<div class="todolist">
<form t-on-keyup="create_task" style="display: flex;flex-direction: column;justify-content: center;align-items: center;margins: 0; padding: 0;">
<input type="text" name="title" id="title" placeholder="Title"/>
<input type="text" name="description" id="description" placeholder="Description"/>
</form>
<t t-foreach="list.items" t-as="item" t-key="item.id">

<TodoItem id="item.id" title="item.title" description="item.description" isCompleted="item.isCompleted" update.bind="update" remove.bind="remove"/>
</t>
</div>
</t>

</templates>
1 change: 1 addition & 0 deletions estateaccountinator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions estateaccountinator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
'name': 'estate-accountinator',
'description': 'Inator that helps you do accounting on real estate',
'category': 'Tutorials/Accountinator',
'author': 'gato',
'depends': [
'realestatinator',
'account',
],
'installable': True,
'application': True,
'auto_install': False,
'version': '0.1',
}
1 change: 1 addition & 0 deletions estateaccountinator/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property
24 changes: 24 additions & 0 deletions estateaccountinator/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import api, Command, fields, models


class EstateProperty(models.Model):
_inherit = 'estate.property'

def mark_sold(self):
for record in self:
line_defs = [
{
'name': f'selling price (6% of {record.selling_price})',
'quantity': 1,
'price_unit': 0.06*record.selling_price
},
{
'name': 'administrative fees',
'quantity': 1,
'price_unit': 100
},
]
lines = [Command.create(line) for line in line_defs]
values = {'partner_id': record.buyer.id, 'move_type': 'out_invoice', 'line_ids': lines}
moves = self.env['account.move'].create(values)
return super().mark_sold()
1 change: 1 addition & 0 deletions realestatinator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions realestatinator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
'name': 'real-estate-inator',
'description': 'Inator that helps you find real estate.',
'category': 'Tutorials/RealEstateInator',
'author': 'gato',
'depends': [
'base',
'web',
],
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_menus.xml',
],
'installable': True,
'application': True,
'auto_install': False,
'version': '0.1',
}
6 changes: 6 additions & 0 deletions realestatinator/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import res_users
Copy link

Choose a reason for hiding this comment

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

alphabetical order

from . import res_partner
from . import estate_property
from . import estate_property_type
from . import estate_property_tags
from . import estate_property_offer
Loading