Skip to content

Commit 94d0037

Browse files
committed
[IMP] estate: added unit tests
This commit adds test cases to validate the key workflows in the estate module, including property creation, status transitions, and offer handling.These tests ensure better coverage and help prevent regressions during future development.
1 parent a90e48d commit 94d0037

File tree

11 files changed

+215
-4
lines changed

11 files changed

+215
-4
lines changed

awesome_owl/static/src/card/card.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @odoo-module **/
2+
3+
import { Component} from "@odoo/owl";
4+
5+
export class Card extends Component {
6+
static template = "awesome_owl.Card";
7+
static props = {
8+
title : {type: String},
9+
content : String,
10+
}
11+
}

awesome_owl/static/src/card/card.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.Card">
4+
<div class="card d-inline-block m-2" style="width: 18rem;">
5+
<div class="card-body">
6+
<h5 class="card-title"><t t-out="props.title"/></h5>
7+
<p class="card-text"><t t-out="props.content"/></p>
8+
</div>
9+
</div>
10+
</t>
11+
</templates>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
5+
export class Counter extends Component {
6+
static template = "awesome_owl.Counter";
7+
static props = {
8+
onChange: {type:Function, optional: true}
9+
}
10+
11+
setup() {
12+
this.state = useState({ value: 1 });
13+
}
14+
15+
increment() {
16+
this.state.value++;
17+
if(this.props.onChange){
18+
this.props.onChange(this.state.value);
19+
}
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.Counter">
4+
<div class="d-inline-flex align-items-center gap-2 m-3 p-3 border">
5+
<p>Counter: <t t-esc="state.value"/></p>
6+
<button class="btn btn-primary" t-on-click="increment" style="background-color: blue; color: white;">Increment</button>
7+
</div>
8+
</t>
9+
</templates>

awesome_owl/static/src/playground.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
/** @odoo-module **/
22

3-
import { Component } from "@odoo/owl";
3+
import { Component, useState } from "@odoo/owl";
4+
import { Counter } from "./counter/counter";
5+
import { Card } from "./card/card";
6+
import { TodoList} from "./todolist/todo_list"
47

58
export class Playground extends Component {
69
static template = "awesome_owl.playground";
10+
static components = {Counter, Card ,TodoList};
11+
12+
setup(){
13+
this.state = useState({sum:2});
14+
}
15+
incrementSum(value){
16+
this.state.sum += 1;
17+
}
718
}

awesome_owl/static/src/playground.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5-
<div class="p-3">
6-
hello world
5+
<div>
6+
<span>hello</span>
7+
<br/><br/>
8+
<Counter onChange.bind="incrementSum" />
9+
<Counter onChange.bind="incrementSum"/>
710
</div>
11+
<div>
12+
<p>the sum is : <t t-esc="state.sum"/></p>
13+
</div><br/><br/>
14+
<Card title="'1st card'" content="'first content'"/>
15+
<Card title="'2st card'" content="'this is real content'"/>
16+
<Card title="'3st card'" content="'last content'"/>
17+
18+
<TodoList/>
819
</t>
920

1021
</templates>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** @odoo-module **/
2+
3+
import { Component, xml } from "@odoo/owl";
4+
5+
export class TodoItem extends Component {
6+
static template = xml/* xml */`
7+
<div>
8+
<t t-esc="props.todo.id"/> .
9+
<t t-esc="props.todo.description" />
10+
</div>
11+
`;
12+
13+
static props = {
14+
todo: {
15+
type: Object,
16+
shape: {
17+
id: Number,
18+
description: String,
19+
isCompleted: Boolean,
20+
},
21+
optional: false,
22+
},
23+
};
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState, xml } from "@odoo/owl";
4+
import { TodoItem } from "./todo_item";
5+
6+
export class TodoList extends Component {
7+
static template = xml/* xml */`
8+
<div class="todo-item mb-2 p-2 border rounded">
9+
<h4>Todo List</h4>
10+
<div t-foreach="todos" t-as="todo" t-key="todo.id">
11+
<TodoItem todo="todo" />
12+
</div>
13+
</div>
14+
`;
15+
16+
static components = { TodoItem };
17+
18+
setup() {
19+
this.todos = useState([
20+
{ id: 3, description: "buy milk", isCompleted: false },
21+
{ id: 4, description: "complete assignment", isCompleted: false },
22+
]);
23+
}
24+
}

estate/models/estate_property.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def _onchange_garden(self):
8282

8383
def sold_button_action(self):
8484
for record in self:
85-
if record.status == 'cancelled':
85+
if record.state == 'cancelled':
8686
raise UserError("Cancelled property cannot be marked as sold.")
87+
elif record.state != 'Offer Accepted':
88+
raise UserError("At least one offer need to be accepted.")
8789
record.status = 'sold'
8890
record.state = 'sold'
8991

estate/tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
from . import test_estate_property

0 commit comments

Comments
 (0)