diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 0000000000..4deb72eac8 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -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 }, + slots: { type: Object, optional: true }, + }; + + setup() { + this.state = useState({ showContent: true }); + this.minimizeContent = this.minimizeContent.bind(this); + } + + minimizeContent() { + this.state.showContent = !this.state.showContent; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 0000000000..9f2a04210e --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,14 @@ + + + +
+
+
+ + +
+ +
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 0000000000..d954dfe433 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,18 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.counter"; + + setup() { + this.state = useState({ value: 1 }); + } + + increment() { + this.state.value++; + if (this.props.onChange) this.props.onChange(); + } + + static props = { + onChange: { type: Function, optional: true }, + }; +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 0000000000..80ac9ed724 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + + +
+

Counter: + +

+ +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07b..37ee641e6c 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,18 @@ /** @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, TodoItem } from "./todo/todo"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoItem, TodoList }; + html = markup("
some content
"); + + setup() { + this.state = useState({ sum: 2 }); + } + + incrementSum() { + this.state.sum++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f..a7bcbab8e5 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,27 @@ - -
- hello world +
+
+ + +
+

+ +

+
+ +
+
+ + + + +
- - +
+ +
+ + \ No newline at end of file diff --git a/awesome_owl/static/src/todo/todo.js b/awesome_owl/static/src/todo/todo.js new file mode 100644 index 0000000000..d1807bf9a2 --- /dev/null +++ b/awesome_owl/static/src/todo/todo.js @@ -0,0 +1,68 @@ +import { Component, useState } from "@odoo/owl"; +import { useAutofocus } from "../utils"; + +export class TodoItem extends Component { + static template = "awesome_owl.todo.item"; + static props = { + todo: { + type: Object, + shape: { + id: { type: Number }, + description: { type: String }, + isCompleted: { type: Boolean }, + }, + }, + toggle_callback: { type: Function }, + remove_callback: { type: Function }, + }; + + setup() { + this.onChange = this.onChange.bind(this); + this.onClick = this.onClick.bind(this); + } + + onChange() { + this.props.toggle_callback(this.props.todo.id); + } + + onClick() { + this.props.remove_callback(this.props.todo.id); + } +} + +export class TodoList extends Component { + static template = "awesome_owl.todo.list"; + static components = { TodoItem }; + + setup() { + this.todos = useState([]); + this.addToDo = this.addToDo.bind(this); + this.toggleState = this.toggleState.bind(this); + this.removeTodo = this.removeTodo.bind(this); + + useAutofocus("input"); + } + + addToDo(event) { + let name = event.target.value; + if (event.keyCode === 13 && name.length) { + this.todos.push({ + id: this.todos.length + 1, + description: name, + isCompleted: false, + }); + event.target.value = ""; + } + } + + removeTodo(id) { + const index = this.todos.findIndex((todo) => todo.id === id); + if (index >= 0) { + this.todos.splice(index, 1); + } + } + + toggleState(id) { + this.todos[id - 1].isCompleted = !this.todos[id - 1].isCompleted; + } +} diff --git a/awesome_owl/static/src/todo/todo.xml b/awesome_owl/static/src/todo/todo.xml new file mode 100644 index 0000000000..40e74fe200 --- /dev/null +++ b/awesome_owl/static/src/todo/todo.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + +
+

+ + : + + +

+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 0000000000..043b7e105e --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(ref) { + let inputRef = useRef(ref); + onMounted(() => { + if (inputRef) inputRef.el.focus(); + }); +} diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 0000000000..35eacba9d9 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'Real Estate', + 'depends': ['base'], + 'category': 'Tutorials', + 'application': True, + 'data': ['data/ir.model.access.csv', + 'views/res_users.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_menus.xml', + ], + 'demo': [ + "demo/demo.xml", + ], + 'license': 'AGPL-3' +} diff --git a/estate/data/ir.model.access.csv b/estate/data/ir.model.access.csv new file mode 100644 index 0000000000..69385c87d8 --- /dev/null +++ b/estate/data/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_prop,access_estate_prop,model_estate_property,base.group_user,1,1,1,1 +access_estate_prop_type,access_estate_prop_type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_prop_offer,access_estate_prop_offer,model_estate_property_offer,base.group_user,1,1,1,1 +access_estate_prop_tag,access_estate_prop_tag,model_estate_property_tag,base.group_user,1,1,1,1 diff --git a/estate/demo/demo.xml b/estate/demo/demo.xml new file mode 100644 index 0000000000..63025fadcb --- /dev/null +++ b/estate/demo/demo.xml @@ -0,0 +1,13 @@ + + + + + Mass cancel + + + list + code + action = records.action_cancel() + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 0000000000..9a2189b638 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 0000000000..87ded8a7fc --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,91 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare +from odoo.fields import Many2many, One2many + +from .helper import format_selection + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate Property modelisation' + _order = 'id desc' + _sql_constraints = [ + ('expected_price_strictly_positive', 'CHECK(expected_price > 0)', 'Expected price must be stricly positive'), + ('selling_price_positive', 'CHECK(selling_price >= 0)', 'Selling price must be positive'), + ] + + name = fields.Char(required=True, string="Name") + description = fields.Text(string="Description") + postcode = fields.Char(string="Postal code") + date_availability = fields.Date(default=lambda x: fields.Date.today() + relativedelta(months=3), copy=False, + string='Availability date') + expected_price = fields.Float(required=True, string='Expected price') + selling_price = fields.Float(readonly=True, copy=False, string='Selling price') + bedrooms = fields.Integer(default=2, string='Bedrooms') + living_area = fields.Integer(string='Living area') + facades = fields.Integer(string='Facades') + garage = fields.Boolean(string='Garage') + garden = fields.Boolean(string='Garden') + garden_area = fields.Integer(string='Garden area') + garden_orientation = fields.Selection(string='Orientation', + selection=format_selection(['north', 'south', 'east', 'west']), + ) + active = fields.Boolean(default=True, string='Active') + state = fields.Selection(string='State', + selection=format_selection( + ['new', 'offer received', 'offer accepted', 'sold', 'canceled']), + default='new') + + property_type_id = fields.Many2one('estate.property.type', string='Property type') + + buyer_id = fields.Many2one('res.partner', copy=False, string='Buyer') + salesperson_id = fields.Many2one('res.users', default=lambda self: self.env.user, string='Salesperson') + + tag_ids = Many2many('estate.property.tag', string='Tags') + offer_ids = One2many('estate.property.offer', 'property_id', string='Offers') + + total_area = fields.Integer(compute='_compute_total_area', string='Total area') + best_price = fields.Float(compute='_compute_best_price', string='Best offer price') + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for estate in self: + estate.total_area = estate.living_area + estate.garden_area + + @api.depends('offer_ids') + def _compute_best_price(self): + for estate in self: + estate.best_price = max(estate.offer_ids.mapped('price'), default=0) + + @api.onchange('garden') + def _onchange_garden(self): + self.garden = [0, 10][self.garden] + self.garden_orientation = ['', 'north'][self.garden] + + @api.constrains('selling_price') + def _check_price_offer_reasonable(self): + if float_compare(self.selling_price, 0.9 * self.expected_price, 3) <= 0: + raise ValidationError('The selling price must be at least 90% of the expected price.') + + @api.ondelete(at_uninstall=False) + def _unlink_property_if_not_new_nor_canceled(self): + self.ensure_one() + if self.state not in ('new', 'canceled'): + raise UserError('Only new and canceled properties can be deleted.') + + def action_sold(self): + self.ensure_one() + if self.state == 'canceled': + raise UserError('Canceled properties cannot be sold.') + self.state = 'sold' + return True + + def action_cancel(self): + self.ensure_one() + if self.state == 'sold': + raise UserError('Sold properties cannot be canceled.') + self.state = 'canceled' + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 0000000000..7adb63b0f1 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,58 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError + +from .helper import format_selection + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _order = 'price desc' + _description = 'Offer modelisation' + _sql_constraints = [('offer_price_strictly_positive', 'CHECK(price > 0)', 'Offer price must be stricly positive')] + + price = fields.Float(string='Price', required=True) + status = fields.Selection(copy=False, selection=format_selection(['accepted', 'refused']), string='Status') + partner_id = fields.Many2one('res.partner', required=True, string='Buyer') + property_id = fields.Many2one('estate.property', required=True, string='Property') + + validity = fields.Integer(default=7, string="Validity") # in days + date_deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline', string='Deadline') + + property_type_id = fields.Many2one(related='property_id.property_type_id', string='Property type') + + @api.depends('validity') + def _compute_deadline(self): + for offer in self: + offer.date_deadline = fields.Date.today() + relativedelta(days=offer.validity) + + def _inverse_deadline(self): + for offer in self: + offer.validity = (offer.date_deadline - fields.Date.today()).days + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_id = self.env['estate.property'].browse(vals['property_id']) + if any(vals['price'] < offer.price for offer in property_id.offer_ids): + raise UserError('Offer price must be higher than existing offers.') + property_id.state = 'offer received' + return super().create(vals_list) + + def action_accept(self): + self.ensure_one() + if self.property_id.state == 'sold': + raise UserError('The house was already sold.') + self.status = 'accepted' + self.property_id.state = 'offer accepted' + self.property_id.buyer_id = self.partner_id + self.property_id.selling_price = self.price + return True + + def action_refuse(self): + for offer in self: + if offer.status == 'accepted': + raise UserError('The offer was already accepted.') + offer.status = 'refused' + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 0000000000..b7d204dbf6 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _order = 'name asc' + _description = 'Tag modelisation' + _sql_constraints = [('unique_name', 'unique(name)', 'Tag name must be unique')] + + name = fields.Char(required=True, string='Tag Name') + color = fields.Integer(string='Color Index') diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 0000000000..4405dca5bf --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,19 @@ +from odoo import fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate Property Type modelisation' + _order = 'sequence asc, name asc' + _sql_constraints = [('unique_name', 'unique(name)', 'Type name must be unique')] + + name = fields.Char(required=True, string='Name') + property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') + sequence = fields.Integer(default=1) + + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') + offer_count = fields.Integer(compute='_compute_offer_count', string='Offer Count') + + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/helper.py b/estate/models/helper.py new file mode 100644 index 0000000000..fb9a179c0d --- /dev/null +++ b/estate/models/helper.py @@ -0,0 +1,2 @@ +def format_selection(l: list): + return [(field, field.title()) for field in l] diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 0000000000..a658f77d3e --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class Users(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many('estate.property', 'salesperson_id', + domain=[('state', 'not in', ['sold', 'canceled'])]) diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 0000000000..9e9f344133 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 0000000000..c4426b8010 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,28 @@ + + + Property Offers + estate.property.offer + [('property_type_id', '=', active_id)] + list + + + + + estate.property.offer.list + estate.property.offer + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + Properties Types + estate.property.type + list,form + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 0000000000..8b727ebe48 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,157 @@ + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +
+
+ +
+
+ Expected Price: + +
+
+ Best Offer Price: + +
+
+ Selling price: + +
+
+ +
+
+
+
+
+
+
+ + + estate.property.form + estate.property + +
+ +
+
+ + + +

+ +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +