diff --git a/awesome_owl/__manifest__.py b/awesome_owl/__manifest__.py index 55002ab81de..36b81016d86 100644 --- a/awesome_owl/__manifest__.py +++ b/awesome_owl/__manifest__.py @@ -34,6 +34,7 @@ 'web/static/lib/bootstrap/scss/_variables.scss', 'web/static/lib/bootstrap/scss/_maps.scss', ('include', 'web._assets_bootstrap'), + ('include', 'web._assets_bootstrap_backend'), ('include', 'web._assets_core'), 'web/static/src/libs/fontawesome/css/font-awesome.css', 'awesome_owl/static/src/**/*', diff --git a/awesome_owl/static/src/components/card/card.js b/awesome_owl/static/src/components/card/card.js new file mode 100644 index 00000000000..f1bd3459f1b --- /dev/null +++ b/awesome_owl/static/src/components/card/card.js @@ -0,0 +1,15 @@ +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({ isOpen: true }); + } + toggleOpen() { + this.state.isOpen = !this.state.isOpen; + } +} diff --git a/awesome_owl/static/src/components/card/card.xml b/awesome_owl/static/src/components/card/card.xml new file mode 100644 index 00000000000..e4e351e115d --- /dev/null +++ b/awesome_owl/static/src/components/card/card.xml @@ -0,0 +1,14 @@ + + + +
+
+
+ + +
+ +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/components/counter/counter.js b/awesome_owl/static/src/components/counter/counter.js new file mode 100644 index 00000000000..b351d71572e --- /dev/null +++ b/awesome_owl/static/src/components/counter/counter.js @@ -0,0 +1,19 @@ +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: 0 }); + } + + increment() { + this.state.value++; + if (this.props.onChange) { + this.props.onChange(); + } + } +} diff --git a/awesome_owl/static/src/components/counter/counter.xml b/awesome_owl/static/src/components/counter/counter.xml new file mode 100644 index 00000000000..af8487139e8 --- /dev/null +++ b/awesome_owl/static/src/components/counter/counter.xml @@ -0,0 +1,12 @@ + + + + +
+ Counter: + + +
+
+ +
diff --git a/awesome_owl/static/src/components/todoo/todo_item/todo_item.js b/awesome_owl/static/src/components/todoo/todo_item/todo_item.js new file mode 100644 index 00000000000..b7d01989fd2 --- /dev/null +++ b/awesome_owl/static/src/components/todoo/todo_item/todo_item.js @@ -0,0 +1,17 @@ +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, + }; +} diff --git a/awesome_owl/static/src/components/todoo/todo_item/todo_item.xml b/awesome_owl/static/src/components/todoo/todo_item/todo_item.xml new file mode 100644 index 00000000000..7d9c55541a3 --- /dev/null +++ b/awesome_owl/static/src/components/todoo/todo_item/todo_item.xml @@ -0,0 +1,13 @@ + + + +
+ + +. + + + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/components/todoo/todo_list/todo_list.js b/awesome_owl/static/src/components/todoo/todo_list/todo_list.js new file mode 100644 index 00000000000..d6ced3e65f8 --- /dev/null +++ b/awesome_owl/static/src/components/todoo/todo_list/todo_list.js @@ -0,0 +1,36 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "../todo_item/todo_item"; +import { useAutofocus } from "../../../utils"; +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + setup() { + this.todos = useState([]); + useAutofocus("todo_input"); + } + addTodo(event) { + if (event.keyCode === 13 && event.target.value.length) { + this.todos.push({ + id: this.todos.length + ? this.todos[this.todos.length - 1].id + 1 + : 1, + description: event.target.value, + isCompleted: false, + }); + event.target.value = ""; + } + } + toggleState(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 !== -1) { + this.todos.splice(index, 1); + } + } +} diff --git a/awesome_owl/static/src/components/todoo/todo_list/todo_list.xml b/awesome_owl/static/src/components/todoo/todo_list/todo_list.xml new file mode 100644 index 00000000000..d29bb302d2c --- /dev/null +++ b/awesome_owl/static/src/components/todoo/todo_list/todo_list.xml @@ -0,0 +1,12 @@ + + + +
+ + + + + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..1340e554b8e 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,15 @@ -import { Component } from "@odoo/owl"; - +import { Component, useState } from "@odoo/owl"; +import { Counter } from "./components/counter/counter"; +import { Card } from "./components/card/card"; +import { TodoList } from "./components/todoo/todo_list/todo_list"; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "awesome_owl.Playground"; + static components = { Counter, Card, TodoList }; + + setup() { + this.sum = useState({ value: 0 }); + } + incrementSum() { + this.sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..f14317744b1 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,28 @@ - + +
+
+ hello world +
+ + + +
- hello world + Sum: +
+
+ + Card 1 content + + + +
+

Todo List

+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..a58f34411a0 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,7 @@ +import { useRef, onMounted } from "@odoo/owl"; +export const useAutofocus = (ref) => { + const inputRef = useRef(ref); + onMounted(() => { + inputRef.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..c60b7eff130 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'Estate', + 'version': '0.0', + 'summary': 'Real Estate Management', + '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/estate_menus.xml', + 'views/res_users_views.xml' + ], + 'application': True, + 'author': 'Odoo S.A.', + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9a2189b6382 --- /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 00000000000..315b1948ff6 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,117 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError +from odoo.tools.date_utils import relativedelta +from odoo.tools.float_utils import float_compare, float_is_zero + + +GARDEN_ORIENTATION = [("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")] +PROPERTY_STATE = [("new", "New"), ("offer_received", "Offer Received"), ("offer_accepted", "Offer Accepted"), ("sold", "Sold"), ("cancelled", "Cancelled")] + + +class EstateProperty(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _name = "estate.property" + _description = "Real Estate Property" + _order = "id desc" + + # ------------------------------------------------------------------------- + # Field declarations + # ------------------------------------------------------------------------- + name = fields.Char(string="Title", required=True) + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + date_availability = fields.Date(string="Date Availability", copy=False, default=lambda self: fields.Date.context_today(self) + relativedelta(months=3)) + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(string="Selling Price", readonly=True, copy=False) + bedrooms = fields.Integer(string="Bedrooms", default=2) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") + garden_orientation = fields.Selection(string="Garden Orientation", selection=GARDEN_ORIENTATION) + active = fields.Boolean(string="Active", default=True) + state = fields.Selection(string="Status", selection=PROPERTY_STATE, required=True, copy=False, default="new") + + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + buyer_id = fields.Many2one("res.partner", string="Buyer") + salesman_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) + property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + + total_area = fields.Integer(string="Total Area (sqm)", compute="_compute_total_area") + best_offer = fields.Float(string="Best Offer", compute="_compute_best_offer") + + # ------------------------------------------------------------------------- + # SQL constraints + # ------------------------------------------------------------------------- + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + "The expected price must be strictly positive." + ) + _check_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + "The selling price must be positive." + ) + + # ------------------------------------------------------------------------- + # Compute methods + # ------------------------------------------------------------------------- + @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_offer(self): + for property in self: + property.best_offer = max(property.offer_ids.mapped("price"), default=0) + + # ------------------------------------------------------------------------- + # Constraints and onchange methods + # ------------------------------------------------------------------------- + @api.constrains("selling_price") + def _check_selling_price_minimum_ratio(self): + for property in self: + if float_is_zero(property.selling_price, precision_digits=2): + continue + if float_compare(property.selling_price, property.expected_price * 0.9, precision_digits=2) < 0: + raise ValidationError("The selling price must be at least 90% of the expected price.") + + @api.onchange("garden") + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = "north" + else: + self.garden_area = 0 + self.garden_orientation = False + + # ------------------------------------------------------------------------- + # ORM methods + # ------------------------------------------------------------------------- + @api.ondelete(at_uninstall=False) + def _unlink_new_cancelled_property(self): + for property in self: + if property.state not in ["new", "cancelled"]: + raise UserError("Only new and canceled properties can be deleted") + + # ------------------------------------------------------------------------- + # Action methods + # ------------------------------------------------------------------------- + def action_cancel_property(self): + for property in self: + if property.state == "sold": + raise UserError("Sold properties cannot be cancelled") + property.state = "cancelled" + return True + + def action_sold_property(self): + for property in self: + if property.state == "cancelled": + raise UserError("Cancelled properties cannot be sold") + property.state = "sold" + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..4f9ca5bddb5 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,91 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +from odoo.tools.date_utils import relativedelta +from odoo.tools.float_utils import float_compare + +PROPERTY_OFFER_STATE = [("accepted", "Accepted"), ("refused", "Refused")] + + +class PropertyOffer(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _name = "estate.property.offer" + _description = "Real Estate Property Offer" + _order = "price desc" + + # ------------------------------------------------------------------------- + # Field declarations + # ------------------------------------------------------------------------- + price = fields.Float() + status = fields.Selection(selection=PROPERTY_OFFER_STATE, copy=False) + + partner_id = fields.Many2one("res.partner", required=True) + property_id = fields.Many2one("estate.property", required=True) + + validity = fields.Integer(string="Validity (days)", default=7) + date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline") + + property_type_id = fields.Many2one( + "estate.property.type", + related="property_id.property_type_id", + string="Property Type", + store=True, + ) + + # ------------------------------------------------------------------------- + # SQL constraints + # ------------------------------------------------------------------------- + _check_price = models.Constraint( + 'CHECK(price > 0)', + "The offer price must be strictly positive." + ) + + # ------------------------------------------------------------------------- + # Compute and inverse methods + # ------------------------------------------------------------------------- + @api.depends("validity", "create_date") + def _compute_date_deadline(self): + for offer in self: + base_date = offer.create_date.date() if offer.create_date else fields.Date.today() + offer.date_deadline = base_date + relativedelta(days=offer.validity) + + def _inverse_date_deadline(self): + for offer in self: + base_date = offer.create_date.date() if offer.create_date else fields.Date.today() + if offer.date_deadline: + offer.validity = (offer.date_deadline - base_date).days + + # ------------------------------------------------------------------------- + # ORM methods + # ------------------------------------------------------------------------- + @api.model_create_multi + def create(self, vals): + for val in vals: + property_record = self.env["estate.property"].browse(val.get("property_id")) + + existing_prices = property_record.offer_ids.mapped("price") + max_property_offers = max(existing_prices) if existing_prices else 0 + if float_compare(val.get("price"), max_property_offers, precision_digits=2) <= 0: + raise UserError(f"The offer must be higher than {max_property_offers}") + if property_record.state == "new": + property_record.state = "offer_received" + return super().create(vals) + + # ------------------------------------------------------------------------- + # Action methods + # ------------------------------------------------------------------------- + def action_accept_offer(self): + for offer in self: + offer.property_id.offer_ids.status = "refused" + offer.status = "accepted" + offer.property_id.buyer_id = offer.partner_id + offer.property_id.selling_price = offer.price + offer.property_id.state = "offer_accepted" + return True + + def action_refuse_offer(self): + for offer in self: + 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..cd0793bde83 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,25 @@ +from odoo import models, fields + + +class PropertyTag(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _name = "estate.property.tag" + _description = "Real Estate Property Tag" + _order = "name" + + # ------------------------------------------------------------------------- + # Field declarations + # ------------------------------------------------------------------------- + name = fields.Char(string="Name", required=True) + color = fields.Integer(string="Color Index") + + # ------------------------------------------------------------------------- + # SQL constraints + # ------------------------------------------------------------------------- + _check_unique_name = models.Constraint( + 'UNIQUE(name)', + "The 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..deebe37532b --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,37 @@ +from odoo import api, models, fields + + +class PropertyType(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _name = "estate.property.type" + _description = "Real Estate Property Type" + _order = "sequence, name" + + # ------------------------------------------------------------------------- + # Field declarations + # ------------------------------------------------------------------------- + name = fields.Char(string="Property Type", required=True) + property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") + sequence = fields.Integer('Sequence', default=10) + + offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") + offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count") + + # ------------------------------------------------------------------------- + # SQL constraints + # ------------------------------------------------------------------------- + _check_unique_name = models.Constraint( + 'UNIQUE(name)', + "The property type name must be unique." + ) + + # ------------------------------------------------------------------------- + # Compute methods + # ------------------------------------------------------------------------- + @api.depends("offer_ids") + def _compute_offer_count(self): + for property_type in self: + property_type.offer_count = len(property_type.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..a7523ad17d9 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,14 @@ +from odoo import models, fields + + +class ResUsers(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _inherit = "res.users" + + # ------------------------------------------------------------------------- + # Field declarations + # ------------------------------------------------------------------------- + property_ids = fields.One2many("estate.property", "salesman_id", string="Estate Properties", domain="[('state', 'in', ('new', 'offer_received'))]") diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..4c593ed42e4 --- /dev/null +++ b/estate/security/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_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/estate/static/description/icon.png b/estate/static/description/icon.png new file mode 100644 index 00000000000..0ceddd7d3e9 Binary files /dev/null and b/estate/static/description/icon.png differ diff --git a/estate/static/description/icon.svg b/estate/static/description/icon.svg new file mode 100644 index 00000000000..40e3e6e98c3 --- /dev/null +++ b/estate/static/description/icon.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..b3476fd443e --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..6eca802a38e --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,24 @@ + + + + Property Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + estate.property.offer.list + estate.property.offer + + + + + + + + +
+

+ +

+ +
+ + + + + + + + + + + + + +
+
+ + estate.property.type.list + estate.property.type + + + + + + + +
\ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..a91d05dd879 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,128 @@ + + + + + Properties + estate.property + list,form,kanban + {'search_default_available': True, 'search_default_current': True} + + + estate.property.list + estate.property + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +
+

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + estate.property.view.search + estate.property + + + + + + + + + + + + + + + + + estate.property.view.kanban + estate.property + + + + + + + + +
+ Expected Price: +
+
+ Best Offer: +
+
+ Selling Price: +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..1896b67e822 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,16 @@ + + + + + res.users.form.inherit.estate + 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..f605bbdcdcb --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Estate Account', + 'version': '0.0', + 'summary': 'Real Estate Management with Account', + 'depends': [ + 'estate', + 'account', + ], + 'data': [ + + ], + 'application': True, + 'author': 'Odoo S.A.', + 'license': 'LGPL-3', +} 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..2f30024ae33 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,32 @@ +from odoo import models +from odoo.orm.commands import Command + + +class EstateProperty(models.Model): + + # ------------------------------------------------------------------------- + # Private attributes + # ------------------------------------------------------------------------- + _inherit = "estate.property" + + # ------------------------------------------------------------------------- + # Action methods + # ------------------------------------------------------------------------- + def action_sold_property(self): + self.env["account.move"].create({ + "partner_id": self.buyer_id.id, + "move_type": "out_invoice", + "invoice_line_ids": [ + Command.create({ + "name": self.name, + "quantity": 1, + "price_unit": self.selling_price * 0.06, + }), + Command.create({ + "name": "Administrative fees", + "quantity": 1, + "price_unit": 100.00, + }) + ], + }) + return super().action_sold_property()