Skip to content
Draft
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
18 changes: 18 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, useState } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.Card";
static props = {
title: { type: String, required: true },
slots: Object,
}

setup() {
this.state = useState({isOpened: false});
}

expand() {
this.state.isOpened = !this.state.isOpened;
}
}

20 changes: 20 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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-body">
<h5 class="card-title">
<t t-out="props.title"/>
<button class="btn btn-primary" t-on-click="expand">
<t t-if="state.isOpened">Collapse</t>
<t t-if="!state.isOpened">Expand</t>
</button>
</h5>
<p class="card-text" t-if="state.isOpened">
<t t-slot="default"/>
</p>
</div>
</div>
</t>
</templates>
18 changes: 18 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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++;
this.props.onChange?.();
}
}
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="m-2 p-2 border d-inline-block">
<span class="me-2">Counter: <t t-out="state.value"/></span>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
16 changes: 15 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
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 components = { Counter, Card, TodoList };

setup() {
this.value1 = "<div class='text-danger'>Hello</div>";
this.value2 = markup("<img src='x' onerror='alert(1)'/>");
this.sum = useState({ value: 2 });
}

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

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<div class="p-3 border d-inline-block">
<Counter onChange.bind="this.incrementSum"/>
<Counter onChange.bind="this.incrementSum"/>
<p class="mt-2">Sum: <t t-out="sum.value"/></p>
</div>

<div>
<Card title="'Card 1'">
Card 1 content.
</Card>
<Card title="'Card 2'">
<Counter/>
</Card>
</div>
<TodoList/>
</t>

</templates>
22 changes: 22 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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,
}
},
toggleState: Function,
removeTodo: Function,
};

onChanged() {
this.props.toggleState(this.props.todo.id);
}

}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.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.TodoItem">
<div t-att-class="props.todo.isCompleted ? 'text-decoration-line-through' : ''">
<input class="form-check-box" type="checkbox" t-att-checked="props.todo.isCompleted" t-on-change="onChanged"/>
<t t-out="props.todo.id"/>.
<t t-out="props.todo.description"/>
<span class="fa fa-remove" t-on-click="() => props.removeTodo(props.todo.id)"/>
</div>
</t>
</templates>
39 changes: 39 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,39 @@
import {Component, useState} from "@odoo/owl";
import {TodoItem} from "./todo_item";
import {useAutoFocus} from "../utils";

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

setup() {
this.currId = 1;
this.todos = useState([]);
useAutoFocus("input_todo");
}

addTodo(ev) {
if (ev.keyCode === 13 && ev.target.value !== "") {
this.todos.push({
id: this.currId++,
description: ev.target.value,
isCompleted: false
});
ev.target.value = "";
}
}

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

removeTodo(id) {
const index = this.todos.findIndex(todo => todo.id === id);
if (index >= 0) {
this.todos.splice(index, 1);
}
}
}
12 changes: 12 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,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_owl.TodoList">
<div class="d-inline-block border p-2 m-2">
<input class="form-control mb-3" type="text" placeholder="Add a todo !" t-on-keyup="addTodo" t-ref="input_todo"/>
<p t-if="todos.length === 0">No todos yet !</p>
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" toggleState.bind="toggleTodo" removeTodo.bind="removeTodo"/>
</t>
</div>
</t>
</templates>
8 changes: 8 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {onMounted, useRef} from "@odoo/owl";

export function useAutoFocus(refName) {
const ref = useRef(refName);
onMounted(() => {
ref.el.focus();
});
}
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',
'author': 'Odoo S.A.',
'license': 'LGPL-3',
'depends': [
'base',
],
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/res_users_views.xml',
'views/estate_menus.xml',
],
'installable': True,
'application': True,
'auto_install': False,
}
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_property_offer
from . import estate_property_tag
from . import estate_property_type
from . import res_users
98 changes: 98 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from dateutil.relativedelta import relativedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Handle real estate property"
_order = "id desc"

name = fields.Char(string='Title', required=True)
description = fields.Text()
postcode = fields.Char(string='Postcode')
date_availability = fields.Date(string='Available From', copy=False, default=fields.Date.today() + relativedelta(months=3))
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer(string='Living Area (sqm)')
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string='Garden Area (sqm)')
garden_orientation = fields.Selection(
selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')],
)
active = fields.Boolean(default=True)
state = fields.Selection(
string='Status',
selection=[('new', 'New'), ('offer_received', 'Offer Received'),
('offer_accepted', 'Offer accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')],
required=True,
copy=False,
default='new',
)

property_type_id = fields.Many2one('estate.property.type')
buyer_id = fields.Many2one('res.partner', copy=False)
salesman_id = fields.Many2one('res.users', default=lambda self: self.env.user)
tag_ids = fields.Many2many('estate.property.tag')
offer_ids = fields.One2many('estate.property.offer', 'property_id')

total_area = fields.Integer(compute="_compute_total_area")
best_price = fields.Float(string='Best Offer', compute="_compute_best_price")

_expected_price_gt_zero = models.Constraint(
'CHECK(expected_price > 0)', 'A property expected price must be strictly positive',
)
_selling_price_gt_zero = models.Constraint(
'CHECK(selling_price >= 0)', 'A property selling price must be positive',
)

@api.depends('living_area', 'garden_area')
def _compute_total_area(self):
for property in self:
property.total_area = property.living_area + property.garden_area

@api.depends('offer_ids.price')
def _compute_best_price(self):
for property in self:
property.best_price = max(property.offer_ids.mapped('price'), default=0)

@api.onchange('garden')
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = 'north'
else:
self.garden_area = False
self.garden_orientation = False

@api.constrains('expected_price', 'selling_price')
def _check_selling_price(self):
precision = 2
for record in self:
if not float_is_zero(record.selling_price, precision_digits=precision) and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=precision) < 0:
raise ValidationError(_('The selling price cannot be lower than 90% of the expected price'))

@api.ondelete(at_uninstall=False)
def _unlink_if_new_or_cancelled(self):
for record in self:
if record.state not in ['new', 'canceled']:
raise UserError(_("You cannot delete a property that is not new or cancelled."))

def action_set_sold(self):
for record in self:
if record.state == 'canceled':
raise UserError(_("Canceled properties can't be sold."))
record.state = 'sold'
return True

def action_cancel(self):
for record in self:
if record.state == 'sold':
raise UserError(_("Canceled properties can't be canceled."))
record.state = 'canceled'
return True
Loading