diff --git a/.gitignore b/.gitignore
index b6e47617de1..faa0263468d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker
.pyre/
+
+#launcher
+.vscode/
diff --git a/awesome_clicker/__manifest__.py b/awesome_clicker/__manifest__.py
index 56dc2f779b9..ac3134c8974 100644
--- a/awesome_clicker/__manifest__.py
+++ b/awesome_clicker/__manifest__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
{
- 'name': "Awesome Clicker",
+ 'name': 'Awesome Clicker',
'summary': """
Starting module for "Master the Odoo web framework, chapter 1: Build a Clicker game"
@@ -10,7 +10,7 @@
Starting module for "Master the Odoo web framework, chapter 1: Build a Clicker game"
""",
- 'author': "Odoo",
+ 'author': 'Odoo',
'website': "https://www.odoo.com/",
'category': 'Tutorials',
'version': '0.1',
diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py
index a1cd72893d7..d31fe4b6c11 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 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..ef4f452889f
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.js
@@ -0,0 +1,81 @@
+import { Component, useState } from "@odoo/owl";
+import { registry } from "@web/core/registry";
+import { Layout } from "@web/search/layout";
+import { useService } from "@web/core/utils/hooks";
+import { DashboardItem } from "./dashboard_item/dashboard_item";
+import { Dialog } from "@web/core/dialog/dialog";
+import { CheckBox } from "@web/core/checkbox/checkbox";
+import { browser } from "@web/core/browser/browser";
+
+class AwesomeDashboard extends Component {
+ static template = "awesome_dashboard.AwesomeDashboard";
+
+ static components = { Layout, DashboardItem };
+
+ setup() {
+ this.action = useService("action");
+ this.statistics = useState(useService("awesome_dashboard.statistics"));
+ this.items = registry.category("awesome_dashboard").getAll();
+ 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;
+ }
+
+ openCustomerView() {
+ this.action.doAction("base.action_partner_form");
+ }
+
+ openLeads() {
+ this.action.doAction({
+ type: "ir.actions.act_window",
+ name: "Lead",
+ res_model: "crm.lead",
+ views: [
+ [false, "form"],
+ [false, "list"],
+ ]
+ })
+ }
+}
+
+class ConfigurationDialog extends Component {
+ static template = "awesome_dashboard.ConfigurationDialog";
+ static components = { CheckBox, Dialog }
+ 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..ef30a37cb18
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.scss
@@ -0,0 +1,3 @@
+.o_dashboard {
+ background-color: paleturquoise;
+}
diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml
new file mode 100644
index 00000000000..8439d143401
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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..6dd67d6a4e2
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item/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,
+ 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..a0ba8116392
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_item/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..c7bdb4ed164
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js
@@ -0,0 +1,65 @@
+import { NumberCard } from "./number_card/number_card";
+import { PieChartCard } from "./pie_chart_card/pie_chart_card";
+import { registry } from "@web/core/registry";
+
+const items = [
+ {
+ id: "average_quantity",
+ description: "Average 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..ca8b584a334
--- /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..3a0713623fa
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js
new file mode 100644
index 00000000000..f78ac8a11ae
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js
@@ -0,0 +1,39 @@
+import { loadJS } from "@web/core/assets";
+import { Component, onWillStart, useRef, onMounted, onWillUnmount, onPatched } 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();});
+ onPatched(() => {
+ this.chart.destroy();
+ this.renderChart();
+ });
+ onWillUnmount(() => {this.chart.destroy();});
+ }
+
+ renderChart() {
+ const labels = Object.keys(this.props.data);
+ const data = Object.values(this.props.data);
+ this.chart = new Chart(this.canvasRef.el, {
+ type: "pie",
+ data: {
+ labels: labels,
+ datasets: [
+ {
+ label: this.props.label,
+ data: data,
+ },
+ ],
+ },
+ });
+ }
+}
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..99711839c96
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
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..4629e018f60
--- /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,
+ },
+ values: {
+ 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..58a6811c83a
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js
new file mode 100644
index 00000000000..67beafcd947
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard/statistics_service.js
@@ -0,0 +1,20 @@
+import { registry } from "@web/core/registry";
+import { reactive } from "@odoo/owl";
+import { rpc } from "@web/core/network/rpc";
+
+const statisticsService = {
+ start() {
+ const statistics = reactive({ isReady: false });
+
+ async function loadData() {
+ const updates = await rpc("/awesome_dashboard/statistics");
+ Object.assign(statistics, updates, { isReady: true });
+ }
+ loadData();
+ // setInterval(loadData, 5*1000);
+
+ return statistics;
+ },
+};
+
+registry.category("services").add("awesome_dashboard.statistics", statisticsService);
diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js
new file mode 100644
index 00000000000..7eed4bd16da
--- /dev/null
+++ b/awesome_dashboard/static/src/dashboard_loader.js
@@ -0,0 +1,10 @@
+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..bb56e025531
--- /dev/null
+++ b/awesome_owl/static/src/card/card.js
@@ -0,0 +1,22 @@
+import { Component, useState } from "@odoo/owl";
+
+export class Card extends Component {
+ static template = "awesome_owl.Card";
+ static props = {
+ title : String,
+ slots: {
+ type: Object,
+ shape: {
+ default: true
+ },
+ }
+ };
+
+ setup() {
+ this.state = useState({ isOpen: true });
+ }
+
+ toggleContent() {
+ this.state.isOpen = !this.state.isOpen;
+ }
+}
diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml
new file mode 100644
index 00000000000..f473dfbc1a2
--- /dev/null
+++ b/awesome_owl/static/src/card/card.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js
new file mode 100644
index 00000000000..58ae29905b7
--- /dev/null
+++ b/awesome_owl/static/src/counter/counter.js
@@ -0,0 +1,19 @@
+import { Component, useState } from "@odoo/owl";
+
+export class Counter extends Component {
+ static template = "awesome_owl.Counter";
+ static props = {
+ onChange: { type: Function, optional: true }
+ }
+
+ setup() {
+ this.state = useState({ value: 1 });
+ }
+
+ increment() {
+ this.state.value++;
+ if (this.props.onChange) {
+ this.props.onChange();
+ }
+ }
+}
diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml
new file mode 100644
index 00000000000..114da93cb83
--- /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..dddc5ec40b4 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_list/todo_list";
export class Playground extends Component {
static template = "awesome_owl.playground";
+
+ static components = { Counter, Card, TodoList };
+
+ setup(){
+ this.str1 = "
some content
";
+ this.str2 = markup("some content
");
+ this.sum = useState({ value: 2 });
+ }
+
+ incrementSum() {
+ this.sum.value++;
+ }
}
diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml
index 4fb905d59f9..25863a53b40 100644
--- a/awesome_owl/static/src/playground.xml
+++ b/awesome_owl/static/src/playground.xml
@@ -4,6 +4,20 @@
hello world
+
+
+
The sum is:
+
+
+
+ content of card 1
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/todo_list/todo_item.js b/awesome_owl/static/src/todo_list/todo_item.js
new file mode 100644
index 00000000000..9780002b56e
--- /dev/null
+++ b/awesome_owl/static/src/todo_list/todo_item.js
@@ -0,0 +1,22 @@
+import { Component } from "@odoo/owl";
+
+export class TodoItem extends Component {
+ static template = "awesome_owl.TodoItem";
+
+ static props = {
+ todo: {
+ type: Object,
+ shape: { id: Number, description: String, isCompleted: Boolean }
+ },
+ toggleState: Function,
+ removeTodo: Function,
+ };
+
+ onChange() {
+ this.props.toggleState(this.props.todo.id);
+ }
+
+ onRemove() {
+ this.props.removeTodo(this.props.todo.id);
+ }
+}
diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml
new file mode 100644
index 00000000000..5b8113dd3d1
--- /dev/null
+++ b/awesome_owl/static/src/todo_list/todo_item.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js
new file mode 100644
index 00000000000..8d8d768f954
--- /dev/null
+++ b/awesome_owl/static/src/todo_list/todo_list.js
@@ -0,0 +1,40 @@
+import { Component, useState } from "@odoo/owl";
+import { TodoItem } from "./todo_item";
+import { useAutofocus } from "../utils";
+
+export class TodoList extends Component {
+ static template = "awesome_owl.TodoList";
+
+ static components = { TodoItem };
+
+ setup() {
+ this.nextId=1;
+ this.todos = useState([]);
+ useAutofocus("input");
+ }
+
+ addTodo(ev){
+ if (ev.keyCode === 13 && ev.target.value != ""){
+ this.todos.push({
+ id: this.nextId++,
+ description: ev.target.value,
+ isCompleted: false
+ });
+ ev.target.value = "";
+ }
+ }
+
+ toggleTodo(todoId) {
+ const todo = this.todos.find((todo) => todo.id === todoId);
+ if (todo) {
+ todo.isCompleted = !todo.isCompleted;
+ }
+ }
+
+ removeTodo(todoId) {
+ const todoIndex = this.todos.findIndex((todo) => todo.id === todoId);
+ if (todoIndex >= 0) {
+ this.todos.splice(todoIndex, 1);
+ }
+ }
+}
diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml
new file mode 100644
index 00000000000..f137197a1d2
--- /dev/null
+++ b/awesome_owl/static/src/todo_list/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..a9b70206b9f
--- /dev/null
+++ b/awesome_owl/static/src/utils.js
@@ -0,0 +1,8 @@
+import { useRef, onMounted } from "@odoo/owl";
+
+export function useAutofocus(refName) {
+ const ref = useRef(refName);
+ onMounted(() => {
+ ref.el.focus();
+ });
+}
diff --git a/estate/__init__.py b/estate/__init__.py
new file mode 100644
index 00000000000..0650744f6bc
--- /dev/null
+++ b/estate/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/estate/__manifest__.py b/estate/__manifest__.py
new file mode 100644
index 00000000000..8e2147d0582
--- /dev/null
+++ b/estate/__manifest__.py
@@ -0,0 +1,21 @@
+{
+ 'name': 'Real Estate',
+ 'version': '1.0',
+ 'summary': 'Real Estate Property Management',
+ 'description': 'Tutorial module for managing real estate properties.',
+ 'author': 'Ester Andreetto',
+ 'category': 'Tutorial',
+ 'depends': ['base'],
+ 'data': [
+ 'security/ir.model.access.csv',
+ 'views/res_users_views.xml',
+ 'views/estate_property_offer_views.xml',
+ 'views/estate_property_tag_views.xml',
+ 'views/estate_property_type_views.xml',
+ 'views/estate_property_views.xml',
+ 'views/estate_menus.xml'
+ ],
+ 'installable': True,
+ 'application': True,
+ '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..30e7eda91cc
--- /dev/null
+++ b/estate/models/estate_property.py
@@ -0,0 +1,105 @@
+from dateutil.relativedelta import relativedelta
+from odoo import api, fields, models
+from odoo.tools.float_utils import float_is_zero
+from odoo.exceptions import UserError, ValidationError
+
+
+class EstateProperty(models.Model):
+ _name = 'estate.property'
+ _description = 'Real Estate Property'
+ _order = 'id desc'
+
+ name = fields.Char(required=True)
+ description = fields.Text()
+ postcode = fields.Char()
+ date_availability = fields.Date(copy=False, default=lambda self: fields.Date.context_today(self) + relativedelta(months=3))
+ expected_price = fields.Float(required=True)
+ selling_price = fields.Float(readonly=True, copy=False)
+ bedrooms = fields.Integer(default=2)
+ living_area = fields.Integer()
+ facades = fields.Integer()
+ garage = fields.Boolean()
+ garden = fields.Boolean()
+ garden_area = fields.Integer()
+ garden_orientation = fields.Selection(
+ selection=[
+ ('north', 'North'),
+ ('south', 'South'),
+ ('east', 'East'),
+ ('west', 'West'),
+ ]
+ )
+ state = fields.Selection(
+ [
+ ('new', 'New'),
+ ('offer_received', 'Offer Received'),
+ ('offer_accepted', 'Offer Accepted'),
+ ('sold', 'Sold'),
+ ('canceled', 'Cancelled'),
+ ], required=True, copy=False, default='new')
+ active = fields.Boolean(default=True)
+ 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', string='Property Tag')
+ offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers')
+ total_area = fields.Integer(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_selling_price(self):
+ for record in self:
+ if float_is_zero(record.selling_price, precision_digits=2):
+ continue
+ if record.selling_price < record.expected_price * 0.9:
+ raise ValidationError('The selling price cannot be lower than 90% of the expected price.')
+
+ @api.depends('garden_area', 'total_area')
+ def _compute_total_area(self):
+ for record in self:
+ record.total_area = record.garden_area + record.living_area
+
+ @api.depends('offer_ids.price')
+ def _compute_best_price(self):
+ for record in self:
+ prices = record.offer_ids.mapped('price')
+ record.best_price = max(prices, default=0.0)
+
+ @api.onchange('garden')
+ def _onchange_garden(self):
+ if self.garden:
+ self.garden_area = 10
+ self.garden_orientation = 'north'
+ else:
+ self.garden_area = 0
+ self.garden_orientation = False
+
+ @api.ondelete(at_uninstall=False)
+ def _unlink_if_new_or_cancelled(self):
+ for record in self:
+ if record.state not in ('new', 'cancelled'):
+ raise UserError('You can only delete a property when its state is New or Cancelled.')
+
+ def action_sold(self):
+ for record in self:
+ if record.state == 'canceled':
+ raise UserError('A canceled property cannot be set as sold.')
+ record.state = 'sold'
+ return True
+
+ def action_cancel(self):
+ for record in self:
+ if record.state == 'sold':
+ raise UserError('A sold property cannot be canceled.')
+ record.state = 'canceled'
+ return True
diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py
new file mode 100644
index 00000000000..bf09127b89d
--- /dev/null
+++ b/estate/models/estate_property_offer.py
@@ -0,0 +1,82 @@
+from odoo import api, fields, models
+from datetime import timedelta
+from odoo.exceptions import UserError
+
+
+class EstatePropertyOffer(models.Model):
+ _name = 'estate.property.offer'
+ _description = 'Estate Property Offer'
+ _order = 'price desc'
+
+ partner_id = fields.Many2one('res.partner', string='Partner', required=True)
+ property_id = fields.Many2one('estate.property', string='Estate Property', required=True)
+ price = fields.Float()
+ status = fields.Selection(
+ copy=False,
+ selection=[
+ ('accepted', 'Accepted'),
+ ('refused', 'Refused'),
+ ]
+ )
+ property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', store=True, readonly=True)
+ validity = fields.Integer(default=7)
+ date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', store=True)
+
+ _check_offer_price = models.Constraint(
+ 'CHECK(price > 0)',
+ 'The offer price must be strictly positive.',
+ )
+
+ @api.depends('create_date', 'validity')
+ def _compute_date_deadline(self):
+ for offer in self:
+ create_dt = offer.create_date if offer.create_date else fields.Datetime.now()
+ offer.date_deadline = (create_dt + timedelta(days=offer.validity)).date()
+
+ def _inverse_date_deadline(self):
+ for offer in self:
+ if offer.date_deadline:
+ create_date = offer.create_date.date() if offer.create_date else fields.Datetime.now()
+ offer.validity = (offer.date_deadline - create_date).days
+
+ def action_confirm(self):
+ for offer in self:
+ if offer.property_id.state in ('offer_accepted', 'sold', 'canceled'):
+ raise UserError('A sold property cannot accept new offers.')
+
+ offer.status = 'accepted'
+
+ offer.property_id.write({
+ 'buyer_id': offer.partner_id.id,
+ 'selling_price': offer.price,
+ 'state': 'offer_accepted',
+ })
+
+ return True
+
+ def action_refuse(self):
+ for offer in self:
+ if offer.status == 'accepted':
+ raise UserError('You cannot refuse an accepted offer.')
+
+ offer.status = 'refused'
+ property_record = offer.property_id
+ active_offers = property_record.offer_ids.filtered(lambda o: o.status in ('pending', 'accepted'))
+
+ if not active_offers:
+ property_record.write({
+ 'buyer_id': False,
+ 'selling_price': 0,
+ 'state': 'new',
+ })
+
+ return True
+
+ @api.model_create_multi
+ def create(self, vals_list):
+ for vals in vals_list:
+ if vals['property_id'] and vals['price'] is not None:
+ if vals['price'] < self.env['estate.property'].browse(vals['property_id']).best_price:
+ raise UserError('The offer must be higher than the existing offers.')
+ self.env['estate.property'].browse(vals['property_id']).state = 'offer_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..f7ef24cf5f9
--- /dev/null
+++ b/estate/models/estate_property_tag.py
@@ -0,0 +1,10 @@
+from odoo import fields, models
+
+
+class EstatePropertyTag(models.Model):
+ _name = 'estate.property.tag'
+ _description = 'Estate Property Tag'
+ _order = 'name'
+
+ name = fields.Char(required=True)
+ color = fields.Integer(name="Color")
diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py
new file mode 100644
index 00000000000..5a080c26857
--- /dev/null
+++ b/estate/models/estate_property_type.py
@@ -0,0 +1,24 @@
+from odoo import api, fields, models
+
+
+class EstatePropertyType(models.Model):
+ _name = 'estate.property.type'
+ _description = 'Estate Property Type'
+ _order = 'name'
+
+ name = fields.Char(required=True)
+ sequence = fields.Integer('Sequence', default=1)
+
+ _unique_type_name = models.Constraint(
+ 'UNIQUE(name)',
+ 'The property type name must be unique.',
+ )
+
+ property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
+ offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers')
+ offer_count = fields.Integer(compute='_compute_offer_count', string='Offer Count')
+
+ @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..8acea9ae096
--- /dev/null
+++ b/estate/models/res_users.py
@@ -0,0 +1,6 @@
+from odoo import fields, models
+
+class ResUsers(models.Model):
+ _inherit = 'res.users'
+
+ property_ids = fields.One2many('estate.property', 'salesperson_id', string='Properties', domain=[('state', 'in', ['new', 'offer_received'])])
diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv
new file mode 100644
index 00000000000..0c0b62b7fee
--- /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
+estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
+estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
+estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
+estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1
diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml
new file mode 100644
index 00000000000..4b9ce3396f3
--- /dev/null
+++ b/estate/views/estate_menus.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml
new file mode 100644
index 00000000000..abfa0f20888
--- /dev/null
+++ b/estate/views/estate_property_offer_views.xml
@@ -0,0 +1,45 @@
+
+
+
+ estate.property.offer.view.list
+ estate.property.offer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.offer.view.form
+ estate.property.offer
+
+
+
+
+
+
+ Offers From Types
+ estate.property.offer
+ list,form
+ [('property_type_id', '=', active_id)]
+
+
+
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml
new file mode 100644
index 00000000000..af3eeaf2663
--- /dev/null
+++ b/estate/views/estate_property_tag_views.xml
@@ -0,0 +1,18 @@
+
+
+
+ Property Tag
+ estate.property.tag
+ list,form
+
+
+
+ estate.property.tag.view.list
+ estate.property.tag
+
+
+
+
+
+
+
diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml
new file mode 100644
index 00000000000..e459251d047
--- /dev/null
+++ b/estate/views/estate_property_type_views.xml
@@ -0,0 +1,58 @@
+
+
+
+ Property Type
+ estate.property.type
+ list,form
+
+
+
+ estate.property.type.view.list
+ estate.property.type
+
+
+
+
+
+
+
+
+
+ estate.property.type.view.form
+ estate.property.type
+
+
+
+
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml
new file mode 100644
index 00000000000..85544ec7043
--- /dev/null
+++ b/estate/views/estate_property_views.xml
@@ -0,0 +1,158 @@
+
+
+
+
+ estate.property.view.list
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.view.form
+ estate.property
+
+
+
+
+
+
+ estate.property.view.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.kanban
+ estate.property
+
+
+
+
+
+
+
+
+
+
+ This is new!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Properties
+ estate.property
+ list,form,kanban
+ {'search_default_available': 1}
+
+
+
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml
new file mode 100644
index 00000000000..83417593df4
--- /dev/null
+++ b/estate/views/res_users_views.xml
@@ -0,0 +1,24 @@
+
+
+
+
+ res.users.view.form.inherit.estate.property
+ 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..d975ba0e958
--- /dev/null
+++ b/estate_account/__manifest__.py
@@ -0,0 +1,12 @@
+{
+ 'name': 'Accounting for Real Estate',
+ 'version': '1.0',
+ 'description': 'Link invoices between estate and account modules.',
+ 'author': 'Ester Andreetto',
+ 'category': 'Tutorial',
+ 'depends': ['estate', 'account'],
+ 'data': [],
+ 'installable': True,
+ 'application': True,
+ 'license': 'LGPL-3',
+}
diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py
new file mode 100644
index 00000000000..02b688798a3
--- /dev/null
+++ b/estate_account/models/__init__.py
@@ -0,0 +1 @@
+from . import estate_account
diff --git a/estate_account/models/estate_account.py b/estate_account/models/estate_account.py
new file mode 100644
index 00000000000..a98127b96ae
--- /dev/null
+++ b/estate_account/models/estate_account.py
@@ -0,0 +1,30 @@
+from odoo import models, Command
+from odoo.exceptions import UserError
+
+class EstateAccount(models.Model):
+ _inherit = 'estate.property'
+
+ def action_sold(self):
+ journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1)
+ if not journal:
+ raise UserError(
+ 'No Sales Journal found for your company. Create one in Invoicing > Configuration > Journals.')
+
+ for record in self:
+ invoice = {'partner_id': record.buyer_id.id,
+ 'move_type': 'out_invoice',
+ 'journal_id': journal.id,
+ 'line_ids': [
+ Command.create({
+ 'name': record.name,
+ 'quantity': 1,
+ 'price_unit': record.selling_price * 0.06,
+ }),
+ Command.create({
+ 'name': 'Fixed fees',
+ 'quantity': 1,
+ 'price_unit': 100.00,
+ })
+ ]}
+ self.env['account.move'].create(invoice)
+ return super().action_sold()