diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..23404132012 --- /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: String, + slots: Object, + } + + setup() { + this.state = useState({isOpened: false}); + } + + expand() { + this.state.isOpened = !this.state.isOpened; + } +} + diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..ca87cd00bfb --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,20 @@ + + + + +
+
+
+ + +
+

+ +

+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..a10a9dfc529 --- /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"; + static props = { + onChange: {type: Function, optional: true}, + } + + setup() { + this.state = useState({ value: 1 }); + } + + increment() { + this.state.value++; + this.props.onChange?.(); + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..8d82cb47d6a --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + + + +
+ Counter: + +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..bf5d32c92a9 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -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 = "
Hello
"; + this.value2 = markup(""); + this.sum = useState({ value: 2 }); + } + + incrementSum() { + this.sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..197bc76954d 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,21 @@ -
- hello world +
+ + +

Sum:

+ +
+ + Card 1 content. + + + + +
+ diff --git a/awesome_owl/static/src/todo_list/todo_item.js b/awesome_owl/static/src/todo_list/todo_item.js new file mode 100644 index 00000000000..ce57bd7aaec --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,26 @@ +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, + }; + + onChange() { + this.props.toggleState(this.props.todo.id); + } + + onRemove() { + this.props.removeTodo(this.props.todo.id); + } + +} diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml new file mode 100644 index 00000000000..e0368666db1 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,20 @@ + + + +
+ + + + + + +
+
+
diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js new file mode 100644 index 00000000000..4079b64baf3 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -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); + } + } +} diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml new file mode 100644 index 00000000000..03fa7517ca9 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,12 @@ + + + +
+ +

No todos yet !

+ + + +
+
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..78eea2a3cb7 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import {onMounted, useRef} from "@odoo/owl"; + +export function useAutoFocus(refName) { + const ref = useRef(refName); + onMounted(() => { + ref.el.focus(); + }); +} diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /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 00000000000..dd3a8824844 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,29 @@ +{ + 'name': 'Real Estate', + 'version': '1.0', + 'category': 'Real Estate/Brokerage', + 'summary': 'Manage your real estate properties and offers', + 'author': 'Odoo S.A.', + 'license': 'LGPL-3', + 'depends': [ + 'base', + ], + 'data': [ + 'security/ir.model.access.csv', + 'security/estate_security.xml', + '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', + 'data/estate.property.type.csv', + ], + 'demo': [ + 'demo/estate_property_demo.xml', + 'demo/estate_property_offer_demo.xml', + ], + 'installable': True, + 'application': True, + 'auto_install': False, +} diff --git a/estate/data/estate.property.type.csv b/estate/data/estate.property.type.csv new file mode 100644 index 00000000000..d534fc454fe --- /dev/null +++ b/estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +"id","name","sequence" +estate_property_type_residential,Residential,1 +estate_property_type_commercial,Commercial,2 +estate_property_type_industrial,Industrial,3 +estate_property_type_land,Land,4 diff --git a/estate/demo/estate_property_demo.xml b/estate/demo/estate_property_demo.xml new file mode 100644 index 00000000000..2379d6b392e --- /dev/null +++ b/estate/demo/estate_property_demo.xml @@ -0,0 +1,58 @@ + + + + + Big Villa + new + A nice and big villa + + 12345 + 2020-02-02 + 1500000 + 6 + 100 + 4 + True + True + 100000 + south + + + Trailer home + canceled + Home in a trailer park + + 54321 + 1970-01-01 + 100000 + 120000 + 1 + 10 + 4 + + + Small Apartment + new + A small apartment in the city center + + 98765 + 2020-01-01 + 500000 + 2 + 50 + 2 + + + + diff --git a/estate/demo/estate_property_offer_demo.xml b/estate/demo/estate_property_offer_demo.xml new file mode 100644 index 00000000000..12a71b8bb09 --- /dev/null +++ b/estate/demo/estate_property_offer_demo.xml @@ -0,0 +1,26 @@ + + + + + 10000 + + + + + + 1500000 + + + + + + 1500001 + + + + + + + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..fea9f441d6d --- /dev/null +++ b/estate/models/__init__.py @@ -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 diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..50407ab0488 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,100 @@ +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") + + company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company) + + _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 diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..59b6d64cca4 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,65 @@ +from dateutil.relativedelta import relativedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Offer for an estate property' + _order = 'price desc' + + price = fields.Float() + status = fields.Selection(copy=False, selection=[('accepted', 'Accepted'), ('refused', 'Refused')]) + validity = fields.Integer(string='Validity (days)', default=7) + date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_inverse_deadline') + + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', required=True) + property_type_id = fields.Many2one(related='property_id.property_type_id', store=True) + + _price_gt_zero = models.Constraint( + 'CHECK(price>0)', 'An offer price must be strictly positive', + ) + + @api.depends('validity', 'create_date') + def _compute_deadline(self): + for offer in self: + create_date = offer.create_date.date() if offer.create_date else fields.Date.today() + offer.date_deadline = create_date + relativedelta(days=offer.validity) + + def _inverse_deadline(self): + for offer in self: + offer.validity = (offer.date_deadline - offer.create_date.date()).days + + @api.model_create_multi + def create(self, vals_list): + precision = 2 + for vals in vals_list: + property_id = self.env['estate.property'].browse(vals['property_id']) + if float_compare(vals.get('price', 0.0), property_id.best_price, precision_digits=precision) < 0: + raise UserError(_("Your offer is too low. You cannot create an offer lower than the best offer.")) + if property_id.state == "new": + property_id.state = "offer_received" + return super().create(vals_list) + + def action_accept_offer(self): + for offer in self: + if 'accepted' in offer.mapped("property_id.offer_ids.status"): + raise UserError(_("Only one offer can be accepted !")) + offer.status = 'accepted' + offer.property_id.buyer_id = offer.partner_id + offer.property_id.selling_price = offer.price + offer.property_id.state = 'offer_accepted' + (offer.property_id.offer_ids - offer).write({'status': 'refused'}) + return True + + def action_refuse_offer(self): + for offer in self: + if offer.status == 'accepted': + offer.property_id.buyer_id = False + offer.property_id.selling_price = False + offer.property_id.state = 'offer_received' + 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 00000000000..8cb08b223ac --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate Property Tag' + _order = 'name' + + name = fields.Char(required=True) + color = fields.Integer() + + _unique_name = models.Constraint( + 'UNIQUE(name)', + 'Property tag name must be unique', + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..507994e8e11 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,23 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Define type of properties' + _order = 'name' + + name = fields.Char(required=True) + property_ids = fields.One2many('estate.property', 'property_type_id') + sequence = fields.Integer('Sequence', default=1) + offer_ids = fields.One2many('estate.property.offer', 'property_type_id') + offer_count = fields.Integer(compute='_compute_offer_count') + + _unique_name = models.Constraint( + 'UNIQUE(name)', + 'Property type name must be unique', + ) + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..8165fccb60f --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many('estate.property', 'salesman_id', domain=[('state', 'in', ['new', 'offer_received'])]) diff --git a/estate/security/estate_security.xml b/estate/security/estate_security.xml new file mode 100644 index 00000000000..804d5608be4 --- /dev/null +++ b/estate/security/estate_security.xml @@ -0,0 +1,43 @@ + + + + Real Estate + + + + + Agent + + + + + Manager + + + + + + Estate Property: see personal properties + + + [ + '|', ('salesman_id', '=', user.id), ('salesman_id', '=', False) + ] + + + + Estate Property: see all + + + [(1,'=',1)] + + + + Estate Property multi-company + + [ + '|', ('company_id', '=', False), + ('company_id', 'in', company_ids) + ] + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..07161ba7b12 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,9 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property_user,access_estate_property,model_estate_property,estate_group_user,1,1,1,0 +access_estate_property_manager,access_estate_property,model_estate_property,estate_group_manager,1,1,1,1 +access_estate_property_type_user,access_estate_property_type,model_estate_property_type,estate_group_user,1,0,0,0 +access_estate_property_type_manager,access_estate_property_type,model_estate_property_type,estate_group_manager,1,1,1,1 +access_estate_property_tag_user,access_estate_property_tag,model_estate_property_tag,estate_group_user,1,0,0,0 +access_estate_property_tag_manager,access_estate_property_tag,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_property_offer_user,access_estate_property_offer,model_estate_property_offer,estate_group_user,1,1,1,0 +access_estate_property_offer_manager,access_estate_property_offer,model_estate_property_offer,estate_group_manager,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..2602e669538 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..9e5cf882d04 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,42 @@ + + + + + estate.property.offers.view.list + estate.property.offer + + + + + + + +
+ + + + + + + + + + + + + + + + + + Property 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 00000000000..62815af8bcd --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,144 @@ + + + + Properties + estate.property + list,form,kanban + {'search_default_available': True} + + + + estate.properties.list + estate.property + + + + + + + + + + + + + + + + + estate.properties.view.form + estate.property + +
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.properties.view.search + estate.property + + + + + + + + + + + + + + + + + + + + estate.properties.view.kanban + estate.property + + + + + +
+
+

+ +

+
+
+ Expected price: + +
+
+ Best price: + +
+
+ Selling price: + +
+
+ +
+
+
+
+
+
+
+ + + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..8c9a6b1a3d7 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,17 @@ + + + + + res.users.view.form.inherit.estate.property + res.users + + + + + + + + + + + diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..0e68e55ed80 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,10 @@ + +{ + 'name': 'Estate Account', + 'author': 'Odoo S.A', + 'license': 'LGPL-3', + 'depends': [ + 'estate', + 'account', + ], +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..e3857b7a579 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,33 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_set_sold(self): + super().action_set_sold() + journal = self.env["account.journal"].search([("type", "=", "sale")], limit=1) + + for property in self: + commission = 0.06 * property.selling_price + + print(" reached ".center(50, "=")) + self.env['account.move'].sudo().create({ + 'name': property.name, + 'partner_id': property.buyer_id.id, + 'move_type': 'out_invoice', + 'journal_id': journal.id, + 'invoice_line_ids': [ + Command.create({ + 'name': f"Commission for selling property {property.name}", + 'quantity': 1, + 'price_unit': commission, + }), + Command.create({ + 'name': "Administrative fees", + 'quantity': 1, + 'price_unit': 100.0, + }), + ], + }) + return True