From 23b96c4faef8aa36e8c67fe7df9e9008059535a8 Mon Sep 17 00:00:00 2001 From: "Gilles (gicha)" Date: Mon, 15 Dec 2025 13:15:50 +0100 Subject: [PATCH 1/5] [ADD] estate: create a real estate module for Odoo. This pull request will add a new real estate module in Odoo that will allow the user to manage their properties and the customers offers. The key features are the following: - Property management: allow the user to manage property, its caracteristics (name, description, number of facades, living area, garder area and orientation, ...), expected price, tags and property type. - Offers management: allow the use to manage the offers made on each property. Each offer is made by a customer, has a validity and expiration date and can be either accepted or refused. - Automation: the module contains the following automation - the best price is automatically computed using the highest offer - the selling price is automatically computed when accepting an offer - the property state is automatically updated - an invoice is automatically created when a property is sold. This invoice contains the administration fees as well as a dowm payment for the property (6%). --- awesome_owl/__init__.py | 2 +- awesome_owl/static/src/card/card.js | 22 +++ awesome_owl/static/src/card/card.xml | 16 ++ awesome_owl/static/src/counter/counter.js | 19 +++ awesome_owl/static/src/counter/counter.xml | 9 + awesome_owl/static/src/main.js | 1 - awesome_owl/static/src/playground.js | 16 +- awesome_owl/static/src/playground.xml | 17 +- awesome_owl/static/src/todo_list/todo_item.js | 21 +++ .../static/src/todo_list/todo_item.xml | 13 ++ awesome_owl/static/src/todo_list/todo_list.js | 39 +++++ .../static/src/todo_list/todo_list.xml | 11 ++ awesome_owl/static/src/utils.js | 8 + estate/__init__.py | 1 + estate/__manifest__.py | 20 +++ estate/models/__init__.py | 5 + estate/models/estate_property.py | 120 ++++++++++++++ estate/models/estate_property_offer.py | 75 +++++++++ estate/models/estate_property_tag.py | 14 ++ estate/models/estate_property_type.py | 25 +++ estate/models/res_users.py | 11 ++ estate/security/ir.model.access.csv | 5 + estate/views/estate_menus.xml | 11 ++ estate/views/estate_property_offer_views.xml | 31 ++++ estate/views/estate_property_tag_views.xml | 26 +++ estate/views/estate_property_type_views.xml | 62 +++++++ estate/views/estate_property_views.xml | 156 ++++++++++++++++++ estate/views/res_users_views.xml | 14 ++ estate_account/__init__.py | 1 + estate_account/__manifest__.py | 13 ++ estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 27 +++ 32 files changed, 807 insertions(+), 5 deletions(-) create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml create mode 100644 awesome_owl/static/src/todo_list/todo_item.js create mode 100644 awesome_owl/static/src/todo_list/todo_item.xml create mode 100644 awesome_owl/static/src/todo_list/todo_list.js create mode 100644 awesome_owl/static/src/todo_list/todo_list.xml create mode 100644 awesome_owl/static/src/utils.js create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/models/__init__.py create mode 100644 estate/models/estate_property.py create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tag.py create mode 100644 estate/models/estate_property_type.py create mode 100644 estate/models/res_users.py create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/views/estate_menus.xml create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tag_views.xml create mode 100644 estate/views/estate_property_type_views.xml create mode 100644 estate/views/estate_property_views.xml create mode 100644 estate/views/res_users_views.xml create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py diff --git a/awesome_owl/__init__.py b/awesome_owl/__init__.py index 457bae27e11..b0f26a9a602 100644 --- a/awesome_owl/__init__.py +++ b/awesome_owl/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from . import controllers \ No newline at end of file +from . import controllers diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..a08dd547cb7 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,22 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + static props = { + title: String, + slots: { + type: Object, + shape: { + default: true + }, + }, + }; + + setup() { + this.state = useState({ isOpen: true }); + } + + toggleContent() { + this.state.isOpen = !this.state.isOpen; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..6ea4ccef97f --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,16 @@ + + + +
+
+
+ + +
+

+ +

+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..6b2cfb305c0 --- /dev/null +++ b/awesome_owl/static/src/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: 1 }); + } + + increment() { + this.state.value++; + if (this.props.onChange) { + 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..7102b0aa414 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +
+ Counter: + +
+
+
diff --git a/awesome_owl/static/src/main.js b/awesome_owl/static/src/main.js index 1aaea902b55..6c108687e29 100644 --- a/awesome_owl/static/src/main.js +++ b/awesome_owl/static/src/main.js @@ -9,4 +9,3 @@ const config = { // Mount the Playground component when the document.body is ready whenReady(() => mountComponent(Playground, document.body, config)); - diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..5ceb14d8a29 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 { markup, Component, 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.str1 = "
some content
"; + this.str2 = markup("
some content
"); + 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..549b2143040 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,8 +2,21 @@ -
- hello world +
+ + +
The sum is:
+
+
+ +
+
+ + + + + +
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..29d4e7ebbac --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,21 @@ +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..60c05fcf86d --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,13 @@ + + + +
+ + + +
+
+
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..64c6c6d7f3c --- /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.nextId = 0; + this.todos = useState([]); + useAutoFocus("input"); + } + + addTodo(ev) { + if (ev.keyCode == 13 && ev.target.value != ""){ + this.todos.push({ + id: this.nextId++, + description: ev.target.value, + isCompleted: false + }); + ev.target.value = ""; + } + } + + toggleTodo(todoId) { + const todo = this.todos.find((todo) => todo.id === todoId); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(todoId) { + const index = this.todos.findIndex((todo) => todo.id === todoId); + 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..3248c389e9c --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,11 @@ + + + +
+ + + + +
+
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..e19a0f03f62 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { useRef, onMounted } 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..b7d8db60d31 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'estate', + 'version': 1.0, + 'author': 'Odoo', + 'license': 'LGPL-3', + 'depends': [ + 'base', + ], + 'installable': True, + 'application': True, + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_offer_views.xml', + 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + ], +} 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..10a44248af5 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,120 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate property' + _order = 'id desc' + + name = fields.Char(required=True, string="Title") + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Datetime( + "Available From", copy=False, + default=lambda self: fields.Datetime.add(fields.Datetime.today(), months=3), + ) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + best_price = fields.Float(compute="_compute_best_price") + 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( + string="Garden Orientation", + selection=[ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West"), + ], + ) + total_area = fields.Integer(compute="_compute_total_area", readonly=True) + active = fields.Boolean(default=True) + state = fields.Selection( + string="Status", + selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + default="new", + ) + property_type_id = fields.Many2one("estate.property.type", string="Type") + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + salesperson_id = fields.Many2one( + "res.users", string="Salesperson", default=lambda self: self.env.uid, + ) + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + + _check_positive_expected_price = models.Constraint( + "CHECK(expected_price > 0)", + "The expected price of a property must be strictly positive.", + ) + + _check_positive_selling_price = models.Constraint( + "CHECK(selling_price >= 0)", "The selling price of a property must be positive.", + ) + + @api.constrains("selling_price") + def _check_selling_price(self): + for property in self: + if (float_compare(property.selling_price, (0.9 * property.expected_price), 2) == -1): + raise ValidationError(self.env._("The selling price must be at least 90% of the expected price. You may decrease the expected price if you want to accept this offer.")) + + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends("offer_ids.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): + if self.garden: + self.garden_area = 10 + self.garden_orientation = "north" + else: + self.garden_area = 0 + self.garden_orientation = "" + + def action_sold_property(self): + for property in self: + if property.state == "cancelled": + raise UserError(self.env._("Cancelled properties cannot be sold")) + property.state = "sold" + return True + + def action_cancel_property(self): + for property in self: + if property.state == "sold": + raise UserError(self.env._("Sold properties cannot be cancelled")) + property.state = "cancelled" + return True + + @api.ondelete(at_uninstall=False) + def _check_unlink(self): + for property in self: + if property.state != "new" and property.state != "cancelled": + raise UserError(self.env._("Only new and cancelled properties can be deleted!")) + + @api.onchange("offer_ids") + def _onchange_offer_ids(self): + for property in self: + if len(property.offer_ids) == 0: + property.state = "new" + elif property.state != "offer_accepted": + property.state = "offer_received" diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..5c48f0c1403 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,75 @@ +from odoo import api, fields, models +from odoo.exceptions import ValidationError + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Estate Property Offer' + _order = 'price desc' + + price = fields.Float() + status = fields.Selection( + string="Status", + selection=[("accepted", "Accepted"), ("refused", "Refused")], + copy=False, + ) + validity = fields.Integer(default=7, string="Validity (days)") + date_deadline = fields.Date( + compute="_compute_deadline", inverse="_inverse_deadline", string="Deadline", + ) + + partner_id = fields.Many2one("res.partner", string="Partner") + property_id = fields.Many2one("estate.property", string="Property") + property_type_id = fields.Many2one( + related="property_id.property_type_id", store=True, + ) + + _check_positive_price = models.Constraint( + "CHECK(price > 0)", + "The expected price of a offer must be positive.", + ) + + @api.depends("validity") + def _compute_deadline(self): + for offer in self: + if offer.create_date: + offer.date_deadline = fields.Date.add( + offer.create_date, days=offer.validity, + ) + else: + offer.date_deadline = fields.Date.add( + fields.Date.today(), days=offer.validity, + ) + + def _inverse_deadline(self): + for offer in self: + offer.validity = ( + offer.date_deadline - fields.Date.to_date(offer.create_date) + ).days + + def action_accept_offer(self): + for offer in self: + if offer.property_id.state == "offer_accepted": + offer.status = "refused" + return True + offer.status = "accepted" + offer.property_id.selling_price = offer.price + offer.property_id.buyer_id = offer.partner_id + offer.property_id.state = "offer_accepted" + return True + + def action_refuse_offer(self): + for offer in self: + if offer.status == "accepted": + offer.property_id.selling_price = 0 + offer.property_id.buyer_id = "" + offer.status = "refused" + return True + + @api.model + def create(self, vals): + for record in vals: + best_price = self.env["estate.property"].browse(record["property_id"]).best_price + if record["price"] < best_price: + raise ValidationError(self.env._("The offer must be greater than %s€", best_price)) + return super().create(vals) diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..7ad8e1f0ccf --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate Property Type' + _order = 'name asc' + + name = fields.Char(required=True) + color = fields.Integer() + + _check_unique_name = models.Constraint( + "UNIQUE(name)", "A property tag name should be unique", + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..dd5bd1b4539 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,25 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate Property Type' + _order = 'name asc' + + name = fields.Char(required=True) + sequence = fields.Integer( + "Sequence", default=1, help="Use to order property types. Lower is better.", + ) + + property_ids = fields.One2many("estate.property", "property_type_id") + offer_ids = fields.One2many("estate.property.offer", "property_type_id") + offer_count = fields.Integer(compute="_compute_offer_count") + + _check_unique_name = models.Constraint( + "UNIQUE(name)", "A property type name should be unique", + ) + + @api.depends("offer_ids") + def _compute_offer_count(self): + for type in self: + type.offer_count = len(type.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..16301fc546f --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class User(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", + "salesperson_id", + 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..49bca99cac8 --- /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 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..2407326acd7 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..2f58d88c7f9 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,31 @@ + + + + estate.property.offer.view.list + estate.property.offer + + + + + + + + +
+
+

+ +

+
+ + + + + + + + + + + + + + + + + + estate.property.type.view.list + estate.property.type + + + + + + + + + + estate.property.type.action + 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..a29cf154fc9 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,156 @@ + + + + estate.property.action + estate.property + list,form,kanban + {'search_default_available': True} + + + + estate.property.view.search + estate.property + + + + + + + + + + + + + + + + + estate.property.view.list + estate.property + + + + + + + + + + + + + + + + estate.property.view.form + estate.property + + +
+ + +
+
+ +
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.view.kanban + estate.property + + + + + +
+

+ +

+
+ Expected Price: +
+ Best Offer: +
+
+ Selling Price: +
+ +
+
+
+
+
+
+
+
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..d649a6cc5ce --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,14 @@ + + + res.users.view.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..3d6e9c860df --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,13 @@ +{ + 'name': 'estate_account', + 'version': 1.0, + 'author': 'Odoo', + 'license': 'LGPL-3', + 'depends': [ + 'account', + 'estate', + ], + 'installable': True, + 'application': True, + 'data': [], +} 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..25ea1306056 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,27 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold_property(self): + for record in self: + self.env['account.move'].create( + { + 'partner_id': int(record.buyer_id), + 'move_type': 'out_invoice', + 'invoice_line_ids': [ + Command.create({ + 'name': f"{record.name} (6% down payment)", + 'quantity': 1, + 'price_unit': 0.06 * record.selling_price, + }), + Command.create({ + 'name': 'Admin fees', + 'quantity': 1, + 'price_unit': 100.00, + }), + ], + }, + ) + return super().action_sold_property() From d1577d286d05be5365132c64f665ec22e583edca Mon Sep 17 00:00:00 2001 From: "Gilles (gicha)" Date: Mon, 22 Dec 2025 09:27:05 +0100 Subject: [PATCH 2/5] [IMP] awesome_dashboard: add a layout and reusable items to the dashboard. This will add a new layout to the dashboard, new buttons to allow quick navigation to the customers kanban view and the leads, and create a new DashboardItem component. This component is reusable and is displayed as a card on the dashboard. Its content is defined using a default slot to allow it to be set in the parent component. The width of the card is defined as (18*size)rem, where size is a property of the class with a default value of 1. This allow to easily create dashboard items of different sizes. --- awesome_dashboard/__manifest__.py | 2 +- awesome_dashboard/static/src/dashboard.js | 27 +++++++++++++++++++ awesome_dashboard/static/src/dashboard.scss | 3 +++ awesome_dashboard/static/src/dashboard.xml | 12 ++++++++- .../src/dashboard_item/dashboard_item.js | 21 +++++++++++++++ .../src/dashboard_item/dashboard_item.xml | 12 +++++++++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 awesome_dashboard/static/src/dashboard.scss create mode 100644 awesome_dashboard/static/src/dashboard_item/dashboard_item.js create mode 100644 awesome_dashboard/static/src/dashboard_item/dashboard_item.xml diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index a1cd72893d7..ae84852e416 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -26,5 +26,5 @@ 'awesome_dashboard/static/src/**/*', ], }, - 'license': 'AGPL-3' + 'license': 'AGPL-3', } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index c4fb245621b..ec435bbde27 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,8 +1,35 @@ import { Component } from "@odoo/owl"; import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { DashboardItem } from "./dashboard_item/dashboard_item"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem }; + + setup() { + this.display = { + controlPanel: {} + }; + this.action = useService("action"); + } + + openCustomerKanban() { + this.action.doAction("base.action_partner_form"); + } + + openLeadsViews() { + this.action.doAction({ + type: "ir.actions.act_window", + name: "All leads", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + }); + } } registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.scss b/awesome_dashboard/static/src/dashboard.scss new file mode 100644 index 00000000000..0dea9c62b16 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: lightgray; +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index 1a2ac9a2fed..08b0795a24e 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -2,7 +2,17 @@ - hello dashboard + + + + + +
+ some content + I love milk + some content +
+
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..0416e2e51bb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js @@ -0,0 +1,21 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + static props = { + size: { + type: Number, + default: 1, + }, + slots: { + type: Object, + shape: { + default: true, + }, + }, + }; + + setup() { + console.log("This item has a size of " + this.props.size); + } +} diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..a0ba8116392 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml @@ -0,0 +1,12 @@ + + + + +
+
+ +
+
+
+ +
From bd8abdb7f33b3160b5013e42509a4074e6c86308 Mon Sep 17 00:00:00 2001 From: "Gilles (gicha)" Date: Mon, 22 Dec 2025 10:32:48 +0100 Subject: [PATCH 3/5] [IMP] awesome_dashboard: get statistics, cache them and diplay a pie chart. This will add a service to get statistics and cache them to prevent calling the rpc route at every dashboard mounting. This will also add a pie chart using ChartJS through a newly created component. This allow the user to have an overview of the fetched data. --- awesome_dashboard/static/src/dashboard.js | 13 ++++-- awesome_dashboard/static/src/dashboard.xml | 37 +++++++++++++++-- .../src/dashboard_item/dashboard_item.js | 4 -- .../static/src/pie_chart/pie_chart.js | 41 +++++++++++++++++++ .../static/src/pie_chart/pie_chart.xml | 10 +++++ .../static/src/statistics_service.js | 14 +++++++ 6 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 awesome_dashboard/static/src/pie_chart/pie_chart.js create mode 100644 awesome_dashboard/static/src/pie_chart/pie_chart.xml create mode 100644 awesome_dashboard/static/src/statistics_service.js diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index ec435bbde27..e30bbd384e5 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,18 +1,23 @@ -import { Component } from "@odoo/owl"; +import { Component, onWillStart } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; +import { PieChart} from "./pie_chart/pie_chart"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; - static components = { Layout, DashboardItem }; + static components = { Layout, DashboardItem, PieChart }; setup() { + this.action = useService("action"); + this.statistics = useService("awesome_dashboard.statistics"); this.display = { - controlPanel: {} + controlPanel: {}, }; - this.action = useService("action"); + onWillStart(async () => { + this.statistics = await this.statistics.loadStatistics(); + }); } openCustomerKanban() { diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index 08b0795a24e..2ffd284f619 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -8,9 +8,40 @@
- some content - I love milk - some content + + Average number of t-shirt by order +
+ +
+
+ + Average time for an order to go from 'new' to 'send' or 'cancelled' +
+ +
+
+ + Number of new orders this month +
+ +
+
+ + Number of cancelled orders this month +
+ +
+
+ + Total amount of orders this month +
+ +
+
+ + Shirt orders by size + +
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js index 0416e2e51bb..7bf867b3d4f 100644 --- a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js @@ -14,8 +14,4 @@ export class DashboardItem extends Component { }, }, }; - - setup() { - console.log("This item has a size of " + this.props.size); - } } diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.js b/awesome_dashboard/static/src/pie_chart/pie_chart.js new file mode 100644 index 00000000000..aec45f0d25a --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.js @@ -0,0 +1,41 @@ +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +import { Component, onWillStart, useRef, onMounted, onWillUnmount } from "@odoo/owl"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + static props = { + title: String, + data: Object + }; + + setup(){ + this.canvasRef = useRef("canvas"); + onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onMounted(() => { + this.renderChart(); + }); + onWillUnmount(() => { + this.chart.destroy(); + }); + } + + renderChart() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + const color = labels.map((_, index) => getColor(index)); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data:{ + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + backgroundColor: color, + }, + ], + }, + }); + } +} diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..14e6684262c --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js new file mode 100644 index 00000000000..b5f6650a8c1 --- /dev/null +++ b/awesome_dashboard/static/src/statistics_service.js @@ -0,0 +1,14 @@ +import { registry } from "@web/core/registry"; +import { memoize } from "@web/core/utils/functions"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + async: ["loadStatistics"], + start() { + return { + loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), + }; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); From 41c8d2c8b2658c5cf154d4592262ca0da2f2d007 Mon Sep 17 00:00:00 2001 From: "Gilles (gicha)" Date: Mon, 22 Dec 2025 11:07:10 +0100 Subject: [PATCH 4/5] [IMP] awesome_dashboard: add realtime update to dashboard data and dashboard lazy loading. This will update the service so that it will update in realtime using a defined interval of 10 mintues (set as 10 seconds for test purpose). To update the data displayed in the dashboard, the service return a reactive object. This will also change the dashboard component from an action to a lazy component. This will allow the user to only load the dashboard when it is displayed. All dashboard item were moved into a new dashboard folder to make it easier to bundle and a new DashboadLoader component has been created to load the dashboard as a lazy component. --- awesome_dashboard/__manifest__.py | 4 ++++ .../static/src/{ => dashboard}/dashboard.js | 15 ++++++------- .../static/src/{ => dashboard}/dashboard.scss | 0 .../static/src/{ => dashboard}/dashboard.xml | 2 +- .../dashboard_item/dashboard_item.js | 0 .../dashboard_item/dashboard_item.xml | 0 .../{ => dashboard}/pie_chart/pie_chart.js | 0 .../{ => dashboard}/pie_chart/pie_chart.xml | 0 .../src/dashboard/statistics_service.js | 21 +++++++++++++++++++ .../static/src/dashboard_loader.js | 13 ++++++++++++ .../static/src/statistics_service.js | 14 ------------- 11 files changed, 45 insertions(+), 24 deletions(-) rename awesome_dashboard/static/src/{ => dashboard}/dashboard.js (66%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard.scss (100%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard.xml (96%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard_item/dashboard_item.js (100%) rename awesome_dashboard/static/src/{ => dashboard}/dashboard_item/dashboard_item.xml (100%) rename awesome_dashboard/static/src/{ => dashboard}/pie_chart/pie_chart.js (100%) rename awesome_dashboard/static/src/{ => dashboard}/pie_chart/pie_chart.xml (100%) create mode 100644 awesome_dashboard/static/src/dashboard/statistics_service.js create mode 100644 awesome_dashboard/static/src/dashboard_loader.js delete mode 100644 awesome_dashboard/static/src/statistics_service.js diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index ae84852e416..3da83434c8d 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,11 @@ 'assets': { 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', + ('remove', 'awesome_dashboard/static/src/dashboard/**/*'), ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' + ] }, 'license': 'AGPL-3', } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js similarity index 66% rename from awesome_dashboard/static/src/dashboard.js rename to awesome_dashboard/static/src/dashboard/dashboard.js index e30bbd384e5..2f455e57360 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -1,9 +1,9 @@ -import { Component, onWillStart } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; -import { PieChart} from "./pie_chart/pie_chart"; +import { PieChart } from "./pie_chart/pie_chart"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; @@ -11,20 +11,17 @@ class AwesomeDashboard extends Component { setup() { this.action = useService("action"); - this.statistics = useService("awesome_dashboard.statistics"); + this.statistics = useState(useService("awesome_dashboard.statistics")); this.display = { controlPanel: {}, }; - onWillStart(async () => { - this.statistics = await this.statistics.loadStatistics(); - }); } - openCustomerKanban() { + openCustomerView() { this.action.doAction("base.action_partner_form"); } - openLeadsViews() { + openLeads() { this.action.doAction({ type: "ir.actions.act_window", name: "All leads", @@ -37,4 +34,4 @@ class AwesomeDashboard extends Component { } } -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss similarity index 100% rename from awesome_dashboard/static/src/dashboard.scss rename to awesome_dashboard/static/src/dashboard/dashboard.scss diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml similarity index 96% rename from awesome_dashboard/static/src/dashboard.xml rename to awesome_dashboard/static/src/dashboard/dashboard.xml index 2ffd284f619..26b74edd8a0 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -7,7 +7,7 @@ -
+
Average number of t-shirt by order
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js similarity index 100% rename from awesome_dashboard/static/src/dashboard_item/dashboard_item.js rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml similarity index 100% rename from awesome_dashboard/static/src/dashboard_item/dashboard_item.xml rename to awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js similarity index 100% rename from awesome_dashboard/static/src/pie_chart/pie_chart.js rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml similarity index 100% rename from awesome_dashboard/static/src/pie_chart/pie_chart.xml rename to awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml diff --git a/awesome_dashboard/static/src/dashboard/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js new file mode 100644 index 00000000000..61fc1b87120 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,21 @@ +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + start() { + const statistics = reactive({ isReady: false }); + + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + + setInterval(loadData, 10*1000); + loadData(); + + return statistics; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..fde089e0f9e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,13 @@ +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; + +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); \ No newline at end of file diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js deleted file mode 100644 index b5f6650a8c1..00000000000 --- a/awesome_dashboard/static/src/statistics_service.js +++ /dev/null @@ -1,14 +0,0 @@ -import { registry } from "@web/core/registry"; -import { memoize } from "@web/core/utils/functions"; -import { rpc } from "@web/core/network/rpc"; - -const statisticsService = { - async: ["loadStatistics"], - start() { - return { - loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), - }; - }, -}; - -registry.category("services").add("awesome_dashboard.statistics", statisticsService); From 9871edc96ae925cffa5c3514a043cd165f41092d Mon Sep 17 00:00:00 2001 From: "Gilles (gicha)" Date: Mon, 22 Dec 2025 14:29:32 +0100 Subject: [PATCH 5/5] [IMP] awesome_dashboard: make the dashboard generic with item loaded from registry. This will make the dashboard generic by using a loop on an items list into the xml template. The item are fetch from a registry to allow other module to create dashboard item. This module load its items from the dashboard_items.js file. This will also add a filtering dialog, that will allow the user to choose which dashboad item to diplay. The configuration is store locally into the browser storage. --- awesome_dashboard/__manifest__.py | 4 +- .../static/src/dashboard/dashboard.js | 58 +++++++++++++++- .../static/src/dashboard/dashboard.xml | 65 ++++++++---------- .../static/src/dashboard/dashboard_items.js | 67 +++++++++++++++++++ .../src/dashboard/number_card/number_card.js | 17 +++++ .../src/dashboard/number_card/number_card.xml | 9 +++ .../pie_chart_card/pie_chart_card.js | 15 +++++ .../pie_chart_card/pie_chart_card.xml | 7 ++ .../src/dashboard/statistics_service.js | 2 +- .../static/src/dashboard_loader.js | 2 +- 10 files changed, 203 insertions(+), 43 deletions(-) create mode 100644 awesome_dashboard/static/src/dashboard/dashboard_items.js create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.js create mode 100644 awesome_dashboard/static/src/dashboard/number_card/number_card.xml create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js create mode 100644 awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 3da83434c8d..89481aa5f4a 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -27,8 +27,8 @@ ('remove', 'awesome_dashboard/static/src/dashboard/**/*'), ], 'awesome_dashboard.dashboard': [ - 'awesome_dashboard/static/src/dashboard/**/*' - ] + 'awesome_dashboard/static/src/dashboard/**/*', + ], }, 'license': 'AGPL-3', } diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js index 2f455e57360..81c30358067 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.js +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -3,18 +3,25 @@ import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { DashboardItem } from "./dashboard_item/dashboard_item"; -import { PieChart } from "./pie_chart/pie_chart"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; - static components = { Layout, DashboardItem, PieChart }; + static components = { Layout, DashboardItem }; setup() { this.action = useService("action"); this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); this.display = { controlPanel: {}, }; + this.items = registry.category("awesome_dashboard").getAll(); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }) } openCustomerView() { @@ -32,6 +39,51 @@ class AwesomeDashboard extends Component { ], }); } + + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this) + }); + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } +} + +class ConfigurationDialog extends Component { + static template = "awesome_dashboard.ConfigurationDialog"; + static components = { Dialog, CheckBox }; + static props = ["close", "items", "disabledItems", "onUpdateConfiguration"]; + + setup() { + this.items = useState(this.props.items.map((item) => { + return { + ...item, + enabled: !this.props.disabledItems.includes(item.id), + } + })); + } + + done() { + this.props.close(); + } + + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) + + browser.localStorage.setItem( + "disabledDashboardItems", + newDisabledItems, + ); + + this.props.onUpdateConfiguration(newDisabledItems); + } } -registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml index 26b74edd8a0..c3fccbb1945 100644 --- a/awesome_dashboard/static/src/dashboard/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -4,46 +4,39 @@ - - + + + + + +
- - Average number of t-shirt by order -
- -
-
- - Average time for an order to go from 'new' to 'send' or 'cancelled' -
- -
-
- - Number of new orders this month -
- -
-
- - Number of cancelled orders this month -
- -
-
- - Total amount of orders this month -
- -
-
- - Shirt orders by size - - + + + + + +
+ + + Which cards do you whish to see ? + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..b4bf1079c14 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,67 @@ +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; + +const items = [ + { + id: "average_quantity", + description: "Average number of t-shirt by order", + Component: NumberCard, + props: (data) => ({ + title: "Average number of t-shirt by order", + value: data.average_quantity + }), + }, + { + id: "average_time", + description: "Average time for an order", + Component: NumberCard, + props: (data) =>({ + title: "Average time for an order to go from 'new' to 'send' or 'cancelled'", + value: data.average_time, + }), + size: 2, + }, + { + id: "number_new_orders", + description: "Number of new orders", + Component: NumberCard, + props: (data) =>({ + title: "Number of new orders this month", + value: data.nb_new_orders, + }), + }, + { + id: "number_cancelled_orders", + description: "Number of cancelled orders", + Component: NumberCard, + props: (data) =>({ + title: "Number of cancelled orders this month", + value: data.nb_cancelled_orders, + }), + }, + { + id: "total_order", + description: "Total amount of orders", + Component: NumberCard, + props: (data) =>({ + title: "Total amount of orders this month", + value: data.total_amount, + }), + }, + { + id: "orders_by_size", + description: "Orders by size", + Component: PieChartCard, + props: (data) =>({ + title: "Shirt orders by size", + data: data['orders_by_size'], + }), + size: 2, + }, + +]; + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js new file mode 100644 index 00000000000..d3b2c4a8f99 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,17 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + }, + size: { + type: Number, + default: 1, + } + }; +} diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..8489a7f9be9 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..b1ee5af017b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,15 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../pie_chart/pie_chart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart } + static props = { + title: { + type: String, + }, + data: { + type: Object, + }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..9404da0e5c6 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js index 61fc1b87120..05af453dcb7 100644 --- a/awesome_dashboard/static/src/dashboard/statistics_service.js +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -11,7 +11,7 @@ const statisticsService = { Object.assign(statistics, updates, { isReady: true }); } - setInterval(loadData, 10*1000); + setInterval(loadData, 10*1000*60); loadData(); return statistics; diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js index fde089e0f9e..a5bdc15e1e9 100644 --- a/awesome_dashboard/static/src/dashboard_loader.js +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -10,4 +10,4 @@ class AwesomeDashboardLoader extends Component { } -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); \ No newline at end of file +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader);