diff --git a/.gitignore b/.gitignore index b6e47617de1..58710ec238a 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# VS Code +.vscode \ No newline at end of file diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..c5b63b98530 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -25,6 +25,9 @@ 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*', + ], }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/controllers/controllers.py b/awesome_dashboard/controllers/controllers.py index 56d4a051287..ab12c1acdfc 100644 --- a/awesome_dashboard/controllers/controllers.py +++ b/awesome_dashboard/controllers/controllers.py @@ -4,10 +4,11 @@ import random from odoo import http -from odoo.http import request +# from odoo.http import request logger = logging.getLogger(__name__) + class AwesomeDashboard(http.Controller): @http.route('/awesome_dashboard/statistics', type='json', auth='user') def get_statistics(self): @@ -33,4 +34,3 @@ def get_statistics(self): }, 'total_amount': random.randint(100, 1000) } - 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/card/number_card.js b/awesome_dashboard/static/src/dashboard/card/number_card.js new file mode 100644 index 00000000000..7dbe11671cb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/card/number_card.js @@ -0,0 +1,9 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.number_card"; + static props = { + title: { type: String }, + data: { type: Number } + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/card/number_card.xml b/awesome_dashboard/static/src/dashboard/card/number_card.xml new file mode 100644 index 00000000000..57e7466f14e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/card/number_card.xml @@ -0,0 +1,13 @@ + + + + +
+
+

+ +

+
+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/card/pie_chart_card.js new file mode 100644 index 00000000000..e14086eb359 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/card/pie_chart_card.js @@ -0,0 +1,11 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../pie_chart/pie_chart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.pie_chart_card"; + static components = { PieChart }; + static props = { + title: { type: String }, + data: { type: Object }, + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/card/pie_chart_card.xml new file mode 100644 index 00000000000..15451757c87 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/card/pie_chart_card.xml @@ -0,0 +1,11 @@ + + + + +
+
+ +
+
+ +
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..9de6e817ff2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,79 @@ +import { Component, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; +import { registry } from "@web/core/registry"; +import { browser } from "@web/core/browser/browser"; + +import { Layout } from "@web/search/layout"; +import { DashboardItem } from "./dashboard_item/dashboard_item"; +import { PieChart } from "./pie_chart/pie_chart"; +import { DashboardDialog } from "./dialog/dialog"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.dashboard"; + static components = { Layout, DashboardItem, PieChart }; + + setup() { + this.display = { + controlPanel: {} + }; + + this.action = useService("action"); + this.dialog = useService("dialog"); + + this.statisticsService = useService("awesome_dashboard.statistics"); + + this.statistics = useState(this.statisticsService.statistics); + this.items = registry.category("awesome_dashboard").getAll(); + + this.storageKey = ["awesome_dashboard_item"]; + this.setupActiveDashboardItem(); + }; + + openCustomers() { + this.action.doAction("base.action_partner_form"); + } + + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + name: "Leads", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + target: "current", + }); + } + + openDialog() { + this.dialog.add(DashboardDialog, { + items: this.items, + activeDashboardItem: this.activeDashboardItem, + storageKey: this.storageKey, + }); + } + + get activeItems() { + return this.items.filter( + (item) => this.activeDashboardItem[item.id] + ); + } + + setupActiveDashboardItem() { + const activeDashboardItemList = browser.localStorage.getItem(this.storageKey)?.split(","); + + this.activeDashboardItem = useState({}); + for (const item of this.items) { + if (activeDashboardItemList) { + this.activeDashboardItem[item.id] = activeDashboardItemList.includes( + item.id.toString() + ); + } else { + this.activeDashboardItem[item.id] = true; + } + } + } +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..aa380c4834d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,18 @@ +.o_dashboard { + background-color: gray; + overflow-y: auto; +} + +.pie-chart-container { + width: 100%; + aspect-ratio: 1 / 1; + max-width: 350px; + margin: 0 auto; +} + +.pie-chart-container canvas { + display: block; + width: 100% !important; + height: 100% !important; + max-width: 100% !important; +} \ 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..31003c4f6f7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + +
+
+ +
+ + + + +
+
+
+
+
+
+ +
\ No newline at end of file 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..d930062f2a5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,12 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.dashboard_item"; + static props = { + size: { optional: true}, + slots: { optional: true } + }; + static defaultProps = { + size: 1 + }; +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..b7bb0ee0835 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,12 @@ + + + + +
+
+ +
+
+
+ +
\ 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..e6298ef645b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,65 @@ +import { registry } from "@web/core/registry"; +import { NumberCard } from "./card/number_card"; +import { PieChartCard } from "./card/pie_chart_card"; + +const items = [ + { + id: "avg_amount", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + data: data.average_quantity, + }), + }, + { + id: "avg_time", + description: "Average time for an order to go", + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + data: data.average_time, + }), + }, + { + id: "new_order", + description: "Number of new orders", + Component: NumberCard, + props: (data) => ({ + title: "Number of new orders this month", + data: data.nb_new_orders, + }), + }, + { + id: "cancelled_order", + description: "Number of cancelled orders", + Component: NumberCard, + props: (data) => ({ + title: "Number of cancelled orders this month", + data: data.nb_cancelled_orders, + }), + }, + { + id: "total_order", + description: "Total amount of new orders", + Component: NumberCard, + props: (data) => ({ + title: "Total amount of new orders this month", + data: data.total_amount, + }), + }, + { + id: "order_by_size", + description: "Shirt orders by size", + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: "Shirt orders by size", + data: 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/dialog/dialog.js b/awesome_dashboard/static/src/dashboard/dialog/dialog.js new file mode 100644 index 00000000000..8beb96b0880 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dialog/dialog.js @@ -0,0 +1,26 @@ +import { Component } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { Dialog } from "@web/core/dialog/dialog"; + +export class DashboardDialog extends Component { + static template = "awesome_dashboard.dialog"; + static components = { CheckBox, Dialog }; + static props = [ "title", "items", "storageKey", "activeDashboardItem" ]; + + setup() { + this.items = this.props.items; + this.storageKey = this.props.storageKey; + this.activeDashboardItem = this.props.activeDashboardItem; + } + + toggleActiveItem(itemId) { + this.activeDashboardItem[itemId] = !this.activeDashboardItem[itemId]; + browser.localStorage.setItem( + this.storageKey.join(","), + Object.keys(this.activeDashboardItem).filter( + (itemId) => this.activeDashboardItem[itemId] + ) + ); + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dialog/dialog.xml b/awesome_dashboard/static/src/dashboard/dialog/dialog.xml new file mode 100644 index 00000000000..38946838984 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dialog/dialog.xml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js new file mode 100644 index 00000000000..2118634b880 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,56 @@ +import { Component, onWillStart, onMounted, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + +export class PieChart extends Component { + static template = "awesome_dashboard.pie_chart"; + static props = { + data: { type: Object } + }; + + chart = null; + + setup() { + this.chartRef = useRef("pieChartCanvas"); + // Lazy load + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + this.shouldRenderChart = true; + }); + + onMounted(() => { + if (this.shouldRenderChart && window.Chart) { + this.renderChart(); + } else { + console.warn("Chart.js not loaded, skipping render."); + } + }); + } + + renderChart() { + const ctx = this.chartRef.el.getContext("2d"); + + if (this.chart) { + this.chart.destroy(); + } + this.chart = new window.Chart(ctx, { + type: "pie", + data: { + labels: Object.keys(this.props.data), + datasets: [{ + data: Object.values(this.props.data), + backgroundColor: [ + "#42A5F5", "#66BB6A", "#AB47BC" + ], + }] + }, + options: { + responsive: false, + plugins: { + legend: { + position: "bottom" + } + } + } + }); + } +} \ 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..9c4828b0c87 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/services/dashboard_statistics_service.js b/awesome_dashboard/static/src/dashboard/services/dashboard_statistics_service.js new file mode 100644 index 00000000000..d35949f5351 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/services/dashboard_statistics_service.js @@ -0,0 +1,27 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +export const statisticsService = { + dependencies: [], + start() { + const statistics = reactive({}); + + async function loadStatistics() { + const result = await rpc("/awesome_dashboard/statistics"); + + Object.keys(statistics).forEach((k) => delete statistics[k]); + Object.assign(statistics, result); + } + + loadStatistics(); + setInterval(loadStatistics, 600_000); + + return { + statistics, + reload: loadStatistics, + }; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..ad191ce2856 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,12 @@ +import { Component, xml } from "@odoo/owl"; +import { LazyComponent } from "@web/core/assets"; +import { registry } from "@web/core/registry"; + +export class DashboardComponentLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; +} + +registry.category("actions").add("awesome_dashboard.dashboard", DashboardComponentLoader); \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..3c570c8f934 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,16 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static props = ["title", "slots"]; + static template = "awesome_owl.card"; + + setup() { + this.state = useState({ + isOpen: false, + }); + } + + toggle() { + this.state.isOpen = !this.state.isOpen; + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..f55492b182f --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,52 @@ + + + + +
+
+
+
+ + +
+ +

+ +

+
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..fca5db1af2f --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,18 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static props = ["onChange?"]; + static template = "awesome_owl.counter"; + + setup() { + this.state = useState({ value: 1}); + } + + increment() { + this.state.value++; + + if (this.props.onChange) { + this.props.onChange(); + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..29bf8404d52 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,38 @@ + + + + +
+

Counter:

+ +
+
+ +
diff --git a/awesome_owl/static/src/main.js b/awesome_owl/static/src/main.js index 1af6c827e0b..1ba7b61f346 100644 --- a/awesome_owl/static/src/main.js +++ b/awesome_owl/static/src/main.js @@ -1,6 +1,6 @@ import { whenReady } from "@odoo/owl"; import { mountComponent } from "@web/env"; -import { Playground } from "./playground"; +import { Playground } from "./playground/playground"; const config = { dev: true, diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js deleted file mode 100644 index 657fb8b07bb..00000000000 --- a/awesome_owl/static/src/playground.js +++ /dev/null @@ -1,7 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; - -export class Playground extends Component { - static template = "awesome_owl.playground"; -} diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml deleted file mode 100644 index 4fb905d59f9..00000000000 --- a/awesome_owl/static/src/playground.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - -
- hello world -
-
- -
diff --git a/awesome_owl/static/src/playground/playground.js b/awesome_owl/static/src/playground/playground.js new file mode 100644 index 00000000000..37626ceb4f0 --- /dev/null +++ b/awesome_owl/static/src/playground/playground.js @@ -0,0 +1,24 @@ +/** @odoo-module **/ + +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 }; + + setup() { + this.state = useState({ + sum: 2 + }); + + this.title1 = "Card 1"; + this.title2 = "Card 2"; + } + + incrementSum() { + this.state.sum++; + } +} diff --git a/awesome_owl/static/src/playground/playground.xml b/awesome_owl/static/src/playground/playground.xml new file mode 100644 index 00000000000..25c110e7748 --- /dev/null +++ b/awesome_owl/static/src/playground/playground.xml @@ -0,0 +1,36 @@ + + + + +
+
+ hello world +
+ + + +
+ The sum is: +
+ + + + + + + +
some other content
+
+
+
+ +
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..ac85691e2c9 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,15 @@ +import { Component, useState } from "@odoo/owl"; +import { useAutoFocus } from "../utils/utils"; + +export class TodoItem extends Component { + static props = ["todo", "toggleState", "removeTodo"]; + static template = "awesome_owl.todo_item"; + + change() { + this.props.toggleState(this.props.todo.id); + } + + remove() { + this.props.removeTodo(this.props.todo.id); + } +} \ No newline at end of file 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..5bed0b51a1d --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,29 @@ + + + + +
+ +

+ . +

+ +
+
+ +
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..6ba60064156 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,42 @@ +import { Component, useState, useRef, onMounted } from "@odoo/owl"; +import { TodoItem } from "./todo_item"; +import { useAutoFocus } from "../utils/utils"; + +export class TodoList extends Component { + static template = "awesome_owl.todo_list"; + static components = { TodoItem }; + + setup() { + this.state = useState({ + todos: [] + }); + + this.inputRef = useAutoFocus("todo_input"); + + this.idCount = 0; + } + + addTodo(ev) { + const description = ev.target.value.trim(); + if (ev.keyCode === 13 && description) { + const newTodo = { + id: this.idCount++, + description: description, + isCompleted: false + }; + this.state.todos.push(newTodo); + ev.target.value = ""; + } + } + + toggleState(id) { + const todo = this.state.todos.find(todo => todo.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(id) { + this.state.todos = this.state.todos.filter(todo => todo.id !== id); + } +} \ 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..c570f0fe656 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,29 @@ + + + + +
+ + + + +
+
+ +
diff --git a/awesome_owl/static/src/utils/utils.js b/awesome_owl/static/src/utils/utils.js new file mode 100644 index 00000000000..c4c38b119e2 --- /dev/null +++ b/awesome_owl/static/src/utils/utils.js @@ -0,0 +1,13 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutoFocus(refName = "input") { + const inputRef = useRef(refName); + + onMounted(() => { + if (inputRef.el) { + inputRef.el.focus(); + } + }); + + return inputRef; +} \ No newline at end of file diff --git a/case_data_access/__init__.py b/case_data_access/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/case_data_access/__manifest__.py b/case_data_access/__manifest__.py new file mode 100644 index 00000000000..6f83ed5d923 --- /dev/null +++ b/case_data_access/__manifest__.py @@ -0,0 +1,14 @@ +{ + 'name': 'Case Study: Data Access', + 'category': 'Sales/Sales', + 'depends': [ + 'sale', + 'sales_team', + ], + 'application': True, + 'installable': True, + 'data': [ + 'security/sales_team_security.xml' + ], + 'license': 'AGPL-3', +} diff --git a/case_data_access/security/sales_team_security.xml b/case_data_access/security/sales_team_security.xml new file mode 100644 index 00000000000..7b11f6b9a39 --- /dev/null +++ b/case_data_access/security/sales_team_security.xml @@ -0,0 +1,17 @@ + + + + Sales Team Leader + + + the user will have access to all of his own team's data in the sales application + + + + Sales Team Leader Rule + + + + [('team_id.id', '=', user.sale_team_id.id)] + + \ No newline at end of file diff --git a/case_javascript/__init__.py b/case_javascript/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/case_javascript/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/case_javascript/__manifest__.py b/case_javascript/__manifest__.py new file mode 100644 index 00000000000..4eaa4535294 --- /dev/null +++ b/case_javascript/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': 'Case Study: Javascript', + 'depends': [ + 'point_of_sale', + ], + 'application': True, + 'installable': True, + 'data': [ + 'views/pos_config_views.xml' + ], + 'assets': { + 'point_of_sale._assets_pos': [ + 'case_javascript/static/src/**/*', + ] + }, + 'license': 'AGPL-3', +} diff --git a/case_javascript/models/__init__.py b/case_javascript/models/__init__.py new file mode 100644 index 00000000000..39c258af875 --- /dev/null +++ b/case_javascript/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_product +from . import pos_config diff --git a/case_javascript/models/pos_config.py b/case_javascript/models/pos_config.py new file mode 100644 index 00000000000..e3982f7b17a --- /dev/null +++ b/case_javascript/models/pos_config.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + congratulatory_text = fields.Char( + string='Congratulatory Text', + default='Congratulations!') diff --git a/case_javascript/models/product_product.py b/case_javascript/models/product_product.py new file mode 100644 index 00000000000..62ac8c932dd --- /dev/null +++ b/case_javascript/models/product_product.py @@ -0,0 +1,19 @@ +from odoo import models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def get_product_info_pos(self, price, quantity, pos_config_id): + product_info = super().get_product_info_pos( + price, + quantity, + pos_config_id) + + product_info.update( + weight=self.weight, + weight_uom_name=self.weight_uom_name, + volume=self.volume, + volume_uom_name=self.volume_uom_name + ) + return product_info diff --git a/case_javascript/static/src/order_receipt.xml b/case_javascript/static/src/order_receipt.xml new file mode 100644 index 00000000000..6c6f6f24ebb --- /dev/null +++ b/case_javascript/static/src/order_receipt.xml @@ -0,0 +1,12 @@ + + + + + +
+

+
+
+
+ +
\ No newline at end of file diff --git a/case_javascript/static/src/pos_store.js b/case_javascript/static/src/pos_store.js new file mode 100644 index 00000000000..5f3dd0b5156 --- /dev/null +++ b/case_javascript/static/src/pos_store.js @@ -0,0 +1,11 @@ +import { patch } from "@web/core/utils/patch"; +import { PosStore } from "@point_of_sale/app/store/pos_store"; + +patch(PosStore.prototype, { + getReceiptHeaderData(order) { + return { + ...super.getReceiptHeaderData(...arguments), + congratulatory_text: this.config.congratulatory_text, + } + } +}); \ No newline at end of file diff --git a/case_javascript/static/src/product_info_popup.xml b/case_javascript/static/src/product_info_popup.xml new file mode 100644 index 00000000000..9fb5297fd9a --- /dev/null +++ b/case_javascript/static/src/product_info_popup.xml @@ -0,0 +1,24 @@ + + + + + +
+

Logistics

+
+ + + + + + + + + +
Weight:
Volume:
+
+
+
+
+ +
\ No newline at end of file diff --git a/case_javascript/static/src/product_screen.js b/case_javascript/static/src/product_screen.js new file mode 100644 index 00000000000..13faa58efbb --- /dev/null +++ b/case_javascript/static/src/product_screen.js @@ -0,0 +1,10 @@ +import { patch } from "@web/core/utils/patch"; +import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; + +patch(ProductScreen.prototype, { + onRemoveClick() { + if (this.currentOrder.get_selected_orderline()) { + this.currentOrder.removeOrderline(this.currentOrder.get_selected_orderline()); + } + } +}); \ No newline at end of file diff --git a/case_javascript/static/src/product_screen.xml b/case_javascript/static/src/product_screen.xml new file mode 100644 index 00000000000..1aa46b8147c --- /dev/null +++ b/case_javascript/static/src/product_screen.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/case_javascript/views/pos_config_views.xml b/case_javascript/views/pos_config_views.xml new file mode 100644 index 00000000000..eef2c78780b --- /dev/null +++ b/case_javascript/views/pos_config_views.xml @@ -0,0 +1,17 @@ + + + + + pos.config.view.form.inherit.case_javascript + pos.config + + + + + + + + + + + \ No newline at end of file diff --git a/case_report/__init__.py b/case_report/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/case_report/__manifest__.py b/case_report/__manifest__.py new file mode 100644 index 00000000000..d145d15c59c --- /dev/null +++ b/case_report/__manifest__.py @@ -0,0 +1,13 @@ +{ + 'name': 'Case Study: Report', + 'depends': [ + 'account', + 'contacts' + ], + 'data': [ + 'report/contacts_templates.xml', + 'report/contacts_reports.xml', + 'report/account_invoice_templates.xml', + ], + 'license': 'AGPL-3' +} diff --git a/case_report/report/account_invoice_templates.xml b/case_report/report/account_invoice_templates.xml new file mode 100644 index 00000000000..884f7f419f7 --- /dev/null +++ b/case_report/report/account_invoice_templates.xml @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/case_report/report/contacts_reports.xml b/case_report/report/contacts_reports.xml new file mode 100644 index 00000000000..bb87aa755ca --- /dev/null +++ b/case_report/report/contacts_reports.xml @@ -0,0 +1,12 @@ + + + + Contacts + res.partner + qweb-pdf + case_report.contacts_report_template + case_report.contacts_report_template + 'Contacts - %s' % (object.name or 'Contact').replace('/','') + + + \ No newline at end of file diff --git a/case_report/report/contacts_templates.xml b/case_report/report/contacts_templates.xml new file mode 100644 index 00000000000..31d462cf572 --- /dev/null +++ b/case_report/report/contacts_templates.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file 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..3e01ef51900 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,32 @@ +{ + 'name': 'Real Estate', + 'category': 'Real Estate/Brokerage', + 'depends': [ + 'base', + ], + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + + 'report/estate_property_offer_templates.xml', + 'report/estate_property_templates.xml', + 'report/estate_property_reports.xml', + 'report/res_users_templates.xml', + 'report/res_users_reports.xml', + + 'data/estate.property.type.csv', + ], + 'demo': [ + 'demo/estate_property_demo.xml', + 'demo/estate_property_offer_demo.xml', + ], + 'application': True, + 'license': 'AGPL-3' +} diff --git a/estate/data/estate.property.type.csv b/estate/data/estate.property.type.csv new file mode 100644 index 00000000000..2a4a2c20f76 --- /dev/null +++ b/estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +id,name +estate_property_type_residential, Residential +estate_property_type_commercial, Commercial +estate_property_type_industrial, Industrial +estate_property_type_land, Land \ No newline at end of file diff --git a/estate/demo/estate_property_demo.xml b/estate/demo/estate_property_demo.xml new file mode 100644 index 00000000000..5be4bd4de89 --- /dev/null +++ b/estate/demo/estate_property_demo.xml @@ -0,0 +1,87 @@ + + + + Big Villa + new + A nice and big villa + 12345 + 2020-02-02 + 1600000 + 6 + 100 + 4 + True + True + 100000 + south + + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 120000 + 1 + 10 + 4 + False + + + + + Biomedical Campus + new + Empty office with King Odoo inside + 23456 + 2002-04-04 + 5000000 + 0 + 900 + 0 + False + + + + + + International Space Station + new + Aliens sometimes come visit + ---- + 2030-12-31 + 45890000 + + + + + + Cozy Cabin + new + Small cabin by lake + 10000 + 2020-01-01 + 80000 + 1 + 10 + 4 + False + True + + + + \ No newline at end of file diff --git a/estate/demo/estate_property_offer_demo.xml b/estate/demo/estate_property_offer_demo.xml new file mode 100644 index 00000000000..a7600b864ec --- /dev/null +++ b/estate/demo/estate_property_offer_demo.xml @@ -0,0 +1,53 @@ + + + + + + + 10000 + + + + + + + 1500000 + + + + + + + 1500001 + + + + + + + + + + + + + + 60000 + 14 + + + + + + + 75000 + 14 + + + + + + + + + \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9a2189b6382 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..efa742faf80 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,137 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class Property(models.Model): + _name = "estate.property" + _description = "Estate Property" + _order = "id desc" + _sql_constraints = [ + ('expected_price_positive', + 'CHECK(expected_price > 0)', + 'The expected price must be strictly positive.'), + ('selling_price_positive', + 'CHECK(selling_price >= 0)', + 'The selling price must be positive.') + ] + + # misc + name = fields.Char(string='Title', required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date( + string='Available From', + default=fields.Date.add(fields.Date.today(), months=3), copy=False) + + # price + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + + # area + bedrooms = fields.Integer(default=2) + living_area = fields.Integer(string='Living Area (sqm)') + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer(string='Garden Area (sqm)') + garden_orientation = fields.Selection([ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West')]) + + # reserved + active = fields.Boolean(default=True) + state = fields.Selection([ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled')], + string="Status", required=True, default='new', copy=False) + + # many2one + property_type_id = fields.Many2one('estate.property.type', + string='Property Type') + salesman = fields.Many2one('res.users', default=lambda self: self.env.user) + buyer = fields.Many2one('res.partner', copy=False) + company_id = fields.Many2one('res.company', + string='Company', + default=lambda self: self.env.company, + required=True) + + # many2many + tag_ids = fields.Many2many('estate.property.tag', string='Tags') + + # one2many + offer_ids = fields.One2many('estate.property.offer', + 'property_id', + string='Offers') + + # computed + total_area = fields.Integer(compute='_compute_total_area', + string='Total Area (sqm)') + best_offer = fields.Float(compute='_compute_best_offer') + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends('offer_ids') + def _compute_best_offer(self): + for record in self: + record.best_offer = max(record.offer_ids.mapped('price'), + default=0) + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price_margin(self): + for record in self: + if float_is_zero(record.selling_price, precision_rounding=0.01): + continue + + min_price = record.expected_price * 0.9 + if float_compare(record.selling_price, min_price, + precision_rounding=0.01) < 0: + raise ValidationError( + 'The selling price must be at least' + ' 90% of the selling price!' + 'You must reduce the expected price ' + 'if you want to accept this offer.') + + @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_only_for_new_or_cancelled(self): + for record in self: + if record.state not in ('new', 'cancelled'): + raise UserError( + 'Only new and cancelled properties can be deleted.') + + def action_sell_property(self): + for record in self: + if record.state == 'cancelled': + raise UserError('Cancelled property cannot be sold.') + + if not any( + offer.status == 'accepted' for offer in record.offer_ids): + raise UserError('There is no accepted offer.') + + record.state = 'sold' + return True + + def action_cancel_property(self): + for record in self: + if record.state == 'sold': + raise UserError('Sold property cannot be cancelled.') + + record.state = 'cancelled' + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..a9d7bec882d --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,90 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class PropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Estate Property Offer" + _order = "price desc" + _sql_constraints = [ + ('price_positive', + 'CHECK(price > 0)', + 'The offer price must be strictly positive.' + ) + ] + + # misc + price = fields.Float() + status = fields.Selection([ + ('accepted', 'Accepted'), + ('refused', 'Refused')], + copy=False) + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', required=True) + + # computed + validity = fields.Integer(string='Validity (days)', default=7) + date_deadline = fields.Date(compute='_compute_date_deadline', + inverse='_inverse_date_deadline', + string='Deadline') + property_type_id = fields.Many2one(related="property_id.property_type_id") + + @api.depends('validity') + def _compute_date_deadline(self): + for record in self: + safe_create_date = record.create_date or fields.Date.today() + record.date_deadline = fields.Date.add(safe_create_date, + days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + safe_create_date = record.create_date or fields.Date.today() + delta = ( + record.date_deadline - fields.Date.to_date(safe_create_date)) + record.validity = delta.days + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_id = vals.get('property_id') + new_price = vals.get('price', 0.0) + + if property_id: + property = self.env['estate.property'].browse(property_id) + + if property.state == 'sold': + raise UserError( + 'The property %s is already sold.' % property.name + ) + + max_offer = max(property.offer_ids.mapped('price'), + default=0.0) + if new_price < max_offer: + raise ValidationError( + ('The offer cannot be lower than %.2f.') % max_offer + ) + + if property.state == 'new': + property.state = 'offer_received' + + return super().create(vals_list) + + def action_accept_offer(self): + for record in self: + # refuse other offers + other_offers = self.search([ + ('property_id', '=', record.property_id.id), + ('id', '!=', record.id) + ]) + other_offers.write({'status': 'refused'}) + + record.property_id.selling_price = record.price + record.property_id.buyer = record.partner_id + record.property_id.state = 'offer_accepted' + record.status = 'accepted' + return True + + def action_refuse_offer(self): + for record in self: + 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..351a6313ba6 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,17 @@ +from odoo import fields, models + + +class PropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Estate Property Tag" + _order = "name" + _sql_constraints = [ + ('name_unique', + 'UNIQUE(name)', + 'The property tag name must be unique.' + ) + ] + + # misc + name = fields.Char(required=True) + color = fields.Integer(string='Color') diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..5ac421643fd --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,33 @@ +from odoo import api, fields, models + + +class PropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate Property Type" + _order = "sequence, name" + _sql_constraints = [ + ('name_unique', + 'UNIQUE(name)', + 'The property type name must be unique.') + ] + + # misc + name = fields.Char(string='Type', required=True) + sequence = fields.Integer(string='Sequence') + + # one2many + property_ids = fields.One2many('estate.property', + 'property_type_id', + string='Properties') + offer_ids = fields.One2many('estate.property.offer', + 'property_type_id', + string='Offers') + + # computed + offer_count = fields.Integer(compute='_compute_offer_count', + string='Offer Counts') + + @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..cf9063a567a --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,12 @@ +from odoo import models, fields + + +class Users(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', + 'salesman', + string='Properties', + domain=['|', ('state', '=', 'new'), ('state', '=', 'offer_received')] + ) diff --git a/estate/report/estate_property_offer_templates.xml b/estate/report/estate_property_offer_templates.xml new file mode 100644 index 00000000000..741c665098b --- /dev/null +++ b/estate/report/estate_property_offer_templates.xml @@ -0,0 +1,43 @@ + + + + \ No newline at end of file diff --git a/estate/report/estate_property_reports.xml b/estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..7af4019595f --- /dev/null +++ b/estate/report/estate_property_reports.xml @@ -0,0 +1,12 @@ + + + + Properties + estate.property + qweb-pdf + estate.estate_property_report_template + estate.estate_property_report_template + 'Property Offers - %s' % (object.name or 'Property').replace('/','') + + + \ No newline at end of file diff --git a/estate/report/estate_property_templates.xml b/estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..31d2d76ce7b --- /dev/null +++ b/estate/report/estate_property_templates.xml @@ -0,0 +1,29 @@ + + + + \ No newline at end of file diff --git a/estate/report/res_users_reports.xml b/estate/report/res_users_reports.xml new file mode 100644 index 00000000000..291a913730a --- /dev/null +++ b/estate/report/res_users_reports.xml @@ -0,0 +1,12 @@ + + + + Real Estate Properties + res.users + qweb-pdf + estate.res_users_report_template + estate.res_users_report_template + 'Real Estate Properties - %s' % (object.partner_id.name or 'Users').replace('/','') + + + \ No newline at end of file diff --git a/estate/report/res_users_templates.xml b/estate/report/res_users_templates.xml new file mode 100644 index 00000000000..721da9b658f --- /dev/null +++ b/estate/report/res_users_templates.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..36b6e2d0b43 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property,estate_property,model_estate_property,estate_group_user,1,1,1,0 +access_user_estate_property_type,user_estate_property_type,model_estate_property_type,estate_group_user,1,0,0,0 +access_manager_estate_property_type,manager_estate_property_type,model_estate_property_type,estate_group_manager,1,1,1,1 +access_user_estate_property_tag,user_estate_property_tag,model_estate_property_tag,estate_group_user,1,0,0,0 +access_manager_estate_property_tag,manager_estate_property_tag,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_property_offer,estate_property_offer,model_estate_property_offer,estate_group_user,1,1,1,1 diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..cb3f16f5bbc --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,31 @@ + + + + Agent + + + + + Manager + + + + + + Agent Rule + + + [ + '|', '&', + ('salesman', '=', user.id), ('salesman', '=', False), + ('company_id', 'in', company_ids) + ] + + + + Manager Rule + + + [(1, '=', 1)] + + \ No newline at end of file diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..d6724ad4c71 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_estate_property +from . import test_estate_property_offer diff --git a/estate/tests/common.py b/estate/tests/common.py new file mode 100644 index 00000000000..2eda93e8c31 --- /dev/null +++ b/estate/tests/common.py @@ -0,0 +1,42 @@ +from odoo.tests import TransactionCase + + +class TestEstateCommon(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + # PARTNER + cls.partner = cls.env['res.partner'].create({ + 'name': 'Test Partner' + }) + + # PROPERTIES + cls.property_offer_received = cls.env['estate.property'].create({ + 'name': 'Test Property Offer Received', + 'expected_price': 100000, + 'state': 'offer_received' + }) + cls.property_offer_accepted = cls.env['estate.property'].create({ + 'name': 'Test Property Offer Accepted', + 'expected_price': 200000, + 'state': 'offer_accepted' + }) + cls.property_cancelled = cls.env['estate.property'].create({ + 'name': 'Test Property Cancelled', + 'expected_price': 200000, + 'state': 'cancelled' + }) + + # OFFERS + cls.offer = cls.env['estate.property.offer'].create({ + 'property_id': cls.property_offer_received.id, + 'partner_id': cls.partner.id, + 'price': 110000 + }) + cls.offer_accepted = cls.env['estate.property.offer'].create({ + 'property_id': cls.property_offer_accepted.id, + 'partner_id': cls.partner.id, + 'price': 220000, + 'status': 'accepted' + }) diff --git a/estate/tests/test_estate_property.py b/estate/tests/test_estate_property.py new file mode 100644 index 00000000000..656a3038734 --- /dev/null +++ b/estate/tests/test_estate_property.py @@ -0,0 +1,37 @@ +from odoo.tests import Form, tagged +from odoo.exceptions import UserError +from odoo.addons.estate.tests.common import TestEstateCommon + + +@tagged('post_install', '-at_install') +class TestEstateProperty(TestEstateCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_action_sell_property(self): + # Test failed case: Cancelled state + with self.assertRaises(UserError): + self.property_cancelled.action_sell_property() + + # Test failed case: No accepted offer + with self.assertRaises(UserError): + self.property_offer_received.action_sell_property() + + # Test successful case + result = self.property_offer_accepted.action_sell_property() + self.assertTrue(result) + self.assertEqual(self.property_offer_accepted.state, 'sold') + + def test_onchange_garden(self): + property_form = Form(self.env['estate.property']) + + # Test when garden is True + property_form.garden = True + self.assertEqual(property_form.garden_area, 10) + self.assertEqual(property_form.garden_orientation, 'north') + + # Test when garden is False + property_form.garden = False + self.assertFalse(property_form.garden_area) + self.assertFalse(property_form.garden_orientation) diff --git a/estate/tests/test_estate_property_offer.py b/estate/tests/test_estate_property_offer.py new file mode 100644 index 00000000000..a37c0524e95 --- /dev/null +++ b/estate/tests/test_estate_property_offer.py @@ -0,0 +1,38 @@ +from odoo.tests import tagged +from odoo.exceptions import UserError, ValidationError +from odoo.addons.estate.tests.common import TestEstateCommon + + +@tagged('post_install', '-at_install') +class TestEstatePropertyOffer(TestEstateCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_create_offer(self): + # Test failed case: Property is already sold + self.property_offer_accepted.action_sell_property() + + with self.assertRaises(UserError): + self.env['estate.property.offer'].create({ + 'property_id': self.property_offer_accepted.id, + 'partner_id': self.partner.id, + 'price': 250000 + }) + + # Test failed case: Offer price is less than maximum offer + with self.assertRaises(ValidationError): + self.env['estate.property.offer'].create({ + 'property_id': self.property_offer_received.id, + 'partner_id': self.partner.id, + 'price': 90000 # Less than the expected price + }) + + # Test successful case + offer = self.env['estate.property.offer'].create({ + 'property_id': self.property_offer_received.id, + 'partner_id': self.partner.id, + 'price': 120000 # Valid offer price + }) + self.assertTrue(offer) + self.assertEqual(offer.property_id, self.property_offer_received) diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..4609abd3c08 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ 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..8cd65d730ba --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,51 @@ + + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + + +
+
+
+ + + + estate.property.offer.list + estate.property.offer + + + + + + +