Skip to content
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
11 changes: 11 additions & 0 deletions awesome_owl/static/src/components/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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 },
};
}
15 changes: 15 additions & 0 deletions awesome_owl/static/src/components/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.card" owl="1">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">
<t t-esc="props.title"/>
</h5>
<p class="card-text">
<t t-out="props.content"/>
</p>
</div>
</div>
</t>
</templates>
20 changes: 20 additions & 0 deletions awesome_owl/static/src/components/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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++
if (this.props.onChange) {
this.props.onChange();
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/components/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" owl="1">
<div class="counter-container p-3 border m-2">
<p>Counter Value: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">
increment
</button>
</div>
</t>
</templates>
12 changes: 12 additions & 0 deletions awesome_owl/static/src/components/todo/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 },
},
};
}
9 changes: 9 additions & 0 deletions awesome_owl/static/src/components/todo/todo_item.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.TodoItem" owl="1">
<div class="todo-item p-2 border-bottom"
t-att-class="props.todo.isCompleted ? 'text-muted text-decoration-line-through' : ''">
<t t-esc="props.todo.id"/>. <t t-esc="props.todo.description"/>
</div>
</t>
</templates>
38 changes: 38 additions & 0 deletions awesome_owl/static/src/components/todo/todo_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, useState, onMounted, useRef} from "@odoo/owl"
import { TodoItem } from "./todo_item";

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

setup() {
// in TodoList
this.todos = useState([
// { id: 2, description: "write tutorial", isCompleted: true },
// { id: 3, description: "buy milk", isCompleted: false },
]);
this.nextId = 1;

this.inputRef = useRef("todo-input");

onMounted(() => {
this.inputRef.el.focus();
})
}

addTodo(ev) {
if (ev.keyCode == 13) {
const description = ev.target.value.trim();

if (description !== "") {
this.todos.push({
id:this.nextId++,
description: description,
isCompleted: false,
});

ev.target.value = "";
}
}
}
}
22 changes: 22 additions & 0 deletions awesome_owl/static/src/components/todo/todo_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.todo_list" owl="1">
<div class="todo-list p-3 shadow-sm bg-white rounded">
<h3 class="mb-3">My Tasks</h3>

<div class="mb-3">
<input type="text"
class="form-control"
placeholder="Enter a new task"
t-on-keyup="addTodo"
t-ref="todo-input"/>
</div>

<div class="list-group">
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo"/>
</t>
</div>
</div>
</t>
</templates>
18 changes: 17 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { Component } from "@odoo/owl";
import { Component, useState, markup } from "@odoo/owl";
import { Counter } from "./components/counter/counter"
import { Card } from "./components/card/card";
import { TodoList } from "./components/todo/todo_list";

export class Playground extends Component {
static template = "awesome_owl.playground";

static components = { Counter, Card, TodoList };

setup() {
this.html = markup("<div class='text-primary'>some content</div>");

this.state = useState({sum: 2})
this.incrementSum = this.incrementSum.bind(this);
}

incrementSum(){
this.state.sum++;
}
}
22 changes: 19 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<div class="p-4 bg-light border">
<div class="p-3">
hello world
</div>

<div class="p-4">
<Counter onChange="() => this.incrementSum()"/>
<Counter onChange="() => this.incrementSum()"/>


<strong>The sum is: <t t-esc="state.sum"/></strong>
</div>

<Card title="'card 1'" content="this.html"/>
<Card title="'card 2'" content="'content of card 2'"/>

<TodoList/>

</div>
</t>
</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
28 changes: 28 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

{
'name': 'Real Estate',
'version': '19.0.0.1.0',
'category': 'Real Estate/Properties',
'sequence': 15,
'summary': 'Track leads and close opportunities',
'website': 'https://www.odoo.com/app/estate',
'depends': [
'base',
],
'data': [
'security/ir.model.access.csv',
'views/estate_property_type_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_users_views.xml',
'views/estate_property_offers_views.xml',
'views/estate_property_views.xml',
'views/estate_property_menu.xml',
],
'demo': [],
'installable': True,
'application': True,
'assets': {},
'author': 'Odoo S.A.',
'license': 'LGPL-3',
}
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_propery_type
from . import estate_propery_tag
from . import estate_propery_offer
from . import res_users
112 changes: 112 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from odoo import fields, models, api
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = "estate.property"
Comment thread
yogietama marked this conversation as resolved.
_description = "Real Estate Property"
_order = "id desc"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_avaibility = fields.Date(string="Date Avaibility")
expected_price = fields.Float()
selling_price = fields.Float()
bedrooms = fields.Integer()
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
selection=[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West")
],
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
("new", "New"),
("offer received", "Offer Received"),
("offer accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled")
],
default="new"
)

partner_id = fields.Many2one("res.partner", string="Partner")
user_id = fields.Many2one("res.users", string="Users")
property_type_id = fields.Many2one("estate.property.type",
string="PropType")
property_tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many(
"estate.property.offer", "property_id", string="offers")
total_area = fields.Float(compute="_compute_total")
best_price = fields.Float(compute="_compute_best_price")

# define constrain
_check_expected_price = models.Constraint(
'CHECK(expected_price > 0)',
'The expected price must be strictly positive',
)

@api.depends("living_area", "garden_area")
def _compute_total(self):
for record in self:
record.total_area = record.living_area + record.garden_area

@api.depends("offer_ids.price", "expected_price")
def _compute_best_price(self):
for record in self:
if record.offer_ids:
record.best_price = max(record.offer_ids.mapped("price"))
else:
record.best_price = 0

@api.onchange("garden")
def _onchange_garden(self):
for record in self:
if record.garden:
record.garden_area = 10
record.garden_orientation = "north"
else:
record.garden_area = 0
record.garden_orientation = ""

@api.constrains("expected_price", "selling_price")
def _check_price_offer(self):
for record in self:
if record.selling_price > 0:
if float_is_zero(record.selling_price, precision_rounding=2):
continue
min_price = 0.9 * record.expected_price
# if offer percentage lower then 90%
if float_compare(record.selling_price, min_price, precision_digits=2) == -1:
raise ValidationError(
"The selling price cannot be lower than 90% of the expected price\n"
"You must reduce the expected price if you want to accept this offer"
)

def action_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError("Cancelled properties cannot be sold")
record.state = "sold"

def action_cancel(self):
for record in self:
if record.state == "sold":
raise UserError("Sold properties cannot be cancelled")
record.state = "cancelled"

@api.ondelete(at_uninstall=False)
def _unlink_if_new_or_canceled(self):
for record in self:
if record.state not in ['new', 'cancelled']:
raise UserError("You can only delete new or canceled properties.")
Loading