diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index a1cd72893d7..becb0a0bb88 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,6 +24,10 @@ '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.js deleted file mode 100644 index c4fb245621b..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/configuration/configuration.js b/awesome_dashboard/static/src/dashboard/configuration/configuration.js new file mode 100644 index 00000000000..44ce10d9c6e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration/configuration.js @@ -0,0 +1,35 @@ +import { Component, useState } from "@odoo/owl" +import { Dialog } from "@web/core/dialog/dialog"; + +export class Configuration extends Component{ + static template = "awesome_dashboard.Configuration"; + static components = { Dialog }; + static props = { + items: { + type: Array, + }, + disabledItems: { + type: Array, + }, + update: { + type: Function, + }, + close: { + type: Function, + }, + } + + setup(){ + console.log(this.props.disabledItems); + } + + onChange(itemId){ + if(this.props.disabledItems.includes(itemId)){ + this.props.disabledItems = this.props.disabledItems.filter(id => id !== itemId); + } + else{ + this.props.disabledItems= [...this.props.disabledItems, itemId]; + } + this.props.update(this.props.disabledItems); + } +} diff --git a/awesome_dashboard/static/src/dashboard/configuration/configuration.xml b/awesome_dashboard/static/src/dashboard/configuration/configuration.xml new file mode 100644 index 00000000000..3ece31dde29 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration/configuration.xml @@ -0,0 +1,21 @@ + + + + + + Enabled cards: +
+ +
+ +

+

+
+
+ + + +
+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..4ed9d440698 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,54 @@ +import { Component, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; +import { Layout } from "@web/search/layout"; +import { registry } from "@web/core/registry"; +import { DashboardItem } from "./dashboard_item/dashboard_item"; +import { Configuration } from "./configuration/configuration"; +import { browser } from "@web/core/browser/browser"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem } + + setup(){ + this.display = {ControlPanel: {}} + this.action = useService("action"); + this.dialog = useService("dialog"); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.items = registry.category("awesome_dashboard").getAll(); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }); + } + + openCustomerView() { + this.action.doAction("base.action_partner_form"); + } + + openLeads(){ + this.action.doAction({ + type: 'ir.actions.act_window', + name: 'All leads', + res_model: 'crm.lead', + views: [ + [false, 'list'], + [false, 'form'], + ], + }); + } + + updateItems(disabledItems){ + this.state.disabledItems = disabledItems; + browser.localStorage.setItem("disabledDashboardItems", disabledItems); + } + + openConfiguration() { + this.dialog.add(Configuration, { + items: this.items, + disabledItems: this.state.disabledItems, + update: this.updateItems.bind(this), + }); + } +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..8ac16aaf14d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/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/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..f355ab857c1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + +
+ + + + + + +
+
+
+ +
diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..ed4888e06c2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,20 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + + static props = { + slots: { + type: Object, + optional: true + }, + size: { + type: Number, + optional: true, + }, + }; + + static defaultProps = { + size: 1, + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..d33810f171c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + + +
+ +
+
+ +
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..304cac39cca --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,63 @@ +import { registry } from "@web/core/registry" +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; + +const dashboard_registry = registry.category("awesome_dashboard") +dashboard_registry.add("average_new_order",{ + id: "average_new_order", + description: "Average amount of new orders", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of new orders this month", + value: data.total_amount + }), +}); +dashboard_registry.add("number_new_order",{ + id: "number_new_order", + description: "Total amount of new orders", + Component: NumberCard, + size: 1, + props: (data) => ({ + title: "Total amount of new orders this month", + value: data.nb_new_orders + }), +}); +dashboard_registry.add("average_quantity",{ + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + size: 5, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + value: data.average_quantity + }), +}); +dashboard_registry.add("number_cancelled_order",{ + id: "number_cancelled_order", + description: "Number of cancelled orders", + Component: NumberCard, + size: 2, + props: (data) => ({ + title: "Number of cancelled orders this month", + value: data.nb_cancelled_orders + }), +}); +dashboard_registry.add("average_state_change",{ + id: "average_state_change", + description: "Average time for state change", + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time + }), +}); +dashboard_registry.add("pie_chart",{ + id: "pie_chart", + description: "Shirt orders by size", + Component: PieChartCard, + size: 3, + props: (data) => ({ + title: "Shirt orders by size", + value: data.orders_by_size + }), +}); 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..545e402b8cc --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl" + +export class NumberCard extends Component{ + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + } + }; +} 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..c6afa9ebe6e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,11 @@ + + + + + +
+ +
+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js new file mode 100644 index 00000000000..5542b0d074c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,51 @@ +import { Component, onWillStart, onMounted, onWillUnmount, onPatched, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets" + +export class PieChart extends Component{ + static template = "awesome_dashboard.PieChart"; + + static props = { + label: { + type: String, + }, + data: { + type: Object, + }, + } + + setup(){ + this.canvasRef = useRef("canvas") + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }); + onMounted(()=>{ + this.renderChart(); + }); + onPatched(() => { + this.chart.destroy(); + this.renderChart(); + }); + onWillUnmount(() => { + this.chart.destroy(); + }); + + } + + renderChart() { + const labels = Object.keys(this.props.data); + const dataValues = Object.values(this.props.data); + + this.chart = new Chart(this.canvasRef.el, { + type: 'pie', + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: dataValues, + }, + ] + } + }); + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..89a7de9ca96 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + + +
+ +
+
+ +
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..2cb0d4fe7e1 --- /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, + }, + value: { + 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..d66fa141d1c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file 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..eff81e2ce3f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,21 @@ +import { reactive } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + start() { + const statistics = reactive({ isReady: false }); + + async function update() { + const value = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, value, { isReady: true }); + } + + setInterval(update, 10*60*1000); + update() + + return statistics + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..1b866c1ecc5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,12 @@ +import { Component, xml } from "@odoo/owl" +import { LazyComponent } from "@web/core/assets" +import { registry } from "@web/core/registry"; + +export 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_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..fc15aef7799 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,18 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + + static props = { + title: {type: String}, + slots: {optional: true}, + } + + setup(){ + this.state = useState({isOpen: true}) + } + + toggle(){ + this.state.isOpen = !this.state.isOpen; + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..1815fa3c6ec --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,21 @@ + + + + +
+
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+ diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..e314d5896b2 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,21 @@ +import { useState, Component } 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..a38ca1d10a6 --- /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..b86a74e9c90 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,21 @@ -import { Component } from "@odoo/owl"; +import { Component, useState, markup } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo/TodoList"; export class Playground extends Component { static template = "awesome_owl.playground"; + + static components = { Counter, Card, TodoList }; + + setup(){ + this.state = useState({sum: 2}); + } + + incrementSum(){ + this.state.sum++; + } + + card1_value = "
TESTINGINGINGING
"; + card2_value = markup("
TESTINGINGINGING
"); } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..53b0eb34d9f 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,22 @@ -
- hello world +
+ + + + + + + + + +
+

+ Sum: +

+ diff --git a/awesome_owl/static/src/todo/TodoItem.js b/awesome_owl/static/src/todo/TodoItem.js new file mode 100644 index 00000000000..e25db7ed27d --- /dev/null +++ b/awesome_owl/static/src/todo/TodoItem.js @@ -0,0 +1,30 @@ +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, + }, + }, + onChange: { + type: Function, + }, + onRemove: { + type: Function, + }, + } + + change(){ + this.props.onChange(); + } + + remove(){ + this.props.onRemove(); + } +}; \ No newline at end of file diff --git a/awesome_owl/static/src/todo/TodoItem.xml b/awesome_owl/static/src/todo/TodoItem.xml new file mode 100644 index 00000000000..6fecadaa685 --- /dev/null +++ b/awesome_owl/static/src/todo/TodoItem.xml @@ -0,0 +1,19 @@ + + + + +
+

+

+ +
+ . + +
+
+ +

+
+
+ +
diff --git a/awesome_owl/static/src/todo/TodoList.js b/awesome_owl/static/src/todo/TodoList.js new file mode 100644 index 00000000000..5003944b9c3 --- /dev/null +++ b/awesome_owl/static/src/todo/TodoList.js @@ -0,0 +1,39 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./TodoItem"; +import { useAutofocus } from "../utils"; + +export class TodoList extends Component{ + static template = "awesome_owl.TodoList" + + static components = { TodoItem } + + setup(){ + this.todoItems = useState([]); + this.nextId = 0; + useAutofocus("todoInput"); + } + + addTodo(event){ + if(event.keyCode === 13){ + const description = event.target.value.trim(); + if(description.length){ + this.todoItems.push({id: this.nextId++, description: description, isCompleted: false}) + event.target.value = "" + } + } + } + + toggleState(todoId){ + const todo = this.todoItems.find(item => item.id === todoId); + + todo.isCompleted = !todo.isCompleted; + } + + removeTodo(todoId) { + const index = this.todoItems.findIndex(todo => todo.id === todoId); + + if (index >= 0) { + this.todoItems.splice(index, 1); + } + } +}; \ No newline at end of file diff --git a/awesome_owl/static/src/todo/TodoList.xml b/awesome_owl/static/src/todo/TodoList.xml new file mode 100644 index 00000000000..46a070cec41 --- /dev/null +++ b/awesome_owl/static/src/todo/TodoList.xml @@ -0,0 +1,13 @@ + + + + +
+ + + + +
+
+ +
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..df2c2f0cfe1 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,9 @@ +import { useRef, useEffect } from "@odoo/owl" + +export function useAutofocus(name){ + let ref = useRef(name); + useEffect ( + (el) => el & el.focus(), + () => [ref.el] + ) +} \ No newline at end of file diff --git a/awesome_owl/views/templates.xml b/awesome_owl/views/templates.xml index aa54c1a7241..3df6b44bd5b 100644 --- a/awesome_owl/views/templates.xml +++ b/awesome_owl/views/templates.xml @@ -5,6 +5,7 @@ + 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..00fbb41cb6b --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,28 @@ +{ + 'name': 'Real Estate', + 'category': 'Real Estate/Brokerage', + 'depends': [ + 'base' + ], + 'application': True, + 'installable': True, + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + + 'data/estate.property.type.csv', + + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_types_views.xml', + 'views/estate_property_tags_views.xml', + 'views/res_user_views.xml', + 'views/estate_menus.xml', + ], + 'demo': [ + 'demo/estate_properties_demo.xml', + 'demo/estate_offers_demo.xml', + ], + 'author': 'Odoo S.A.', + 'license': 'AGPL-3' +} diff --git a/estate/data/estate.property.type.csv b/estate/data/estate.property.type.csv new file mode 100644 index 00000000000..ff0886c87f0 --- /dev/null +++ b/estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +id,name,sequence,offer_count,property_ids,offer_ids +property_type_0,Residential,,,, +property_type_1,Commercial,,,, +property_type_2,Industrial,,,, +property_type_3,Land,,,, \ No newline at end of file diff --git a/estate/demo/estate_offers_demo.xml b/estate/demo/estate_offers_demo.xml new file mode 100644 index 00000000000..98aed901193 --- /dev/null +++ b/estate/demo/estate_offers_demo.xml @@ -0,0 +1,35 @@ + + + + + + + 10000 + 14 + + + + + + 1500000 + 14 + + + + + + 1500001 + 14 + + + + + + + + + + + + + \ No newline at end of file diff --git a/estate/demo/estate_properties_demo.xml b/estate/demo/estate_properties_demo.xml new file mode 100644 index 00000000000..cf04d459359 --- /dev/null +++ b/estate/demo/estate_properties_demo.xml @@ -0,0 +1,56 @@ + + + + + Big Villa + new + A nice and big villa + 12345 + 2020-02-02 + 1600000 + 6 + 100 + 4 + True + True + 100000 + south + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 120000 + 1 + 10 + 4 + False + + + + Great home + new + Home in a great place + 15243 + 1998-10-01 + 150000 + 4 + 50 + 4 + False + + + + + \ No newline at end of file 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..9352e2d9102 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,92 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_is_zero + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = "Estate properties" + _order = 'id desc' + + name = fields.Char(string='Name', required=True) + description = fields.Char(string='Description') + postcode = fields.Char(string='Post Code') + bedrooms = fields.Integer(string='Bedrooms', default=2) + living_area = fields.Integer(string='Living Area') + facades = fields.Integer(string='Facades') + garden_area = fields.Integer(string='Garden Area') + total_area = fields.Integer(string='Total Area', compute='_compute_total_area') + expected_price = fields.Float(string='Expected Price', required=True) + selling_price = fields.Float(string='Selling Price', readonly=True, copy=False) + best_price = fields.Float(string='Best Offer', compute='_compute_best_price') + garage = fields.Boolean(string='Garage') + garden = fields.Boolean(string='Garden') + active = fields.Boolean(string='Active', default=True) + date_availability = fields.Date(string='Available From', copy=False, default=lambda x: fields.Date.add(fields.Date.today(), months=3)) + garden_orientation = fields.Selection( + string='Garden Orientation', + selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')]) + state = fields.Selection( + string='State', + selection=[('new', 'New'), ('offer_received', 'Offer Received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Cancelled')], + required=True, + copy=False, + default='new') + property_type_id = fields.Many2one(comodel_name='estate.property.type', string='Type') + buyer_id = fields.Many2one(comodel_name='res.partner', string='Buyer') + salesman_id = fields.Many2one(comodel_name='res.users', string='Salesman', default=lambda self: self.env.user) + company_id = fields.Many2one(comodel_name='res.company', string='Company', required=True, default=lambda self: self.env.company) + tag_ids = fields.Many2many(comodel_name='estate.property.tag', string='Tags') + offer_ids = fields.One2many(comodel_name='estate.property.offer', inverse_name='property_id', string='Offers') + + _check_name = models.Constraint('UNIQUE(name)', 'Property name must be unique') + _check_expected_price = models.Constraint('CHECK(expected_price > 0)', 'Expected price must be positive') + _check_selling_price = models.Constraint('CHECK(selling_price >= 0)', 'Selling price cannot be negative') + _check_bedrooms = models.Constraint('CHECK(bedrooms >= 0)', 'Bedrooms cannot be negative') + _check_living_area = models.Constraint('CHECK(living_area >= 0)', 'Living area cannot be negative') + _check_facades = models.Constraint('CHECK(facades >= 0)', 'Facades cannot be negative') + _check_garden_area = models.Constraint('CHECK(garden_area >= 0)', 'Garden area cannot be negative') + + @api.constrains('selling_price') + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, 2) and record.selling_price < 0.9 * record.expected_price: + raise ValidationError("Selling price cannot be lower than 90% of the expected price") + + @api.depends('garden_area', 'living_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.garden_area + record.living_area + + @api.depends('offer_ids') + def _compute_best_price(self): + for record in self: + record.best_price = max(record.offer_ids.mapped('price'), default=0.0) + + @api.onchange('garden') + def _onchange_garden(self): + for record in self: + record.garden_area = (10 if record.garden else 0) + record.garden_orientation = ('north' if record.garden else None) + + @api.ondelete(at_uninstall=False) + def _property_delete(self): + if self.state != 'new' and self.state != 'cancelled': + raise UserError("Cannot delete property with a state other than 'New' or 'Cancelled'") + self.offer_ids.unlink() + + def action_change_state_to_sold(self): + for record in self: + if record.state == 'cancelled': + raise UserError("This property was already cancelled") + if record.state != 'offer_accepted': + raise UserError("Please accept an offer before selling the property") + record.state = 'sold' + return True + + def action_change_state_to_cancelled(self): + for record in self: + if record.state == 'sold': + raise UserError("This property was already sold") + record.state = 'cancelled' + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..7be19177683 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,69 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = "An offer placed on some property" + _order = 'price desc' + + validity = fields.Integer(string='Validity (days)', default=7) + price = fields.Float(string='Price') + date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_compute_validity') + status = fields.Selection( + string='Status', + selection=[('accepted', 'Accepted'), ('refused', 'Refused')], + copy=False + ) + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', required=True) + property_type_id = fields.Many2one(comodel_name='estate.property.type', related='property_id.property_type_id', store=True) + + _check_price = models.Constraint('CHECK(price > 0)', 'Price must be positive') + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = fields.Date.add(record.create_date, days=record.validity) + + def _compute_validity(self): + for record in self: + if record.create_date and record.date_deadline: + record.validity = (record.date_deadline - fields.Date.to_date(record.create_date)).days + + @api.model_create_multi + def create(self, vals): + for offer in vals: + property_id = offer.get('property_id') + property = self.env['estate.property'].browse(property_id) + + if offer.get('price') <= max(property.mapped('best_price')): + raise UserError("The offer price must be higher than the previous offers") + if property.state == 'sold': + raise UserError("This property was already sold") + + if property.state == 'new': + property.state = 'offer_received' + return super().create(vals) + + def action_accept_offer(self): + for record in self: + if record.status == 'refused': + raise UserError("This offer was already refused") + if fields.Date.today() > record.date_deadline: + raise UserError("This offer has already expired") + if record.property_id.buyer_id: + raise UserError("An offer has already been accepted") + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + record.property_id.state = 'offer_accepted' + record.status = 'accepted' + return True + + def action_reject_offer(self): + for record in self: + if record.status == 'accepted': + raise UserError("This offer was already accepted") + record.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..37e76797896 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = "Real estate property tags" + _order = 'name' + + name = fields.Char(string='Name', required=True) + color = fields.Integer(string='Color') + + _check_name = models.Constraint('UNIQUE(name)', '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..59aaf992c75 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,20 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = "The types available for properties/real estates" + _order = 'name' + + name = fields.Char(string='Name', required=True) + sequence = fields.Integer(string='Sequence', default=1) + offer_count = fields.Integer(string='Offers Count', compute='_compute_offer_count') + property_ids = fields.One2many(comodel_name='estate.property', inverse_name='property_type_id') + offer_ids = fields.One2many(comodel_name='estate.property.offer', inverse_name='property_type_id') + + _check_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..bd4bd993e60 --- /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(comodel_name='estate.property', inverse_name='salesman_id', domain=['|', ('state', '=', 'new'), ('state', '=', 'offer_received')]) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..3eceb639cf8 --- /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_manager,access_estate_property_user,model_estate_property,estate_group_manager,1,1,1,1 +access_estate_property_agent,access_estate_property_user,model_estate_property,estate_group_user,1,1,1,0 +access_estate_property_type_manager,access_estate_property_type_user,model_estate_property_type,estate_group_manager,1,1,1,1 +access_estate_property_type_agent,access_estate_property_type_user,model_estate_property_type,estate_group_user,1,0,0,0 +access_estate_property_tag_manager,access_estate_property_tag_user,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_property_tag_agent,access_estate_property_tag_user,model_estate_property_tag,estate_group_user,1,0,0,0 +access_estate_property_offer_manager,access_estate_property_offer_user,model_estate_property_offer,estate_group_manager,1,1,1,1 +access_estate_property_offer_agent,access_estate_property_offer_user,model_estate_property_offer,estate_group_user,1,1,1,0 \ No newline at end of file diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..40b8c07da36 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,39 @@ + + + + Real Estate + + + + + Agent + + + + + Manager + + + + + Limit agents to only see or modify properties with no salesperson assigned + + + [ + '|', ('salesman_id', '=', user.id), + ('salesman_id', '=', False) + ] + + + Bypass for the managers to see all properties + + + [(1, '=', 1)] + + + Limit agents to only see or modify properties with a company that they work for + + + [('company_id', 'in', company_ids)] + + \ No newline at end of file diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..dfd37f0be11 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate diff --git a/estate/tests/test_estate.py b/estate/tests/test_estate.py new file mode 100644 index 00000000000..2ddacdbac2c --- /dev/null +++ b/estate/tests/test_estate.py @@ -0,0 +1,51 @@ +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class EstateTestCase(TransactionCase): + + @classmethod + def setUpClass(self): + super().setUpClass() + + self.properties = self.env['estate.property'].create([ + { + 'name': 'Test Villa', + 'expected_price': 15, + 'postcode': '12345', + 'bedrooms': 3, + } + ]) + + self.offers = self.env['estate.property.offer'].create([ + { + 'partner_id': self.env.ref('base.main_partner').id, + 'property_id': self.properties.id, + 'price': 14, + } + ]) + + def test_offer_sold_property(self): + self.offers.action_accept_offer() + + self.properties.action_change_state_to_sold() + + with self.assertRaises(UserError): + self.env['estate.property.offer'].create({ + 'partner_id': self.env.ref('base.main_partner').id, + 'property_id': self.properties.id, + 'price': 15, + }) + + def test_sell_with_no_accept(self): + with self.assertRaises(UserError): + self.properties.action_change_state_to_sold() + + def test_property_state(self): + self.offers.action_accept_offer() + + self.properties.action_change_state_to_sold() + + self.assertEqual(self.properties.state, 'sold') diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..36b2e44127b --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,35 @@ + + + + + + + + \ 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..aece4db1f51 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,40 @@ + + + real.estate.offer.list + estate.property.offer + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + Real Estate Types + estate.property.type + list,form + + \ 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..e722ff1ed4d --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,130 @@ + + + real.estate.list + estate.property + + + + + + + + + + + + + + + real.estate.form + estate.property + +
+
+
+ + +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + real.estate.kanban + estate.property + + + + + + +
+ Expected Price: + +
+
+ Best Offer: + +
+
+ Selling Price: + +
+ +
+
+
+
+
+ + + real.estate.search + estate.property + + + + + + + + + + + + + + + + Real Estates + estate.property + list,kanban,form + {"search_default_available": True} + +
\ No newline at end of file diff --git a/estate/views/res_user_views.xml b/estate/views/res_user_views.xml new file mode 100644 index 00000000000..f1f10520f4b --- /dev/null +++ b/estate/views/res_user_views.xml @@ -0,0 +1,14 @@ + + + res.users.view.form.inherit.estate + res.users + + + + + + + + + + \ No newline at end of file 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..f6245a07e54 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,12 @@ +{ + 'name': 'Real Estate Account', + 'category': 'Tutorials', + 'depends': [ + 'estate', + 'account', + ], + 'application': True, + 'installable': True, + 'author': 'Odoo S.A.', + 'license': 'AGPL-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..112e77c9801 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,34 @@ +from odoo import models, Command + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_change_state_to_sold(self): + try: + self.check_access('write') + except AccessError: + print("You aren't allowed to edit this!") + res = super().action_change_state_to_sold() + self.env['account.move'].sudo().create({ + 'partner_id': self.buyer_id.id, + 'move_type': 'out_invoice', + 'line_ids': [ + Command.create({ + 'name': self.name, + 'quantity': 1, + 'price_unit': self.selling_price + }), + Command.create({ + 'name': 'Administrative Fees', + 'quantity': 1, + 'price_unit': 100.00 + }), + Command.create({ + 'name': 'Additional Costs', + 'quantity': 1, + 'price_unit': 0.06 * self.selling_price + }), + ], + }) + return res