diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py
index 31406e8addb..59d70791d98 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.js
deleted file mode 100644
index 637fa4bb972..00000000000
--- a/awesome_dashboard/static/src/dashboard.js
+++ /dev/null
@@ -1,10 +0,0 @@
-/** @odoo-module **/
-
-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/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js
new file mode 100644
index 00000000000..ed77251f373
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.js
@@ -0,0 +1,97 @@
+/** @odoo-module **/
+
+import { Component, onWillStart, useState } from "@odoo/owl";
+import { registry } from "@web/core/registry";
+import { Layout } from "@web/search/layout";
+import { Dialog } from "@web/core/dialog/dialog";
+import { AwesomeDashboardItem } from "./dashboard_item/dashboard_item"
+import { useService } from "@web/core/utils/hooks";
+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, AwesomeDashboardItem}
+
+ setup() {
+ this.action = useService("action");
+ this.statistic = useState(useService("awesome_dashboard.statistics"))
+ this.items = registry.category("awesome_dashboard").getAll();
+ this.dialog = useService("dialog");
+ this.display = {
+ controlPanel: {},
+ };
+ this.state = useState({
+ disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
+ });
+ }
+
+ openCustomerView() {
+ this.action.doAction("base.action_partner_form");
+ }
+
+ openConfiguration() {
+ this.dialog.add(ConfigurationDialog, {
+ items: this.items,
+ disabledItems: this.state.disabledItems,
+ onUpdateConfiguration: this.updateConfiguration.bind(this),
+ })
+ }
+
+ updateConfiguration(newDisabledItems) {
+ this.state.disabledItems = newDisabledItems;
+ }
+
+ openLeads() {
+ this.action.doAction({
+ type: "ir.actions.act_window",
+ name: "All leads",
+ res_model: "crm.lead",
+ views: [
+ [false, "list"],
+ [false, "form"],
+ ],
+ });
+ }
+
+
+}
+
+
+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);
diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss
new file mode 100644
index 00000000000..90e1493325f
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.scss
@@ -0,0 +1,3 @@
+.o_dashboard {
+ background-color: grey;
+}
diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml
new file mode 100644
index 00000000000..4114bc55f9f
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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..2bb81caae09
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js
@@ -0,0 +1,22 @@
+/** @odoo-module **/
+
+import { Component } from "@odoo/owl";
+
+export class AwesomeDashboardItem extends Component {
+ static template = "awesome_dashboard.AwesomeDashboardItem";
+
+ static props = {
+ slots: {
+ type: Object,
+ shape: {
+ default: Object
+ },
+ },
+ size: {
+ type: Number,
+ default: 1,
+ optional: true,
+ },
+ };
+
+}
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..ec35c48d323
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
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..a8642967e34
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js
@@ -0,0 +1,67 @@
+/** @odoo-module **/
+
+import { NumberCard } from "./number_card/number_card"
+import { PieChartCard } from "./pie_chart_card/pie_chart_card"
+import { registry } from "@web/core/registry";
+
+export const items = [
+ {
+ id: "average_quantity",
+ description: "Average amount of t-shirt",
+ Component: NumberCard,
+ props: (data) => ({
+ title: "Average amount of t-shirt by order this month",
+ 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 'sent' or 'cancelled'",
+ value: data.average_time,
+ })
+ },
+ {
+ id: "number_new_orders",
+ description: "New orders this month",
+ Component: NumberCard,
+ props: (data) => ({
+ title: "Number of new orders this month",
+ value: data.nb_new_orders,
+ })
+ },
+ {
+ id: "cancelled_orders",
+ description: "Cancelled orders this month",
+ Component: NumberCard,
+ props: (data) => ({
+ title: "Number of cancelled orders this month",
+ value: data.nb_cancelled_orders,
+ })
+ },
+ {
+ id: "amount_new_orders",
+ description: "amount orders this month",
+ Component: NumberCard,
+ props: (data) => ({
+ title: "Total amount of new orders this month",
+ value: data.total_amount,
+ })
+ },
+ {
+ id: "pie_chart",
+ description: "Shirt orders by size",
+ Component: PieChartCard,
+ size: 2,
+ props: (data) => ({
+ title: "Shirt orders by size",
+ values: data.orders_by_size,
+ })
+ }
+]
+
+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..98122393699
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js
@@ -0,0 +1,11 @@
+import { Component} from "@odoo/owl";
+
+export class NumberCard extends Component {
+ static template = "awesome_dashboard.NumberCard";
+
+ static props = {
+ title: String,
+ value: 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..e5071bec301
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
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..e2ce48aed4d
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js
@@ -0,0 +1,45 @@
+import { loadJS } from "@web/core/assets";
+import { getColor } from "@web/core/colors/colors";
+import { Component, onWillStart, useRef, onMounted, onWillUnmount, onWillUpdateProps } from "@odoo/owl";
+
+export class PieChart extends Component {
+ static template = "awesome_dashboard.PieChart";
+ static props = {
+ label: String,
+ data: Object,
+ };
+
+ setup() {
+ this.canvasRef = useRef("canvas");
+ onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js"));
+ onMounted(() => {
+ this.renderChart();
+ });
+ onWillUpdateProps(() => {
+ this.chart.destroy()
+ 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,
+ },
+ ],
+ },
+ });
+ }
+}
\ 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..9be0991dcbc
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
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..3c532abae73
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js
@@ -0,0 +1,13 @@
+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: String,
+ values: Object,
+ };
+
+}
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.xml
new file mode 100644
index 00000000000..819f0c5000a
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.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
new file mode 100644
index 00000000000..2fc0873ae90
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/statistics_service.js
@@ -0,0 +1,22 @@
+import { registry } from "@web/core/registry";
+import { rpc } from "@web/core/network/rpc";
+import { reactive } from "@odoo/owl";
+
+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,10000);
+ loadData();
+
+ return statistics;
+
+ },
+};
+
+registry.category("services").add("awesome_dashboard.statistics", statisticsService);
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js
new file mode 100644
index 00000000000..06ae51de339
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard_loader.js
@@ -0,0 +1,15 @@
+/** @odoo-module */
+
+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_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..b8d1c45eb03
--- /dev/null
+++ b/awesome_owl/static/src/card/card.js
@@ -0,0 +1,26 @@
+import { Component, useState } from "@odoo/owl";
+
+export class Card extends Component {
+ static template = "my_module.Card";
+
+
+ setup() {
+ this.state = useState({ isToggled: true });
+ }
+
+ static props = {
+ title: {type: String},
+ slots: {
+ type: Object,
+ shape: { default:true },
+ },
+ }
+
+ toggle() {
+ this.state.isToggled = !this.state.isToggled;
+ if (this.props.onChange) {
+ this.props.onChange(this.state.isToggled);
+ }
+ }
+
+}
diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml
new file mode 100644
index 00000000000..ed065afc3e6
--- /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..7bf14855720
--- /dev/null
+++ b/awesome_owl/static/src/counter/counter.js
@@ -0,0 +1,23 @@
+import { Component, useState } from "@odoo/owl";
+
+export class Counter extends Component {
+ static template = "my_module.Counter";
+
+ static props = {
+ initialValue: { type: Number, optional: true, default: 0, validate: (value) => value >= 0 },
+ 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/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml
new file mode 100644
index 00000000000..66085c8102d
--- /dev/null
+++ b/awesome_owl/static/src/counter/counter.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js
index 657fb8b07bb..747cfba8da3 100644
--- a/awesome_owl/static/src/playground.js
+++ b/awesome_owl/static/src/playground.js
@@ -1,7 +1,21 @@
/** @odoo-module **/
-
-import { Component } from "@odoo/owl";
+import { Card } from "./card/card";
+import { Counter } from "./counter/counter";
+import { TodoList } from "./todolist/todolist";
+import { Component, useState, markup} from "@odoo/owl";
export class Playground extends Component {
static template = "awesome_owl.playground";
+
+ static components = {Counter,Card,TodoList}
+
+ setup() {
+ this.state = useState({ safe_title: markup("
some content
"), sum:0 });
+ }
+
+ incrementSum(){
+ this.state.sum++;
+ }
+
}
+
diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml
index 4fb905d59f9..792b60f9aee 100644
--- a/awesome_owl/static/src/playground.xml
+++ b/awesome_owl/static/src/playground.xml
@@ -1,9 +1,15 @@
-
+
+
+
- hello world
+ Counter sum :
+
+
+
+
diff --git a/awesome_owl/static/src/todolist/todoitem.js b/awesome_owl/static/src/todolist/todoitem.js
new file mode 100644
index 00000000000..5f110178a2e
--- /dev/null
+++ b/awesome_owl/static/src/todolist/todoitem.js
@@ -0,0 +1,29 @@
+import { Component } from "@odoo/owl";
+
+export class TodoItem extends Component {
+ static template = "my_module.TodoItem";
+
+ static props = {
+ todo: { type: Object,
+ shape: {
+ id: { type: Number, default: 0 },
+ description: { type: String, default: "" },
+ isCompleted: { type: Boolean, default: false },
+ }
+ },
+ toggleState: { type: Function, optional: true },
+ removeTodo: { type: Function, optional: true },
+
+ }
+
+ onChange() {
+ this.props.toggleState(this.props.todo.id);
+ }
+
+ onRemove() {
+ this.props.removeTodo(this.props.todo.id);
+ }
+
+
+
+}
diff --git a/awesome_owl/static/src/todolist/todoitem.xml b/awesome_owl/static/src/todolist/todoitem.xml
new file mode 100644
index 00000000000..25a42233df0
--- /dev/null
+++ b/awesome_owl/static/src/todolist/todoitem.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+ -
+
+
+
+
+
diff --git a/awesome_owl/static/src/todolist/todolist.js b/awesome_owl/static/src/todolist/todolist.js
new file mode 100644
index 00000000000..6867d3dbda1
--- /dev/null
+++ b/awesome_owl/static/src/todolist/todolist.js
@@ -0,0 +1,38 @@
+import { Component, useState, useRef, onMounted } from "@odoo/owl";
+import { TodoItem } from "./todoitem";
+
+export class TodoList extends Component {
+ static template = "my_module.TodoList";
+
+ static components = {TodoItem}
+
+ setup() {
+ this.todos = useState([]);
+ this.inputRef = useRef('focus-input');
+ onMounted(() => {
+ this.inputRef.el.focus()
+ });
+ }
+
+ toggleTodo(id) {
+ const todo = this.todos.find(todo => todo.id === id);
+ if (todo){
+ todo.isCompleted = !todo.isCompleted
+ }
+ }
+
+ removeTodo(id) {
+ const index = this.todos.findIndex(todo => todo.id === id);
+ if (index !== -1) {
+ this.todos.splice(index, 1);
+ }
+ }
+
+ addTodo(ev){
+ if (ev.keyCode === 13){
+ this.todos.push({id: this.todos.length + 1, description: ev.target.value.trim(), isCompleted: false})
+ ev.target.value = "" //reinit
+ }
+
+ }
+}
diff --git a/awesome_owl/static/src/todolist/todolist.xml b/awesome_owl/static/src/todolist/todolist.xml
new file mode 100644
index 00000000000..c57f129946e
--- /dev/null
+++ b/awesome_owl/static/src/todolist/todolist.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
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..4fa3963872c
--- /dev/null
+++ b/estate/__manifest__.py
@@ -0,0 +1,26 @@
+{
+ 'name': 'Real estate',
+ 'description': 'Real estate app',
+ 'category': 'Estate',
+ 'application': True,
+ # 'version': '18.0',
+ 'author': 'Nicolas Renard',
+ 'data': [
+ 'views/estate_property_views.xml',
+ 'views/estate_menus.xml',
+ 'views/estate_list_view.xml',
+ 'views/estate_form_view.xml',
+ 'views/estate_search.xml',
+ 'views/estate_offer_list_view.xml',
+ 'views/estate_offer_form_view.xml',
+ 'views/estate_type_form_view.xml',
+ 'views/estate_type_list_view.xml',
+ 'views/estate_tag_list_view.xml',
+ 'views/estate_kanban_view.xml',
+ 'views/res_users_view.xml',
+ 'security/ir.model.access.csv',
+ ],
+ 'assets': {
+ },
+ 'license': 'LGPL-3',
+}
diff --git a/estate/models/__init__.py b/estate/models/__init__.py
new file mode 100644
index 00000000000..c0917a3d550
--- /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 inherited_model
diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py
new file mode 100644
index 00000000000..e05e35b1aa1
--- /dev/null
+++ b/estate/models/estate_property.py
@@ -0,0 +1,106 @@
+from odoo import api, fields, models
+from odoo.exceptions import UserError, ValidationError
+from odoo.tools.float_utils import float_compare
+from dateutil.relativedelta import relativedelta
+
+
+class EstateProperty(models.Model):
+ _name = "estate.property"
+ _description = "Real estate properties"
+ _order = "id desc"
+
+ @api.ondelete(at_uninstall=False)
+ def _unlink_except_new_or_cancelled(self):
+ for property in self:
+ if property.state == 'new' or property.state == 'cancelled':
+ raise UserError("Can't delete a property that is new or cancelled!")
+
+ name = fields.Char("Estate name", required=True)
+ description = fields.Text("Description")
+ postcode = fields.Char("Postcode")
+ date_availability = fields.Date("Date availability", default=fields.Date.today() + relativedelta(months=3), copy=False)
+ expected_price = fields.Float("Expected price")
+ selling_price = fields.Float("Selling price", readonly=True, copy=False)
+ bedrooms = fields.Integer("Number of bedrooms", default=2)
+ living_area = fields.Integer("Living area (sqm)")
+ facades = fields.Integer("Facades")
+ garage = fields.Boolean("Garage")
+ garden = fields.Boolean("Garden")
+ garden_area = fields.Integer("Garden area")
+ garden_orientation = fields.Selection(
+ string='Garden orientation',
+ selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")],
+ help="This Type is used to tell the garden orientation for a property"
+ )
+ active = fields.Boolean("Active", default=True)
+ state = fields.Selection(
+ string='State',
+ selection=[('new', "New"), ('offer_received', "Offer received"), ('offer_accepted', "Offer Accepted"), ('sold', "Sold"), ('cancelled', "Canceled")],
+ help="This is the state of the property",
+ default="new",
+ required=True,
+ copy=False
+ )
+ property_type_id = fields.Many2one('estate.property.type')
+ salesperson_id = fields.Many2one('res.users')
+ buyer_id = fields.Many2one('res.partner')
+ tag_ids = fields.Many2many('estate.property.tag')
+ offers_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
+
+ total_area = fields.Integer(compute='_compute_total')
+ best_price = fields.Float(compute='_compute_best_price')
+
+ cancelled = fields.Boolean(default=False)
+ sold = fields.Boolean(default=False)
+
+ _sql_constraints = [
+ ('check_expected_price', 'CHECK(expected_price > 0)',
+ 'The expected price has to be > 0'),
+
+ ('check_selling_price', 'CHECK(selling_price >= 0)',
+ 'The selling price has to be >= 0')
+ ]
+
+ @api.depends('living_area', 'garden_area')
+ def _compute_total(self):
+ self.total_area = self.garden_area + self.living_area
+
+ @api.depends('offers_ids.price')
+ def _compute_best_price(self):
+ if self.offers_ids.mapped('price'):
+ self.best_price = max(self.offers_ids.mapped('price'))
+ else:
+ self.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 = None
+ self.garden_orientation = None
+
+ def action_sold(self):
+ for record in self:
+ if record.state != "cancelled":
+ record.state = "sold"
+ else:
+ raise UserError("You can't sold an house that has been cancelled")
+ if not record.offers_ids:
+ raise UserError("There are no offers on this property, thus it can't be sold")
+ return True
+
+ def action_cancel(self):
+ for record in self:
+ if record.state != "sold":
+ record.state = "cancelled"
+ else:
+ raise UserError("You can't cancel an house that has already been sold")
+ return True
+
+ @api.constrains('selling_price', 'expected_price')
+ def _check_selling_price(self):
+ for record in self:
+ if record.selling_price != 0 and float_compare(record.selling_price, record.expected_price * 0.9, precision_rounding=2) < 0:
+ raise ValidationError("The selling price must be equal or higher than 90% of the selling price.")
diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py
new file mode 100644
index 00000000000..8d7790121ea
--- /dev/null
+++ b/estate/models/estate_property_offer.py
@@ -0,0 +1,70 @@
+from odoo import fields, models, api
+from odoo.exceptions import UserError
+from dateutil.relativedelta import relativedelta
+
+
+class EstatePropertyOffer(models.Model):
+ _name = "estate.property.offer"
+ _description = "Real estate properties offers"
+ _order = "price desc"
+
+ @api.model_create_multi
+ def create(self, vals):
+ for val in vals:
+ val_property_id = val.get('property_id')
+ property = self.env['estate.property'].browse(val_property_id)
+ if property.state == 'new':
+ property.state = 'offer_received'
+ elif property.state == 'sold':
+ raise UserError("Can't create an offer on a solded property")
+ return super().create(vals)
+
+ price = fields.Float("Price", required=True)
+ status = fields.Selection(
+ string='Status',
+ selection=[('accepted', "Accepted"), ('refused', "Refused")],
+ help="This selection is used to tell whether buying offer is accepted or refused"
+ )
+ partner_id = fields.Many2one('res.partner')
+ property_id = fields.Many2one('estate.property')
+
+ validity = fields.Integer(default=7)
+ create_date = fields.Date(default=fields.Date.today())
+ date_deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_validity')
+
+ property_type_id = fields.Many2one(related='property_id.property_type_id', store=True)
+
+ _sql_constraints = [
+ ('check_offer_price', 'CHECK(price > 0)',
+ 'The offer price has to be > 0'),
+ ]
+
+ @api.depends('validity')
+ def _compute_deadline(self):
+ for record in self:
+ if record.create_date:
+ record.date_deadline = record.create_date + relativedelta(days=record.validity)
+ else:
+ record.date_deadline = fields.Date.today() + relativedelta(days=record.validity)
+
+ def _inverse_validity(self):
+ for record in self:
+ if record.create_date:
+ record.validity = (record.date_deadline - record.create_date).days
+ else:
+ record.date_deadline = (record.date_deadline - fields.Date.today()).days
+
+ def action_confirm_offer(self):
+ for record in self:
+ if not record.status:
+ record.status = 'accepted'
+ record.property_id.buyer_id = record.partner_id
+ record.property_id.selling_price = record.price
+ record.property_id.state = 'offer_accepted'
+ return True
+
+ def action_refuse_offer(self):
+ for record in self:
+ if not record.status:
+ 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..6dc59239dcf
--- /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 = "Real estate properties tags"
+ _order = "name"
+
+ name = fields.Char("Name", required=True)
+ color = fields.Integer("Color")
+
+ _sql_constraints = [
+ ('name_unique', 'unique(name)', 'Each 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..da56168854b
--- /dev/null
+++ b/estate/models/estate_property_type.py
@@ -0,0 +1,25 @@
+from odoo import fields, models, api
+
+
+class EstatePropertyType(models.Model):
+ _name = "estate.property.type"
+ _description = "Real estate properties types"
+ _order = "sequence, name"
+
+ name = fields.Char("Name", required=True)
+ property_ids = fields.One2many('estate.property', 'property_type_id')
+ sequence = fields.Integer("Sequence", default=1, help="Used to order stages. Lower is better.")
+
+ offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
+ offer_count = fields.Integer(compute='_compute_count')
+
+ _sql_constraints = [
+ ('name_unique', 'unique (name)', 'Each name must be unique.'),
+ ]
+
+ @api.depends('offer_ids')
+ def _compute_count(self):
+ self.offer_count = len(self.offer_ids)
+
+ def go_to_offer_button(self):
+ return True
diff --git a/estate/models/inherited_model.py b/estate/models/inherited_model.py
new file mode 100644
index 00000000000..45d9b8a2e6e
--- /dev/null
+++ b/estate/models/inherited_model.py
@@ -0,0 +1,9 @@
+from odoo import fields, models
+
+
+class InheritedModel(models.Model):
+ _inherit = "res.users"
+
+ property_ids = fields.One2many(comodel_name='estate.property',
+ inverse_name='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..7095505221f
--- /dev/null
+++ b/estate/security/ir.model.access.csv
@@ -0,0 +1,6 @@
+id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
+access_estate_property,estate_property,model_estate_property,base.group_user,1,1,1,1
+access_estate_property_type,estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
+access_estate_property_tag,estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
+access_estate_property_offer,estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
+
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..df98975472f
--- /dev/null
+++ b/estate/tests/test_estate.py
@@ -0,0 +1,40 @@
+from odoo.tests.common import TransactionCase
+from odoo.exceptions import UserError
+from odoo.tests import tagged
+
+
+# The CI will run these tests after all the modules are installed,
+# not right after installing the one defining it.
+@tagged('post_install', '-at_install')
+class EstateTestCase(TransactionCase):
+
+ @classmethod
+ def setUpClass(cls):
+ # add env on cls and many other things
+ super().setUpClass()
+
+ # create the data for each tests. By doing it in the setUpClass instead
+ # of in a setUp or in each test case, we reduce the testing time and
+ # the duplication of code.
+ cls.properties = cls.env['estate.property'].create({'name': 'test'})
+
+ def test_creation_area(self):
+ """Test that the total_area is computed like it should."""
+ self.properties.living_area = 20
+ self.assertRecordValues(self.properties, [
+ {'name': 'test', 'total_area': '20'},
+ ])
+
+ def test_create_offer_for_solded_property(self):
+ """Test that offers can't be create for solded properties."""
+ self.properties.state = 'sold'
+ with self.assertRaises(UserError, msg="Should not be able to create an offer for a sold property"):
+ self.env['estate.property.offer'].create({
+ 'property_id': self.properties.id,
+ 'price': 150000.0,
+ })
+
+ def test_sell_property_with_no_offers(self):
+ """Test that offers can't be create for solded properties."""
+ with self.assertRaises(UserError, msg="Should not be able to sell a property with no offers"):
+ self.properties.action_sold()
diff --git a/estate/views/estate_form_view.xml b/estate/views/estate_form_view.xml
new file mode 100644
index 00000000000..956bd7cf859
--- /dev/null
+++ b/estate/views/estate_form_view.xml
@@ -0,0 +1,58 @@
+
+
+
+ estate.property.form.list
+ estate.property
+
+
+
+
+
diff --git a/estate/views/estate_kanban_view.xml b/estate/views/estate_kanban_view.xml
new file mode 100644
index 00000000000..afc78f44f18
--- /dev/null
+++ b/estate/views/estate_kanban_view.xml
@@ -0,0 +1,34 @@
+
+
+
+ estate.kanban
+ estate.property
+
+
+
+
+
+
+
+
+ Expected price :
+
+
+
+ Best offer :
+
+
+
+ Selling Price:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_list_view.xml b/estate/views/estate_list_view.xml
new file mode 100644
index 00000000000..71f1af5cd57
--- /dev/null
+++ b/estate/views/estate_list_view.xml
@@ -0,0 +1,20 @@
+
+
+
+ estate.property.list
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml
new file mode 100644
index 00000000000..7ae61f2577b
--- /dev/null
+++ b/estate/views/estate_menus.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/estate/views/estate_offer_form_view.xml b/estate/views/estate_offer_form_view.xml
new file mode 100644
index 00000000000..3ee4460078b
--- /dev/null
+++ b/estate/views/estate_offer_form_view.xml
@@ -0,0 +1,20 @@
+
+
+
+ estate.offer.form.list
+ estate.property.offer
+
+
+
+
+
diff --git a/estate/views/estate_offer_list_view.xml b/estate/views/estate_offer_list_view.xml
new file mode 100644
index 00000000000..6cd9d0e9ccf
--- /dev/null
+++ b/estate/views/estate_offer_list_view.xml
@@ -0,0 +1,17 @@
+
+
+
+ estate.offer.list
+ estate.property.offer
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml
new file mode 100644
index 00000000000..539e70f9865
--- /dev/null
+++ b/estate/views/estate_property_views.xml
@@ -0,0 +1,28 @@
+
+
+
+ Properties
+ estate.property
+ list,form,kanban
+ {'search_default_active': True}
+
+
+
+ Property Types
+ estate.property.type
+ list,form
+
+
+
+ Property Tags
+ estate.property.tag
+ list,form
+
+
+
+ Property offer
+ estate.property.offer
+ list
+ [('property_type_id', '=', active_id)]
+
+
diff --git a/estate/views/estate_search.xml b/estate/views/estate_search.xml
new file mode 100644
index 00000000000..da242c602dd
--- /dev/null
+++ b/estate/views/estate_search.xml
@@ -0,0 +1,23 @@
+
+
+
+ estate.property.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_tag_list_view.xml b/estate/views/estate_tag_list_view.xml
new file mode 100644
index 00000000000..78764a78040
--- /dev/null
+++ b/estate/views/estate_tag_list_view.xml
@@ -0,0 +1,12 @@
+
+
+
+ estate.tag.list.view
+ estate.property.tag
+
+
+
+
+
+
+
diff --git a/estate/views/estate_type_form_view.xml b/estate/views/estate_type_form_view.xml
new file mode 100644
index 00000000000..627c276a33c
--- /dev/null
+++ b/estate/views/estate_type_form_view.xml
@@ -0,0 +1,35 @@
+
+
+
+ estate.type.form.view
+ estate.property.type
+
+
+
+
+
diff --git a/estate/views/estate_type_list_view.xml b/estate/views/estate_type_list_view.xml
new file mode 100644
index 00000000000..34f007665ee
--- /dev/null
+++ b/estate/views/estate_type_list_view.xml
@@ -0,0 +1,13 @@
+
+
+
+ estate.type.list.view
+ estate.property.type
+
+
+
+
+
+
+
+
diff --git a/estate/views/res_users_view.xml b/estate/views/res_users_view.xml
new file mode 100644
index 00000000000..cbb76ec435c
--- /dev/null
+++ b/estate/views/res_users_view.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ res.users.view
+ 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..4e48e0e6aee
--- /dev/null
+++ b/estate_account/__manifest__.py
@@ -0,0 +1,16 @@
+{
+ 'name': 'Real estate invoicing link',
+ 'description': 'Real estate app for invoicing link',
+ 'category': 'Estate',
+ 'application': True,
+ # 'version': '18.0',
+ 'author': 'Nicolas Renard',
+ 'depends': [
+ 'estate',
+ 'account',
+ ],
+ 'data': [
+ 'security/ir.model.access.csv',
+ ],
+ '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..621a1e15428
--- /dev/null
+++ b/estate_account/models/estate_property.py
@@ -0,0 +1,28 @@
+from odoo import Command, models
+
+
+class EstateProperty(models.Model):
+ _inherit = "estate.property"
+
+ def action_sold(self):
+ self._create_account_move()
+ return super().action_sold()
+
+ def _create_account_move(self):
+ for property in self:
+ self.env["account.move"].create({
+ "partner_id": property.buyer_id.id,
+ "move_type": "out_invoice",
+ "line_ids": [
+ Command.create({
+ 'name': f' 6 % Downpayment for {property.name} (total price: {property.selling_price})',
+ 'quantity': 1,
+ 'price_unit': property.selling_price * 0.06,
+ }),
+ Command.create({
+ 'name': "Admin Fees",
+ 'quantity': 1,
+ 'price_unit': 100,
+ })
+ ],
+ })
diff --git a/estate_account/security/ir.model.access.csv b/estate_account/security/ir.model.access.csv
new file mode 100644
index 00000000000..d9d6ba57cc5
--- /dev/null
+++ b/estate_account/security/ir.model.access.csv
@@ -0,0 +1,2 @@
+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