diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py
index a1cd72893d7..db032f909db 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/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js
new file mode 100644
index 00000000000..2e6c9ec4086
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.js
@@ -0,0 +1,94 @@
+import { Component, useState } from "@odoo/owl";
+import { registry } from "@web/core/registry";
+import { useService } from "@web/core/utils/hooks";
+import { Layout } from "@web/search/layout";
+import { DashboardItem } from "./dashboard_item";
+import { PieChart } from "./pie_chart";
+import { Dialog } from "@web/core/dialog/dialog";
+import { CheckBox } from "@web/core/checkbox/checkbox";
+import { _t } from "@web/core/l10n/translation";
+import { standardActionServiceProps } from "@web/webclient/actions/action_service";
+import { browser } from "@web/core/browser/browser";
+
+class AwesomeDashboard extends Component {
+ static template = "awesome_dashboard.AwesomeDashboard";
+ static components = { Layout, DashboardItem, PieChart };
+ static props = { ...standardActionServiceProps };
+
+ setup() {
+ this.items = registry.category("awesome_dashboard").getAll();
+ this.action = useService("action");
+ this.statistics = useState(useService("awesome_dashboard.statistic_service"));
+ this.dialog = useService("dialog");
+ this.state = useState({
+ disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
+ });
+
+ }
+
+
+ openConfiguration() {
+ this.dialog.add(ConfigurationDialog, {
+ items: this.items,
+ disabledItems: this.state.disabledItems,
+ onUpdateConfiguration: this.updateConfiguration.bind(this),
+ });
+ }
+
+ updateConfiguration(newDisabledItems) {
+ this.state.disabledItems = newDisabledItems;
+ }
+
+ openCustomerKanbanView() {
+ this.action.doAction('base.action_partner_form');
+ }
+
+ openLeads() {
+ this.action.doAction({
+ type: 'ir.actions.act_window',
+ name: _t('Journal Entry'),
+ target: 'current',
+ res_model: 'crm.lead',
+ views: [
+ [false, 'form'],
+ [false, 'list'],
+ ],
+ });
+ }
+}
+
+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),
+ }
+ }));
+ }
+
+ Apply() {
+ 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..4c179be977f
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.scss
@@ -0,0 +1,3 @@
+.o_dashboard {
+ background-color: #bb88bb
+}
\ 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..c4dccc45000
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item.js
new file mode 100644
index 00000000000..f73633a77e9
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item.js
@@ -0,0 +1,18 @@
+import { Component } from "@odoo/owl";
+
+export class DashboardItem extends Component {
+ static template = "awesome_dashboard.DashboardItem"
+ static props = {
+ slots: {
+ type: Object,
+ },
+
+ 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.xml b/awesome_dashboard/static/src/dashboard/dashboard_item.xml
new file mode 100644
index 00000000000..38acafdd791
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
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..6981f932323
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js
@@ -0,0 +1,68 @@
+import { NumberCard } from "./number_card";
+import { PieChartCard } from "./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);
+});
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard/number_card.js b/awesome_dashboard/static/src/dashboard/number_card.js
new file mode 100644
index 00000000000..d3bd9c0e4ef
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/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,
+ }
+ }
+}
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card.xml
new file mode 100644
index 00000000000..25ee80d7aca
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/number_card.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart.js
new file mode 100644
index 00000000000..cc73f32db80
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart.js
@@ -0,0 +1,35 @@
+import { loadJS } from "@web/core/assets";
+import { Component, onWillStart, onMounted, useRef, onPatched } from "@odoo/owl"
+
+export class PieChart extends Component {
+ static template = "awesome_dashboard.PieChart"
+ static props = {
+ data: Object
+ }
+
+ setup() {
+ this.canvasRef = useRef("canvas");
+ onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js"))
+ onMounted(() => this.renderChart())
+ onPatched(() => {
+ if (this.Chart) {
+ this.Chart.destroy();
+ }
+ this.renderChart();
+ });
+ }
+
+ renderChart() {
+ const labels = Object.keys(this.props.data)
+ const values = Object.values(this.props.data)
+ this.Chart = new Chart(this.canvasRef.el, {
+ type: "pie",
+ data: {
+ labels: labels,
+ datasets: [{
+ data: values,
+ }],
+ }
+ });
+ }
+}
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart.xml
new file mode 100644
index 00000000000..ede6a446441
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card.js
new file mode 100644
index 00000000000..a32f2e2b181
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart_card.js
@@ -0,0 +1,15 @@
+import { Component } from "@odoo/owl";
+import { PieChart } from "./pie_chart";
+
+export class PieChartCard extends Component {
+ static template = "awesome_dashboard.PieChartCard";
+ static components = { PieChart }
+ static props = {
+ title: {
+ type: String,
+ },
+ values: {
+ type: Object,
+ },
+ }
+}
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card.xml
new file mode 100644
index 00000000000..71f04da8bcc
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart_card.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/awesome_dashboard/static/src/dashboard/service.js b/awesome_dashboard/static/src/dashboard/service.js
new file mode 100644
index 00000000000..797072a93bf
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/service.js
@@ -0,0 +1,21 @@
+import { rpc } from "@web/core/network/rpc";
+import { registry } from "@web/core/registry";
+import { reactive } from "@odoo/owl";
+
+const statisticService = {
+ start() {
+ const statistics = reactive({ isReady: false });
+
+ async function loadData() {
+ const stat = await rpc("/awesome_dashboard/statistics");
+ Object.assign(statistics, stat, { isReady: true });
+ }
+
+ setInterval(loadData, 25 * 1000);
+ loadData()
+
+ return statistics
+ },
+}
+
+registry.category("services").add("awesome_dashboard.statistic_service", statisticService);
diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js
new file mode 100644
index 00000000000..a5bdc15e1e9
--- /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);
diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js
new file mode 100644
index 00000000000..52cdf4cc861
--- /dev/null
+++ b/awesome_owl/static/src/card/card.js
@@ -0,0 +1,21 @@
+import { Component, useState } from "@odoo/owl";
+
+
+export class Card extends Component {
+ static template = "awesome_owl.card";
+ static props = {
+ title: String,
+ slots: {
+ type: Object,
+ },
+ };
+
+ setup() {
+ this.state = useState({ isOpen: true });
+ }
+
+ toggleContent() {
+ this.state.isOpen = !this.state.isOpen;
+ console.log(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..c96ff3a4596
--- /dev/null
+++ b/awesome_owl/static/src/card/card.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js
new file mode 100644
index 00000000000..6f15e62af06
--- /dev/null
+++ b/awesome_owl/static/src/counter/counter.js
@@ -0,0 +1,20 @@
+import { Component, useState } from "@odoo/owl";
+
+
+export class Counter extends Component {
+ static template = "awesome_owl.counter";
+ static props = {
+ value: Number,
+ onChange: { type: Function, optional: true }
+ };
+ setup() {
+ this.state = useState({ value: this.props.value });
+ }
+ 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..9c3a6b58acc
--- /dev/null
+++ b/awesome_owl/static/src/counter/counter.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
Counter:
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/main.js b/awesome_owl/static/src/main.js
index 1aaea902b55..b78166ed913 100644
--- a/awesome_owl/static/src/main.js
+++ b/awesome_owl/static/src/main.js
@@ -4,7 +4,7 @@ import { Playground } from "./playground";
const config = {
dev: true,
- name: "Owl Tutorial"
+ name: "Owl Tutorial"
};
// Mount the Playground component when the document.body is ready
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js
index 4ac769b0aa5..50b03f8583d 100644
--- a/awesome_owl/static/src/playground.js
+++ b/awesome_owl/static/src/playground.js
@@ -1,5 +1,20 @@
-import { Component } from "@odoo/owl";
+import { Component, markup, useState } from "@odoo/owl";
+import { Counter } from "./counter/counter";
+import { Card } from "./card/card";
+import { TodoList } from "./todo/todo_list";
+
export class Playground extends Component {
static template = "awesome_owl.playground";
+ static components = { Counter, Card, TodoList };
+ static props = {};
+
+ title = markup("
title 1
")
+ content = markup(" some content
")
+ setup() {
+ this.state = useState({ counterSum: 2 });
+ }
+ sumIncrement() {
+ this.state.counterSum++
+ }
}
diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml
index 4fb905d59f9..dd27e8b8d69 100644
--- a/awesome_owl/static/src/playground.xml
+++ b/awesome_owl/static/src/playground.xml
@@ -3,8 +3,19 @@
- hello world
+ Hellow wolrd
+
+
+
+ Counter:
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/todo/todo_item.js b/awesome_owl/static/src/todo/todo_item.js
new file mode 100644
index 00000000000..45154633010
--- /dev/null
+++ b/awesome_owl/static/src/todo/todo_item.js
@@ -0,0 +1,20 @@
+import { Component } from "@odoo/owl";
+
+
+export class TodoItem extends Component {
+ static template = "awesome_owl.TodoItem";
+ static props = {
+ todo: Object,
+ toggleState: { type: Function, optional: true },
+ remove: { type: Function, optional: true },
+ };
+
+ toggleState() {
+ this.props.todo.isCompleted = !this.props.todo.isCompleted;
+ }
+
+ removeTodo() {
+ this.props.remove(this.props.todo.id);
+ }
+
+}
diff --git a/awesome_owl/static/src/todo/todo_item.xml b/awesome_owl/static/src/todo/todo_item.xml
new file mode 100644
index 00000000000..221717b8f5f
--- /dev/null
+++ b/awesome_owl/static/src/todo/todo_item.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/todo/todo_list.js b/awesome_owl/static/src/todo/todo_list.js
new file mode 100644
index 00000000000..80f32f63420
--- /dev/null
+++ b/awesome_owl/static/src/todo/todo_list.js
@@ -0,0 +1,39 @@
+import { Component, useState } from "@odoo/owl";
+import { useFocus } from "../utils";
+import { TodoItem } from "./todo_item";
+
+
+export class TodoList extends Component {
+ static template = "awesome_owl.TodoList";
+ static components = { TodoItem };
+ static props = {};
+
+ setup() {
+ this.todos = useState([]);
+ this.id = 1;
+ useFocus("input");
+
+ }
+
+ addTodo(input) {
+ if (input.keyCode !== 13 || input.target.value == "") {
+ return;
+ }
+
+ const todo = {
+ id: this.id,
+ description: input.target.value,
+ isCompleted: false,
+ }
+
+ this.todos.push(todo);
+ input.target.value = "";
+ this.id++;
+ }
+
+ removeTodo(idDelete) {
+ const todoIndex = this.todos.findIndex((todo) => todo.id === idDelete)
+ this.todos.splice(todoIndex, 1)
+ }
+
+}
\ No newline at end of file
diff --git a/awesome_owl/static/src/todo/todo_list.xml b/awesome_owl/static/src/todo/todo_list.xml
new file mode 100644
index 00000000000..10ed690d1f3
--- /dev/null
+++ b/awesome_owl/static/src/todo/todo_list.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js
new file mode 100644
index 00000000000..6446234e702
--- /dev/null
+++ b/awesome_owl/static/src/utils.js
@@ -0,0 +1,9 @@
+import { useRef, onMounted } from "@odoo/owl";
+
+
+export function useFocus(refName) {
+ const ref = useRef(refName);
+ onMounted(() => {
+ ref.el.focus();
+ });
+}
\ No newline at end of file
diff --git a/awesome_owl/views/templates.xml b/awesome_owl/views/templates.xml
index aa54c1a7241..830eb5c3481 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..e81365cc2df
--- /dev/null
+++ b/estate/__manifest__.py
@@ -0,0 +1,20 @@
+{
+ 'name': 'estate',
+ 'summary': 'test module',
+ 'depends': [
+ 'base'
+ ],
+ 'application': True,
+ 'installable': True,
+ 'author': 'Odoo S.A.',
+ 'data': [
+ 'security/ir.model.access.csv',
+ 'views/estate_property_views.xml',
+ 'views/estate_property_tag_views.xml',
+ 'views/estate_property_type_views.xml',
+ 'views/estate_property_offer_views.xml',
+ 'views/inherit_user_views.xml',
+ 'views/estate_menus.xml',
+ ],
+ 'license': 'LGPL-3',
+}
diff --git a/estate/models/__init__.py b/estate/models/__init__.py
new file mode 100644
index 00000000000..9a2189b6382
--- /dev/null
+++ b/estate/models/__init__.py
@@ -0,0 +1,5 @@
+from . import estate_property
+from . import estate_property_type
+from . import estate_property_tag
+from . import estate_property_offer
+from . import res_users
diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py
new file mode 100644
index 00000000000..386f8ef45b0
--- /dev/null
+++ b/estate/models/estate_property.py
@@ -0,0 +1,127 @@
+from dateutil.relativedelta import relativedelta
+
+from odoo import api, fields, models
+from odoo.tools import float_compare
+from odoo.exceptions import ValidationError, UserError
+
+
+class EstateProperty(models.Model):
+ _name = 'estate.property'
+ _description = "All property created"
+ _order = 'id desc'
+
+ name = fields.Char(required=True, string="Title")
+ description = fields.Text(string="Description")
+ postcode = fields.Char()
+ date_availability = fields.Date(default=lambda p: fields.Date.today() + relativedelta(months=3), copy=False,
+ string="Available Date")
+ expected_price = fields.Float(required=True, string="Expected Price")
+ selling_price = fields.Float(readonly=True, copy=False, string="Selling price")
+ bedrooms = fields.Integer(default=2)
+ living_area = fields.Integer(string="Living Area")
+ facades = fields.Integer(string="Facades")
+ garage = fields.Boolean(string="Garage")
+ garden = fields.Boolean(string="Garden")
+ active = fields.Boolean(default=True)
+ garden_area = fields.Integer(string="Garden Area", default=0)
+
+ property_type_id = fields.Many2one('estate.property.type', string="Property Type")
+ buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False)
+ salesperson_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user)
+
+ tag_ids = fields.Many2many('estate.property.tag')
+
+ offer_ids = fields.One2many(comodel_name='estate.property.offer', inverse_name='property_id', string="Offer")
+
+ garden_orientation = fields.Selection(
+ string="Garden Orientation",
+ selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")]
+ )
+
+ state = fields.Selection(
+ string="Status",
+ required=True,
+ default='new',
+ selection=[
+ ('new', "New"),
+ ('offer', "Offer"),
+ ('received', "Offer Received"),
+ ('accepted', "Offer Accepted"),
+ ('sold', "Sold"),
+ ('cancelled', "Cancelled"),
+ ]
+ )
+
+ total_area = fields.Float(compute='_compute_total_area')
+
+ best_price = fields.Float(compute='_compute_best_price')
+
+ _check_expected_price = models.Constraint(
+ 'CHECK(expected_price > 0)',
+ "The expected price must be strictly positive.",
+ )
+
+ _check_selling_price = models.Constraint(
+ 'CHECK(selling_price >= 0)',
+ "The selling price must be positive.",
+ )
+
+ @api.constrains('selling_price', 'expected_price')
+ def _check_sell_price(self):
+ for estate in self:
+ if len(estate.offer_ids) > 0 and float_compare(estate.selling_price, estate.expected_price * 0.9, 2) == -1:
+ raise ValidationError(self.env._("Put a higher price"))
+ return True
+
+ @api.depends('garden_area', 'living_area')
+ def _compute_total_area(self):
+ for estate in self:
+ estate.total_area = estate.garden_area + estate.living_area
+
+ @api.depends('offer_ids.price')
+ def _compute_best_price(self):
+ for estate in self:
+ prices = estate.offer_ids.filtered(lambda o: o.status != 'refused').mapped('price')
+ estate.best_price = max(prices) if len(prices) > 0 else 0
+
+ @api.onchange('garden')
+ def _onchange_garden(self):
+ self.garden_area = 5 * self.garden
+ self.garden_orientation = 'north' if self.garden else None
+
+ def action_cancel_sell(self):
+ for estate in self:
+ if estate.state == 'sold':
+ raise UserError(self.env._("Sold properties can not be canceled"))
+
+ estate.state = 'cancelled'
+ return True
+
+ def action_sell(self):
+ for estate in self:
+ if estate.state == 'cancelled':
+ raise UserError(self.env._("Cancelled properties can not be sell"))
+
+ estate.state = 'sold'
+ return True
+
+ def set_received(self):
+ for estate in self:
+ estate.state = 'received'
+ return True
+
+ def accepted_offer(self, offer):
+ for estate in self:
+ if offer.status == 'accepted':
+ estate.selling_price = offer.price
+ estate.buyer_id = offer.partner_id
+ estate.state = 'accepted'
+ return True
+
+ @api.model
+ def ondelete(self):
+ for property in self:
+ if property.state != 'new' or property.state != 'cancelled':
+ raise ValidationError(self.env._("Can only delete new or cancelled properties"))
+ return super().ondelete()
+
\ No newline at end of file
diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py
new file mode 100644
index 00000000000..3debb99d463
--- /dev/null
+++ b/estate/models/estate_property_offer.py
@@ -0,0 +1,66 @@
+from dateutil.relativedelta import relativedelta
+
+from odoo import api, fields, models
+from odoo.exceptions import ValidationError, UserError
+
+
+class EstatePropertyOffer(models.Model):
+ _name = 'estate.property.offer'
+ _description = "All property offer"
+ _order = 'price desc'
+
+ price = fields.Float()
+
+ property_id = fields.Many2one('estate.property', string="property", required=True, readonly=True)
+ partner_id = fields.Many2one('res.partner', string="partner", required=True)
+ property_type_id = fields.Many2one(related='property_id.property_type_id')
+
+ status = fields.Selection(
+ copy=False,
+ selection=[('accepted', "Accepted"), ('refused', "Refused")]
+ )
+
+ validity = fields.Integer(default=7)
+
+ date_deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline', string="Deadline")
+
+ _check_price = models.Constraint(
+ 'CHECK(price > 0)',
+ "The price must be strictly positive.",
+ )
+
+ @api.depends('validity')
+ def _compute_deadline(self):
+ for offer in self:
+ offer.date_deadline = fields.Date.today() + relativedelta(days=offer.validity)
+
+ def _inverse_deadline(self):
+ for offer in self:
+ offer.validity = relativedelta(offer.date_deadline, fields.Date.today()).days
+
+ def offer_cancel(self):
+ for offer in self:
+ if offer.status == 'accepted':
+ raise UserError(self.env._("You can not cancel an accepted offer"))
+ else:
+ offer.status = 'refused'
+ return True
+
+ def offer_accept(self):
+ for offer in self:
+ if offer.property_id.state != 'accepted':
+ offer.status = 'accepted'
+ offer.property_id.accepted_offer(offer)
+ else:
+ raise UserError(self.env._("There is already an accepted offer for %s.", offer.property_id.name))
+
+ return True
+
+ @api.model
+ def create(self, vals_list):
+ for vals in vals_list:
+ property = self.env['estate.property'].browse(vals['property_id'])
+ if vals['price'] < property.best_price:
+ raise ValidationError(self.env._("Can not create an offer lower than an existing offer"))
+ property.set_received()
+ return super().create(vals_list)
diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py
new file mode 100644
index 00000000000..ae19132bc34
--- /dev/null
+++ b/estate/models/estate_property_tag.py
@@ -0,0 +1,15 @@
+from odoo import fields, models
+
+
+class EstatePropertyTag(models.Model):
+ _name = 'estate.property.tag'
+ _description = "All property tag"
+ _order = 'name'
+
+ name = fields.Char(required=True)
+ color = fields.Integer(default=0)
+
+ _check_tag_name = models.Constraint(
+ 'UNIQUE (name)',
+ "The tag name must be unique."
+ )
diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py
new file mode 100644
index 00000000000..c9578ff174f
--- /dev/null
+++ b/estate/models/estate_property_type.py
@@ -0,0 +1,30 @@
+from odoo import api, fields, models
+
+
+class EstatePropertyType(models.Model):
+ _name = 'estate.property.type'
+ _description = "All property type e.g. House, Manor "
+ _order = 'sequence asc,name'
+
+ name = fields.Char(required=True)
+ sequence = fields.Integer(string="Sequence", default=1, help="Used to order stages. Lower is better.")
+
+ 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')
+
+ offer_count = fields.Integer(compute='_compute_ofer_count', string="Offer Count")
+
+ @api.depends('offer_ids')
+ def _compute_ofer_count(self):
+ for type in self:
+ type.offer_count = len(type.offer_ids)
+ return True
+
+ def action_estate_property_offer_view_by_type(self):
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'estate.property.offer',
+ 'name': self.env._("Offer"),
+ 'views': [(False, 'list')],
+ 'domain': [('property_type_id', '=', self.id)],
+ }
diff --git a/estate/models/res_users.py b/estate/models/res_users.py
new file mode 100644
index 00000000000..bdf42f2334a
--- /dev/null
+++ b/estate/models/res_users.py
@@ -0,0 +1,8 @@
+from odoo import fields, models
+
+
+class ResUsers(models.Model):
+ _inherit = ['res.users']
+ _name = 'res.users'
+
+ property_ids = fields.One2many(comodel_name='estate.property', inverse_name='salesperson_id', domain=['|', ('state', '=', 'new'), ('state', '=', 'received')])
diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv
new file mode 100644
index 00000000000..4c593ed42e4
--- /dev/null
+++ b/estate/security/ir.model.access.csv
@@ -0,0 +1,5 @@
+id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
+access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
+access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
+access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
+access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
\ No newline at end of file
diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml
new file mode 100644
index 00000000000..ac667f2c476
--- /dev/null
+++ b/estate/views/estate_menus.xml
@@ -0,0 +1,15 @@
+
+
+
+
\ 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..2b7f61b514b
--- /dev/null
+++ b/estate/views/estate_property_offer_views.xml
@@ -0,0 +1,36 @@
+
+
+
+ estate.property.offer.list
+ estate.property.offer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.offer.form
+ estate.property.offer
+
+
+
+
+
\ No newline at end of file
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml
new file mode 100644
index 00000000000..9d905954c51
--- /dev/null
+++ b/estate/views/estate_property_tag_views.xml
@@ -0,0 +1,19 @@
+
+
+
+ estate.property.tag.form
+ estate.property.tag
+
+
+
+
+
+
+ property tag
+ estate.property.tag
+ list,form
+
+
\ No newline at end of file
diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml
new file mode 100644
index 00000000000..aaa02412207
--- /dev/null
+++ b/estate/views/estate_property_type_views.xml
@@ -0,0 +1,40 @@
+
+
+
+ estate.property.type.form
+ estate.property.type
+
+
+
+
+
+
+ property type
+ 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..a1bcdbf3acc
--- /dev/null
+++ b/estate/views/estate_property_views.xml
@@ -0,0 +1,151 @@
+
+
+
+ estate.property.list
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.kanban
+ estate.property
+
+
+
+
+
+
+
+
+ expected price :
+
+
+
+
+ best price :
+
+
+
+ selling price :
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.form
+ estate.property
+
+
+
+
+
+
+ estate.property.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ properties
+ estate.property
+ list,form,kanban,search
+ {'search_default_availability': True}
+
+
\ No newline at end of file
diff --git a/estate/views/inherit_user_views.xml b/estate/views/inherit_user_views.xml
new file mode 100644
index 00000000000..33de1df8b17
--- /dev/null
+++ b/estate/views/inherit_user_views.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ 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..712e15ba90e
--- /dev/null
+++ b/estate_account/__manifest__.py
@@ -0,0 +1,11 @@
+{
+ 'name': 'estate_account',
+ 'summary': 'link between estate and accounting',
+ 'depends': [
+ 'estate',
+ 'account'
+ ],
+ 'installable': True,
+ 'author': 'Odoo S.A.',
+ 'license': 'LGPL-3',
+}
diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py
new file mode 100644
index 00000000000..5e1963c9d2f
--- /dev/null
+++ b/estate_account/models/__init__.py
@@ -0,0 +1 @@
+from . import estate_property
diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py
new file mode 100644
index 00000000000..7749c005a3e
--- /dev/null
+++ b/estate_account/models/estate_property.py
@@ -0,0 +1,29 @@
+from odoo import models, Command
+
+
+class EstateProperty(models.Model):
+ _inherit = ['estate.property']
+ _name = 'estate.property'
+
+ def action_sell(self):
+ result = super().set_sell()
+
+ for estate in self:
+ self.env['account.move'].create({
+ 'partner_id': estate.buyer_id.id,
+ 'move_type': 'out_invoice',
+ 'line_ids': [
+ Command.create({
+ 'name': self.env._("6% of the selling price"),
+ 'quantity': 1,
+ 'price_unit': 0.06 * estate.selling_price,
+ }),
+ Command.create({
+ 'name': self.env._("administrative fee"),
+ 'quantity': 1,
+ 'price_unit': 100,
+ }),
+ ]
+ })
+
+ return result