Skip to content

Unit Tests tutorial #810

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 53 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f5df5c5
[ADD] estate: finished chapter 3
arthurrrm May 19, 2025
59e83b2
[ADD] chapter 3
arthurrrm May 19, 2025
439c30d
[ADD] chapter 4
arthurrrm May 19, 2025
ef2e205
[ADD] chapter 5 first half
arthurrrm May 19, 2025
3edc21b
[ADD] chapter 5 done
arthurrrm May 19, 2025
e6ce348
[ADD] finished chapter 6
arthurrrm May 19, 2025
ca315f5
[FIX] chapter 6 fix
arthurrrm May 20, 2025
a46be7f
[ADD] chapter 7 done
arthurrrm May 20, 2025
6d7858d
[ADD] chapter 7 done
arthurrrm May 20, 2025
86c8ab9
[FIX] chapter 7
arthurrrm May 20, 2025
27825b8
[ADD] estate: chapter 8 done + lint
arthurrrm May 20, 2025
7e69fef
[ADD] gitignore updated
arthurrrm May 20, 2025
3bb6ca4
[ADD] estate: chapter 9 done
arthurrrm May 20, 2025
5821075
[ADD] estate: chapter 9 done
arthurrrm May 20, 2025
d6558e2
[ADD] estate: chapter 10 done
arthurrrm May 21, 2025
f36eeea
[ADD] estate: chapter 11 inline view + widgets
arthurrrm May 21, 2025
c6be45b
[ADD] estate: chapter 11 += List Order
arthurrrm May 21, 2025
e590994
[ADD] estate: chapter 11 += Attributes and options
arthurrrm May 21, 2025
2aae01f
[ADD] estate: chapter 11 done
arthurrrm May 21, 2025
9255a03
[ADD] estate: chapter 12 += Python Inheritance
arthurrrm May 22, 2025
d35f9ba
[ADD] estate: chapter 12 done
arthurrrm May 22, 2025
a3f718a
[FIX] estate: chapter 12 done
arthurrrm May 22, 2025
ab5f481
[FIX] estate: chapter 12 actual final fix v2 final LAST fix
arthurrrm May 22, 2025
0b88c32
[FIX] estate: chapter 13 done + chapter 12 fix v4 (the last one)
arthurrrm May 22, 2025
84710d9
[FIX] estate: chapter 14 + 15 done
arthurrrm May 22, 2025
0356b6b
[REV] revised code on mathieu's comments
arthurrrm May 23, 2025
e9b6410
[REV] revised code on mathieu's comments
arthurrrm May 23, 2025
6c3ab74
[REV] revised code on mathieu's comments
arthurrrm May 23, 2025
546e977
[ADD] awesome_owl: 1.2 extract the counter in a sub component
arthurrrm May 23, 2025
c98f367
[ADD] awesome_owl: 1.3 add a simple card component
arthurrrm May 23, 2025
40c68a9
[ADD] awesome_owl: 1.4 markup to display html
arthurrrm May 23, 2025
4a2ce33
[ADD] awesome_owl: 1.5 + 1.6 props validation and sum oftwo Counter
arthurrrm May 23, 2025
c3713d8
[ADD] awesome_owl: 1.7 little todolist
arthurrrm May 26, 2025
933b277
[ADD] awesome_owl: 1.8 +1.9 dynamic attributes & user can add todos
arthurrrm May 26, 2025
588ea02
[ADD] awesome_owl: 1.10 auto focus on input
arthurrrm May 26, 2025
7b3aeb8
[ADD] awesome_owl: 1.11 toggling todos
arthurrrm May 26, 2025
2fa0f72
[ADD] awesome_owl: 1.12 deleting todos
arthurrrm May 26, 2025
8e65463
[ADD] awesome_owl: 1.13 generic card with slots
arthurrrm May 27, 2025
63d1d12
[ADD] awesome_owl: 1.14 minimizing card content
arthurrrm May 27, 2025
e078e49
[ADD] awesome_dashboard 2.1 new layout
arthurrrm May 27, 2025
9e76c58
[ADD] awesome_dashboard 2.2 Open leads and CRM view
arthurrrm May 27, 2025
029dc4d
[ADD] awesome_dashboard 2.3 add dashboard item
arthurrrm May 28, 2025
36d82b4
[ADD] awesome_dashboard 2.4 add some statistics
arthurrrm May 28, 2025
2c9c67c
[ADD] awesome_dashboard 2.5 cache network calls
arthurrrm May 28, 2025
14d0736
[ADD] awesome_dashboard 2.6 pie charts
arthurrrm May 28, 2025
aedd799
[ADD] estate : Add some standart Real estate property (tuto Define mo…
arthurrrm May 30, 2025
c3f2718
[ADD] estate : demo data for estate. property
arthurrrm May 30, 2025
caf2b1a
[ADD] estate : demo data for property offers
arthurrrm May 30, 2025
e4115af
[ADD] estate : add new demo property with offers directly defined in…
arthurrrm May 30, 2025
6e8d8ac
[ADD] estate : update XML files to include noupdate attribute and enh…
arthurrrm Jun 4, 2025
127db3d
[ADD] estate : implement unit tests for estate property offers
arthurrrm Jun 4, 2025
c500886
[ADD] estate : unit tests for offer creation and property set_sold ac…
arthurrrm Jun 4, 2025
8756ca1
[ADD] estate : add tests for garden field on form view
arthurrrm Jun 4, 2025
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ dmypy.json

# Pyre type checker
.pyre/


#pre commit
.pre-commit-config.yaml
ruff.toml


.vscode/
1 change: 0 additions & 1 deletion awesome_clicker/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion awesome_clicker/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Clicker",

Expand Down
1 change: 0 additions & 1 deletion awesome_dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

from . import controllers
1 change: 0 additions & 1 deletion awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Dashboard",

Expand Down
3 changes: 1 addition & 2 deletions awesome_dashboard/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
1 change: 0 additions & 1 deletion awesome_dashboard/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

import logging
import random
Expand Down
36 changes: 35 additions & 1 deletion awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, onWillStart } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { DashboardItem } from "./dashboard_item";
import { PieChart } from "./pie_chart/pie_chart";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, PieChart };

setup() {
this.display = {
controlPanel: {},
};

this.action = useService("action");
this.statisticsService = useService("awesome_dashboard.statistics");

onWillStart(async () => {
this.stats = await this.statisticsService.loadStatistics();
});
}

openCustomers() {
this.action.doAction("base.action_partner_form");
}

openLeads() {
this.action.doAction({
type: "ir.actions.act_window",
name: "All leads",
res_model: "crm.lead",
views: [
[false, "list"],
[false, "form"],
],
});
}
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: #a17d98;
}
46 changes: 44 additions & 2 deletions awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,48 @@

<t t-name="awesome_dashboard.AwesomeDashboard">
hello dashboard
</t>
<Layout display="display" className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>

</templates>
<div class="d-flex flex-wrap">
<DashboardItem class="dashboard-item">
<div class="dashboard-item-content">
<p>Number of new orders this month:</p>
<div class="fs-1 fw-bold text-success text-center"><t t-esc="stats.nb_new_orders"/></div>
</div>
</DashboardItem>
<DashboardItem class="dashboard-item">
<div class="dashboard-item-content">
<p>Total amount of new orders this month:</p>
<div class="fs-1 fw-bold text-success text-center"><t t-esc="stats.total_amount"/></div>
</div>
</DashboardItem>
<DashboardItem size="2" class="dashboard-item">
<div class="dashboard-item-content">
<p>Average amount of t-shirts per order this month:</p>
<div class="fs-1 fw-bold text-success text-center"><t t-esc="stats.average_quantity"/></div>
</div>
</DashboardItem>
<DashboardItem class="dashboard-item">
<div class="dashboard-item-content">
<p>Number of cancelled orders this month:</p>
<div class="fs-1 fw-bold text-success text-center"><t t-esc="stats.nb_cancelled_orders"/></div>
</div>
</DashboardItem>
<DashboardItem size="2" class="dashboard-item">
<div class="dashboard-item-content">
<p>Average time for an order to go from 'new' to 'sent' or 'cancelled':</p>
<div class="fs-1 fw-bold text-success text-center"><t t-esc="stats.average_time"/></div>
</div>
</DashboardItem>
<DashboardItem size="3" class="dashboard-item">
Shirt orders by size
<PieChart data="stats['orders_by_size']" label="'Shirt orders by size'"/>
</DashboardItem>
</div>
</Layout>
</t>
</templates>
20 changes: 20 additions & 0 deletions awesome_dashboard/static/src/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from "@odoo/owl";


export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";

static props = {
slots: {
type: Object,
shape: {
default: Object
},
},
size: {
type: Number,
default: 1, // Ensure default value is applied
optional: true
},
};
}
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard_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="awesome_dashboard.DashboardItem">
<div class="card m-2 border-dark" t-attf-style="width: {{18 * (props.size || 1)}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

</templates>
41 changes: 41 additions & 0 deletions awesome_dashboard/static/src/pie_chart/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { loadJS } from "@web/core/assets";
import { getColor } from "@web/core/colors/colors";
import { Component, onWillStart, useRef, onMounted, onWillUnmount } from "@odoo/owl";

export class PieChart extends Component {
static template = "awesome_dashboard.PieChart";
static props = {
label: String,
data: Object,
};

setup() {
this.canvasRef = useRef("canvas");
onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js"));
onMounted(() => {
this.renderChart();
});
onWillUnmount(() => {
this.chart.destroy();
});
}

renderChart() {
const labels = Object.keys(this.props.data);
const data = Object.values(this.props.data);
const color = labels.map((_, index) => getColor(index));
this.chart = new Chart(this.canvasRef.el, {
type: "pie",
data: {
labels: labels,
datasets: [
{
label: this.props.label,
data: data,
backgroundColor: color,
},
],
},
});
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/pie_chart/pie_chart.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="awesome_dashboard.PieChart">
<div t-att-class="'h-100 ' + props.class" t-ref="root">
<div class="h-100 position-relative" t-ref="container">
<canvas t-ref="canvas" />
</div>
</div>
</t>
</templates>
14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { registry } from "@web/core/registry";
import { memoize } from "@web/core/utils/functions";
import { rpc } from "@web/core/network/rpc";

const statisticsService = {
async: ["loadStatistics"],
start() {
return {
loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")),
};
},
};

registry.category("services").add("awesome_dashboard.statistics", statisticsService);
1 change: 0 additions & 1 deletion awesome_gallery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import models
1 change: 0 additions & 1 deletion awesome_gallery/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
{
'name': "Gallery View",
'summary': """
Expand Down
1 change: 0 additions & 1 deletion awesome_gallery/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# import filename_python_file_within_folder_or_subfolder
from . import ir_action
from . import ir_ui_view
1 change: 0 additions & 1 deletion awesome_gallery/models/ir_action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from odoo import fields, models


Expand Down
1 change: 0 additions & 1 deletion awesome_gallery/models/ir_ui_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from odoo import fields, models


Expand Down
1 change: 0 additions & 1 deletion awesome_kanban/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion awesome_kanban/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Kanban",
'summary': """
Expand Down
3 changes: 1 addition & 2 deletions awesome_owl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
1 change: 0 additions & 1 deletion awesome_owl/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Owl",

Expand Down
3 changes: 1 addition & 2 deletions awesome_owl/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
28 changes: 28 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @odoo-module **/

import { useState, Component } 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: false,
});
}

toggle() {
this.state.isOpen = !this.state.isOpen;
}
}
21 changes: 21 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.card">
<div class="card d-inline-block">
<div class="card-body">
<h5 class="card-title">
<t t-out="props.title"/>
<button class="btnc" t-on-click="toggle">
<t t-if="state.isOpen">Close</t>
<t t-else="">Open</t>
</button>
</h5>
<p class="card-text" t-show="state.isOpen">
<t t-slot="default"/>
</p>
</div>
</div>
</t>

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

import { useState, Component } 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();
}
}
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/counter/counter.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="awesome_owl.counter">
<p>Counter: <t t-esc="state.value"/>
<button class="btn btn-primary" t-on-click="increment"> Increment</button>
</p>
</t>

</templates>
2 changes: 1 addition & 1 deletion awesome_owl/static/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const config = {
};

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