diff --git a/.gitignore b/.gitignore index b6e47617de1..ca7a1f2cc5b 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# VSCode config files +.vscode/ diff --git a/awesome_clicker/static/src/click_rewards.js b/awesome_clicker/static/src/click_rewards.js new file mode 100644 index 00000000000..ac8540f1b6e --- /dev/null +++ b/awesome_clicker/static/src/click_rewards.js @@ -0,0 +1,24 @@ +export const rewards = [ + { + description: "Get 1 ClickBot", + apply(clicker) { + clicker.bots.clickbot.quantity++; + }, + maxLevel: 3, + }, + { + description: "Get 1 BigBot", + apply(clicker) { + clicker.bots.bigbot.quantity++; + }, + minLevel: 3, + maxLevel: 4, + }, + { + description: "Increase bot power!", + apply(clicker) { + clicker.power++; + }, + minLevel: 3, + }, +]; diff --git a/awesome_clicker/static/src/click_value/click_value.js b/awesome_clicker/static/src/click_value/click_value.js new file mode 100644 index 00000000000..a54ddab5ce1 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.js @@ -0,0 +1,17 @@ +import { Component } from "@odoo/owl"; +import { humanNumber } from "@web/core/utils/numbers"; + +import { useClicker } from "../clicker_service"; + + +export class ClickValue extends Component { + static template = "awesome_clicker.ClickValue"; + + setup() { + this.clicker = useClicker(); + } + + getClickValueDisplay() { + return humanNumber(this.clicker.clicks, { decimals: 1 }); + } +} diff --git a/awesome_clicker/static/src/click_value/click_value.xml b/awesome_clicker/static/src/click_value/click_value.xml new file mode 100644 index 00000000000..63daa1fd995 --- /dev/null +++ b/awesome_clicker/static/src/click_value/click_value.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/awesome_clicker/static/src/clicker_model.js b/awesome_clicker/static/src/clicker_model.js new file mode 100644 index 00000000000..0feefc358a5 --- /dev/null +++ b/awesome_clicker/static/src/clicker_model.js @@ -0,0 +1,117 @@ +import { EventBus } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; +import { Reactive } from "@web/core/utils/reactive"; + +import { chooseReward } from "./utils"; + + +export const LEVEL_REQUIREMENTS = [ + { level: 1, requirement: 1000, event_name: "MILESTONE_1k", message: "Level up! You have unlocked ClickBots." }, + { level: 2, requirement: 5000, event_name: "MILESTONE_5k", message: "Level up! You have unlocked BigBots." }, + { level: 3, requirement: 100000, event_name: "MILESTONE_100k", message: "Level up! You have unlocked Power." }, + { level: 4, requirement: 1000000, event_name: "MILESTONE_1M", message: "Level up! You have unlocked Trees." }, +]; + +export class ClickerModel extends Reactive { + + constructor() { + super(); + + this.version = "1.1"; + this.clicks = 0; + this.level = 0; + this.power = 1; + this.bots = { + clickbot: { + name: "ClickBot", + quantity: 0, + price: 1000, + yield: 10, + level_required: 1, + }, + bigbot: { + name: "BigBot", + quantity: 0, + price: 5000, + yield: 100, + level_required: 2, + } + }; + this.trees = { + pear: { + name: "Pear Tree", + fruit_name: "Pear", + quantity: 0, + price: 1000000, + fruits: 0, + level_required: 4, + }, + cherry: { + name: "Cherry Tree", + fruit_name: "Cherry", + quantity: 0, + price: 1000000, + fruits: 0, + level_required: 4, + }, + peach: { + name: "Peach Tree", + fruit_name: "Peach", + quantity: 0, + price: 1000000, + fruits: 0, + level_required: 4, + } + } + + this.bus = new EventBus(); + document.addEventListener("click", () => this.increment(1), { capture: true }); + setInterval(() => { + Object.values(this.bots).forEach(bot => this.clicks += bot.yield * this.power * bot.quantity); + browser.localStorage.setItem("clicker_state", JSON.stringify(this)); + }, 10 * 1000); + setInterval(() => { + Object.values(this.trees).forEach(tree => tree.fruits += tree.quantity); + }, 30 * 1000); + } + + increment(inc) { + this.clicks += inc; + + LEVEL_REQUIREMENTS.forEach(milestone => { + if (this.clicks >= milestone.requirement && this.level < milestone.level) { + this.level++; + this.bus.trigger(milestone.event_name); + } + }) + } + + purchaseBot(bot_name) { + let purchased_bot = Object.values(this.bots).find(bot => bot.name === bot_name); + purchased_bot.quantity++; + this.clicks -= purchased_bot.price; + } + + purchaseTree(tree_name) { + let purchased_tree = Object.values(this.trees).find(tree => tree.name === tree_name); + purchased_tree.quantity++; + this.clicks -= purchased_tree.price; + } + + purchasePower() { + this.power++; + this.clicks -= 50000; + } + + getReward() { + this.bus.trigger("RANDOM_REWARD", chooseReward(this.level)); + } + + getTotalTreeCount() { + return Object.values(this.trees).map(tree => tree.quantity).reduce((sum, qty) => { sum + qty }, 0); + } + + getTotalFruitCount() { + return Object.values(this.trees).map(tree => tree.fruits).reduce((sum, qty) => { sum + qty }, 0); + } +} diff --git a/awesome_clicker/static/src/clicker_service.js b/awesome_clicker/static/src/clicker_service.js new file mode 100644 index 00000000000..d64957819a7 --- /dev/null +++ b/awesome_clicker/static/src/clicker_service.js @@ -0,0 +1,72 @@ +import { useState } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; + +import { ClickerModel, LEVEL_REQUIREMENTS } from "./clicker_model"; +import { migrate } from "./migration"; + + +function initClickerState() { + let clicker_model = new ClickerModel(); + let local_state = JSON.parse(browser.localStorage.getItem("clicker_state")); + + if (!local_state) { + return clicker_model; + } + + if (local_state.version != clicker_model.version) { + migrate(local_state, clicker_model.version); + } + + delete local_state.bus; + return Object.assign(clicker_model, local_state); +} + +const clickerService = { + dependencies: ["action", "effect", "notification"], + start(env, services) { + let clicker_model = initClickerState(); + + LEVEL_REQUIREMENTS.forEach(milestone => + clicker_model.bus.addEventListener( + milestone.event_name, + () => services.effect.add({ message: milestone.message }), + ) + ) + + clicker_model.bus.addEventListener( + "RANDOM_REWARD", + (ev) => { + const closeNotification = services.notification.add( + `Congratulations, you won a reward: '${ev.detail.description}'`, + { + type: "success", + sticky: true, + buttons: [{ + name: "Collect", + onClick: () => { + ev.detail.apply(clicker_model); + closeNotification(); + services.action.doAction({ + type: "ir.actions.client", + tag: "awesome_clicker.client_action", + target: "new", + name: "Clicker" + }); + } + }], + } + ) + } + ) + + return clicker_model; + } +} + +export function useClicker() { + return useState(useService("awesome_clicker.clicker_service")); +} + +registry.category("services").add("awesome_clicker.clicker_service", clickerService); diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js new file mode 100644 index 00000000000..a630120c846 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.js @@ -0,0 +1,30 @@ +import { Component } from "@odoo/owl"; +import { Dropdown } from "@web/core/dropdown/dropdown"; +import { DropdownItem } from "@web/core/dropdown/dropdown_item"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; + +import { useClicker } from "../clicker_service"; +import { ClickValue } from "../click_value/click_value"; + + +export class ClickerSystrayItem extends Component { + static template = "awesome_clicker.ClickerSystrayItem"; + static components = { ClickValue, Dropdown, DropdownItem }; + + setup() { + this.clicker = useClicker(); + this.action_service = useService("action"); + } + + openClickerWindow() { + this.action_service.doAction({ + type: "ir.actions.client", + tag: "awesome_clicker.client_action", + target: "new", + name: "Clicker" + }); + } +} + +registry.category("systray").add("awesome_clicker.ClickerSystrayItem", { Component: ClickerSystrayItem }); diff --git a/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml new file mode 100644 index 00000000000..7de447b26a1 --- /dev/null +++ b/awesome_clicker/static/src/clicker_systray_item/clicker_systray_item.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + x + ( ) + + + + + + diff --git a/awesome_clicker/static/src/client_action/client_action.js b/awesome_clicker/static/src/client_action/client_action.js new file mode 100644 index 00000000000..0355b794ab9 --- /dev/null +++ b/awesome_clicker/static/src/client_action/client_action.js @@ -0,0 +1,18 @@ +import { Component } from "@odoo/owl"; +import { Notebook } from "@web/core/notebook/notebook"; +import { registry } from "@web/core/registry"; + +import { useClicker } from "../clicker_service"; +import { ClickValue } from "../click_value/click_value"; + + +export class ClientAction extends Component { + static template = "awesome_clicker.ClientAction"; + static components = { ClickValue, Notebook }; + + setup() { + this.clicker = useClicker(); + } +} + +registry.category("actions").add("awesome_clicker.client_action", ClientAction); diff --git a/awesome_clicker/static/src/client_action/client_action.xml b/awesome_clicker/static/src/client_action/client_action.xml new file mode 100644 index 00000000000..ffd4839ecaa --- /dev/null +++ b/awesome_clicker/static/src/client_action/client_action.xml @@ -0,0 +1,50 @@ + + + +
+
+ Clicks: +
+ + + +

Bots

+ +
+ x ( clicks/10s) + +
+
+ +
+ x multiplier to all bot clicks + +
+
+ + +

Fruits

+ + + x + + +

Trees

+ +
+ x (1 /30s) + +
+
+
+
+
+
+
diff --git a/awesome_clicker/static/src/command_provider.js b/awesome_clicker/static/src/command_provider.js new file mode 100644 index 00000000000..f9ee8bd8b5e --- /dev/null +++ b/awesome_clicker/static/src/command_provider.js @@ -0,0 +1,69 @@ +import { registry } from "@web/core/registry"; + + +registry.category("command_provider").add( + "clicker_game", { + provide: (env, options) => { return [ + { + name: "Open Clicker Game", + category: "activity", + action() { + env.services.action.doAction({ + type: "ir.actions.client", + tag: "awesome_clicker.client_action", + target: "new", + name: "Clicker" + }); + } + }, + { + name: "Buy 1 ClickBot", + category: "activity", + action() { + env.services["awesome_clicker.clicker_service"].purchaseBot("ClickBot"); + } + }, + + // Commands below are strictly for debugging, they are not part of the tutorial exercises + { + name: "Increment Clicker by 1,000", + category: "debug", + action() { + env.services["awesome_clicker.clicker_service"].increment(1000); + } + }, + { + name: "Increment Clicker by 100,000", + category: "debug", + action() { + env.services["awesome_clicker.clicker_service"].increment(100000); + } + }, + { + name: "Increment Clicker by 1,000,000", + category: "debug", + action() { + env.services["awesome_clicker.clicker_service"].increment(1000000); + } + }, + { + name: "Grant Clicker Reward", + category: "debug", + action() { + env.services["awesome_clicker.clicker_service"].getReward(); + } + }, + { + name: "Reset Clicker Game", + category: "debug", + action() { + let clicker = env.services["awesome_clicker.clicker_service"]; + Object.values(clicker.bots).forEach(bot => bot.quantity = 0); + clicker.power = 1; + clicker.level = 0; + clicker.clicks = 0; + } + }, + ]} + } +); diff --git a/awesome_clicker/static/src/form_controller/from_controller.js b/awesome_clicker/static/src/form_controller/from_controller.js new file mode 100644 index 00000000000..94a45813141 --- /dev/null +++ b/awesome_clicker/static/src/form_controller/from_controller.js @@ -0,0 +1,15 @@ +import { FormController } from '@web/views/form/form_controller'; +import { patch } from "@web/core/utils/patch"; + +import { useClicker } from "../clicker_service"; + + +patch(FormController.prototype, { + setup() { + super.setup(...arguments); + let clicker = useClicker(); + if (Math.random < 0.01) { + clicker.getReward(); + } + } +}); diff --git a/awesome_clicker/static/src/migration.js b/awesome_clicker/static/src/migration.js new file mode 100644 index 00000000000..82c84748357 --- /dev/null +++ b/awesome_clicker/static/src/migration.js @@ -0,0 +1,27 @@ +const MIGRATIONS = [ + { + version_from: "1.0", + version_to: "1.1", + apply(local_state) { + console.log("Migrating from 1.0 to 1.1"); + Object.assign(local_state.trees, { + peach: { + name: "Peach Tree", + fruit_name: "Peach", + quantity: 0, + price: 1000000, + fruits: 0, + level_required: 4, + } + }); + }, + } +] + +export function migrate(local_state, target_version) { + while (local_state.version != target_version) { + let migration = MIGRATIONS.find(update => update.version_from === local_state.version); + migration.apply(local_state); + local_state.version = migration.version_to; + } +} diff --git a/awesome_clicker/static/src/utils.js b/awesome_clicker/static/src/utils.js new file mode 100644 index 00000000000..dc82a91816f --- /dev/null +++ b/awesome_clicker/static/src/utils.js @@ -0,0 +1,11 @@ +import { rewards } from "./click_rewards"; + + +export function chooseReward(current_level) { + let available_rewards = rewards.filter(reward => + (!reward.minLevel || reward.minLevel <= current_level) && + (!reward.maxLevel || reward.maxLevel >= current_level) + ); + let reward_index = Math.ceil(Math.random() * available_rewards.length) - 1 + return available_rewards[reward_index]; +} diff --git a/awesome_dashboard/static/src/config_dialog/config_dialog.js b/awesome_dashboard/static/src/config_dialog/config_dialog.js new file mode 100644 index 00000000000..f93e1946961 --- /dev/null +++ b/awesome_dashboard/static/src/config_dialog/config_dialog.js @@ -0,0 +1,20 @@ +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 ConfigDialog extends Component { + static template = "awesome_dashboard.ConfigDialog"; + static components = { Dialog, CheckBox }; + + static props = { + items: { type: Object }, + }; + + applyConfig() { + let hidden_item_ids = this.props.items.filter(item => !item.visible).map(item => item.id); + browser.localStorage.setItem("hidden_item_ids", hidden_item_ids); + this.props.close(); + } +} diff --git a/awesome_dashboard/static/src/config_dialog/config_dialog.xml b/awesome_dashboard/static/src/config_dialog/config_dialog.xml new file mode 100644 index 00000000000..3208d217d64 --- /dev/null +++ b/awesome_dashboard/static/src/config_dialog/config_dialog.xml @@ -0,0 +1,14 @@ + + + + + Click on a card to toggle its visibility + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index c4fb245621b..11eea6cf125 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,8 +1,44 @@ -import { Component } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; +import { browser } from "@web/core/browser/browser"; import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { Layout } from "@web/search/layout"; + +import { DashboardItem } from "./dashboard_item/dashboard_item"; +import { ConfigDialog } from "./config_dialog/config_dialog"; + class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; + static components = { DashboardItem, Layout }; + + setup() { + this.action_service = useService("action"); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog_service = useService("dialog"); + + this.items = useState(registry.category("awesome_dashboard").getAll()); + let hidden_item_ids = browser.localStorage.getItem("hidden_item_ids").split(","); + this.items.forEach(item => Object.assign(item, { visible: !hidden_item_ids.includes(item.id) })); + } + + openPartnerKanbanView() { + this.action_service.doAction("base.action_partner_form"); + } + + openCrmLeads() { + this.action_service.doAction({ + type: 'ir.actions.act_window', + name: 'CRM leads', + target: 'current', + res_model: 'crm.lead', + views: [[false, 'list'], [false, 'form']], + }); + } + + openDashboardSettings() { + this.dialog_service.add(ConfigDialog, { items: this.items }); + } } registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.scss b/awesome_dashboard/static/src/dashboard.scss new file mode 100644 index 00000000000..428638b831a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard.scss @@ -0,0 +1,7 @@ +.o_dashboard { + background-color: grey; +} + +.btn-primary { + margin-inline: 5px; +} diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index 1a2ac9a2fed..cb9333920d7 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -2,7 +2,22 @@ - hello dashboard + + + + + + + +
+ + + + +
+
+
diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..291db20c103 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.js @@ -0,0 +1,14 @@ +import { Component } from "@odoo/owl"; + + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + static props = { + size: { type: Number, optional: true }, + slots: { type: Object, optional: true }, + }; + + static defaultProps = { + size: 1, + }; +} diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss new file mode 100644 index 00000000000..8321919cc44 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.scss @@ -0,0 +1,8 @@ +.o_dashboard_item { + border: 2px solid black; + background-color: white; + color: black; + margin: 10px; + padding: 10px; + text-align: center; +} diff --git a/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..c2d2041dbeb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_item/dashboard_item.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard_items.js b/awesome_dashboard/static/src/dashboard_items.js new file mode 100644 index 00000000000..da2e6565f8a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_items.js @@ -0,0 +1,66 @@ +import { registry } from "@web/core/registry"; + +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; + + +const items = [ + { + id: "nb_new_orders", + description: "Number of new orders", + Component: NumberCard, + props: (data) => ({ + title: "Number of new orders this month", + value: data.nb_new_orders, + }), + }, + { + id: "total_amount", + description: "Total number of orders", + Component: NumberCard, + props: (data) => ({ + title: "Total amount of new orders this month", + value: data.total_amount, + }), + }, + { + id: "average_quantity", + description: "Average amount by order", + Component: NumberCard, + size: 2, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + value: data.average_quantity, + }), + }, + { + id: "nb_cancelled_orders", + description: "Number of cancelled orders", + Component: NumberCard, + props: (data) => ({ + title: "Number of cancelled orders this month", + value: data.nb_cancelled_orders, + }), + }, + { + id: "average_time", + description: "Average time to ship/cancel", + Component: NumberCard, + size: 2, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time, + }), + }, + { + id: "orders_by_size", + description: "Pie chart of the number of orders by size", + Component: PieChartCard, + props: (data) => ({ + title: "Number of orders by size", + value: data.orders_by_size, + }), + }, +] + +items.forEach(item => registry.category("awesome_dashboard").add(item.id, item)) diff --git a/awesome_dashboard/static/src/number_card/number_card.js b/awesome_dashboard/static/src/number_card/number_card.js new file mode 100644 index 00000000000..8c709fa1c7e --- /dev/null +++ b/awesome_dashboard/static/src/number_card/number_card.js @@ -0,0 +1,11 @@ +import { Component } from "@odoo/owl"; + + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + + static props = { + title: { type: String }, + value: { type: Number }, + }; +} diff --git a/awesome_dashboard/static/src/number_card/number_card.xml b/awesome_dashboard/static/src/number_card/number_card.xml new file mode 100644 index 00000000000..fb256813ea7 --- /dev/null +++ b/awesome_dashboard/static/src/number_card/number_card.xml @@ -0,0 +1,7 @@ + + + +
+ +
+
diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.js b/awesome_dashboard/static/src/pie_chart/pie_chart.js new file mode 100644 index 00000000000..e42cb396484 --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.js @@ -0,0 +1,41 @@ +import { Component, onWillStart, onWillUnmount, useEffect, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + + static props = { + chart_data: {type: Object}, + }; + + setup() { + this.canvasRef = useRef("pie_chart_canvas"); + this.chart = null; + + onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"])); + + useEffect(() => this.renderChart()); + onWillUnmount(() => this.destroyChart()); + } + + renderChart() { + this.destroyChart(); + this.chart = new Chart( + this.canvasRef.el, + { + type: "pie", + data: { + labels: Object.keys(this.props.chart_data), + datasets: [{ data: Object.values(this.props.chart_data) }], + }, + }, + ); + } + + destroyChart() { + if (this.chart) { + this.chart.destroy(); + } + } +} diff --git a/awesome_dashboard/static/src/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..2f6c0fc9fec --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..e06a38b4b01 --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.js @@ -0,0 +1,14 @@ +import { Component } from "@odoo/owl"; + +import { PieChart } from "../pie_chart/pie_chart"; + + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart }; + + static props = { + title: { type: String }, + value: { type: Number }, + }; +} diff --git a/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..67b5bde3e7b --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + +
+ +
+
diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js new file mode 100644 index 00000000000..98330748e51 --- /dev/null +++ b/awesome_dashboard/static/src/statistics_service.js @@ -0,0 +1,21 @@ +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; +import { registry } from "@web/core/registry"; + + +const statisticsService = { + start() { + let statistics = reactive({ isReady: false }); + + async function loadStatistics() { + let updated_stats = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updated_stats, { isReady: true }); + } + + setInterval(loadStatistics, 10 * 60 * 1000); + loadStatistics(); + return statistics; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_gallery/__init__.py b/awesome_gallery/__init__.py index a0fdc10fe11..9724f5e7f8d 100644 --- a/awesome_gallery/__init__.py +++ b/awesome_gallery/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- from . import models +from . import validation diff --git a/awesome_gallery/models/ir_ui_view.py b/awesome_gallery/models/ir_ui_view.py index 0c11b8298ac..a589605b527 100644 --- a/awesome_gallery/models/ir_ui_view.py +++ b/awesome_gallery/models/ir_ui_view.py @@ -6,3 +6,6 @@ class View(models.Model): _inherit = 'ir.ui.view' type = fields.Selection(selection_add=[('gallery', "Awesome Gallery")]) + + def _get_view_info(self): + return {'gallery': {'icon': 'fa fa-picture-o'}} | super()._get_view_info() diff --git a/awesome_gallery/rng/gallery.rng b/awesome_gallery/rng/gallery.rng new file mode 100644 index 00000000000..38939e0f444 --- /dev/null +++ b/awesome_gallery/rng/gallery.rng @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + diff --git a/awesome_gallery/static/src/gallery_arch_parser/gallery_arch_parser.js b/awesome_gallery/static/src/gallery_arch_parser/gallery_arch_parser.js new file mode 100644 index 00000000000..b093d5297fc --- /dev/null +++ b/awesome_gallery/static/src/gallery_arch_parser/gallery_arch_parser.js @@ -0,0 +1,12 @@ +export class GalleryArchParser { + parse(xmlDoc) { + const imageField = xmlDoc.getAttribute("image_field"); + const limit = xmlDoc.getAttribute("limit") || 80; + const tooltipField = xmlDoc.getAttribute("tooltip_field"); + return { + imageField, + limit, + tooltipField, + }; + } +} diff --git a/awesome_gallery/static/src/gallery_controller/gallery_controller.js b/awesome_gallery/static/src/gallery_controller/gallery_controller.js new file mode 100644 index 00000000000..454b10e921c --- /dev/null +++ b/awesome_gallery/static/src/gallery_controller/gallery_controller.js @@ -0,0 +1,50 @@ +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { Component, onWillStart, onWillUpdateProps, useState } from "@odoo/owl"; +import { usePager } from "@web/search/pager_hook"; +import { standardViewProps } from "@web/views/standard_view_props"; + + +export class GalleryController extends Component { + static template = "awesome_gallery.GalleryController"; + static components = { Layout }; + + static props = { + ...standardViewProps, + archInfo: Object, + Model: Function, + Renderer: Function, + }; + + setup() { + this.orm = useService("orm"); + this.model = useState( + new this.props.Model( + this.orm, + this.props.resModel, + this.props.archInfo, + ) + ); + + usePager(() => { + return { + offset: this.model.pager.offset, + limit: this.model.pager.limit, + total: this.model.recordsLength, + onUpdate: async ({ offset, limit }) => { + this.model.pager.offset = offset; + this.model.pager.limit = limit; + await this.model.load(this.props.domain); + }, + }; + }); + + onWillStart(async () => await this.model.load(this.props.domain)); + + onWillUpdateProps(async (nextProps) => { + if (JSON.stringify(nextProps.domain) !== JSON.stringify(this.props.domain)) { + await this.model.load(nextProps.domain); + } + }); + } +} diff --git a/awesome_gallery/static/src/gallery_controller/gallery_controller.xml b/awesome_gallery/static/src/gallery_controller/gallery_controller.xml new file mode 100644 index 00000000000..c5560883d4a --- /dev/null +++ b/awesome_gallery/static/src/gallery_controller/gallery_controller.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/awesome_gallery/static/src/gallery_model.js b/awesome_gallery/static/src/gallery_model.js new file mode 100644 index 00000000000..8877de2b3e6 --- /dev/null +++ b/awesome_gallery/static/src/gallery_model.js @@ -0,0 +1,35 @@ +export class GalleryModel { + constructor(orm, resModel, archInfo) { + this.orm = orm; + this.resModel = resModel; + this.records = []; + + const { imageField, limit, tooltipField } = archInfo; + this.imageField = imageField; + this.limit = limit; + this.tooltipField = tooltipField; + + this.pager = { offset: 0, limit: limit }; + } + + async load(domain) { + const { length, records } = await this.orm.webSearchRead( + this.resModel, + domain, + { + limit: this.pager.limit, + offset: this.pager.offset, + specification: { + [this.imageField]: {}, + ["name"]: {}, + write_date: {} + }, + context: { + bin_size: true, + } + } + ); + this.records = records; + this.recordsLength = length; + } +} diff --git a/awesome_gallery/static/src/gallery_renderer/gallery_renderer.js b/awesome_gallery/static/src/gallery_renderer/gallery_renderer.js new file mode 100644 index 00000000000..7de17bcb1df --- /dev/null +++ b/awesome_gallery/static/src/gallery_renderer/gallery_renderer.js @@ -0,0 +1,44 @@ +import { useService } from "@web/core/utils/hooks"; +import { url } from "@web/core/utils/urls"; +import { Component } from "@odoo/owl"; +import { FileUploader } from "@web/views/fields/file_handler"; + +import { GalleryModel } from "../gallery_model"; + + +export class GalleryRenderer extends Component { + static template = "awesome_gallery.GalleryRenderer"; + static props = { model: GalleryModel }; + static components = { FileUploader }; + + setup() { + this.action_service = useService("action"); + this.orm = useService("orm"); + } + + getImageUrl(record_id) { + return url("/web/image", { + model: this.props.model.resModel, + id: record_id, + field: this.props.model.imageField, + }); + } + + openFormView(record_id) { + this.action_service.switchView("form", { resId: record_id }); + } + + async onFileUploaded(record_id, { data }) { + await this.orm.webSave( + this.props.model.resModel, + [record_id], + { + [this.props.model.imageField]: data, + }, + { + specification: {}, + } + ) + await this.props.model.load([]); + } +} diff --git a/awesome_gallery/static/src/gallery_renderer/gallery_renderer.xml b/awesome_gallery/static/src/gallery_renderer/gallery_renderer.xml new file mode 100644 index 00000000000..34a2d62aa30 --- /dev/null +++ b/awesome_gallery/static/src/gallery_renderer/gallery_renderer.xml @@ -0,0 +1,17 @@ + + + + + +
+ + + + + + +
+
+
+ +
diff --git a/awesome_gallery/static/src/gallery_view.js b/awesome_gallery/static/src/gallery_view.js new file mode 100644 index 00000000000..a12a5d83800 --- /dev/null +++ b/awesome_gallery/static/src/gallery_view.js @@ -0,0 +1,33 @@ +import { registry } from "@web/core/registry"; + +import { GalleryArchParser } from "./gallery_arch_parser/gallery_arch_parser"; +import { GalleryController } from "./gallery_controller/gallery_controller"; +import { GalleryModel } from "./gallery_model"; +import { GalleryRenderer } from "./gallery_renderer/gallery_renderer"; + + +export const galleryView = { + type: "gallery", + display_name: "Gallery", + icon: "fa fa-picture-o", + multiRecord: true, + Model: GalleryModel, + Controller: GalleryController, + Renderer: GalleryRenderer, + ArchParser: GalleryArchParser, + + props(genericProps, view) { + const { ArchParser } = view; + const { arch } = genericProps; + const archInfo = new ArchParser().parse(arch); + + return { + ...genericProps, + Model: view.Model, + Renderer: view.Renderer, + archInfo, + }; + }, +}; + +registry.category("views").add("gallery", galleryView); diff --git a/awesome_gallery/validation.py b/awesome_gallery/validation.py new file mode 100644 index 00000000000..eee51f4a739 --- /dev/null +++ b/awesome_gallery/validation.py @@ -0,0 +1,26 @@ +import logging +import os + +from lxml import etree + +from odoo.loglevels import ustr +from odoo.tools import misc, view_validation + +_logger = logging.getLogger(__name__) + +_gallery_validator = None + +@view_validation.validate('gallery') +def schema_gallery(arch, **kwargs): + global _gallery_validator + + if _gallery_validator is None: + with misc.file_open(os.path.join('awesome_gallery', 'rng', 'gallery.rng')) as f: + _gallery_validator = etree.RelaxNG(etree.parse(f)) + + if _gallery_validator.validate(arch): + return True + + for error in _gallery_validator.error_log: + _logger.error(ustr(error)) + return False diff --git a/awesome_gallery/views/views.xml b/awesome_gallery/views/views.xml index 56327365875..dcbcaf93652 100644 --- a/awesome_gallery/views/views.xml +++ b/awesome_gallery/views/views.xml @@ -1,18 +1,26 @@ + + awesome_gallery.orders.gallery + res.partner + + + + + Contacts res.partner - kanban,tree,form,activity + kanban,list,form,activity,gallery {'default_is_company': True} -

- Create a Contact in your address book -

- Odoo helps you track all activities related to your contacts. -

+

+ Create a Contact in your address book +

+ Odoo helps you track all activities related to your contacts. +

diff --git a/awesome_kanban/static/src/awesome_kanban_view.js b/awesome_kanban/static/src/awesome_kanban_view.js index 0da52b22c9d..d7dc711d62c 100644 --- a/awesome_kanban/static/src/awesome_kanban_view.js +++ b/awesome_kanban/static/src/awesome_kanban_view.js @@ -1 +1,10 @@ -// TODO: Define here your AwesomeKanban view +import { kanbanView } from "@web/views/kanban/kanban_view"; +import { registry } from "@web/core/registry"; +import { AwesomeKanbanController } from "./kanban_controller/kanban_controller"; + +const awesomeKanbanController = { + ...kanbanView, + Controller: AwesomeKanbanController, +}; + +registry.category("views").add("awesome_kanban", awesomeKanbanController); diff --git a/awesome_kanban/static/src/customer_list/customer_list.js b/awesome_kanban/static/src/customer_list/customer_list.js new file mode 100644 index 00000000000..eb669b3f451 --- /dev/null +++ b/awesome_kanban/static/src/customer_list/customer_list.js @@ -0,0 +1,37 @@ +import { Component, onWillStart, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; +import { fuzzyLookup } from "@web/core/utils/search"; + + +export class CustomerList extends Component { + static template = "awesome_kanban.CustomerList"; + + static props = { selectCustomer: Function }; + + setup() { + super.setup(); + this.orm = useService("orm"); + this.customers = useState({ data: [] }); + this.state = useState({ nameFilter: "", isActiveChecked: false }); + + onWillStart(async () => this.customers.data = await this.loadCustomers()) + } + + get displayedCustomers() { + return this.filterCustomersByName(this.state.nameFilter); + } + + async toggleActiveCustomerFilter(ev) { + this.state.isActiveChecked = ev.target.checked; + this.customers.data = await this.loadCustomers(); + } + + loadCustomers() { + let domain = this.state.isActiveChecked ? [["opportunity_ids", "!=", false]] : []; + return this.orm.searchRead("res.partner", domain, ["display_name"]); + } + + filterCustomersByName(filter) { + return filter === "" ? this.customers.data : fuzzyLookup(filter, this.customers.data, (customer) => customer.display_name); + } +} diff --git a/awesome_kanban/static/src/customer_list/customer_list.scss b/awesome_kanban/static/src/customer_list/customer_list.scss new file mode 100644 index 00000000000..e1829dc48a5 --- /dev/null +++ b/awesome_kanban/static/src/customer_list/customer_list.scss @@ -0,0 +1,7 @@ +.o_customer_list { + float: left; + width: 300px; + height: 100%; + background-color: black; + text-align: center; +} diff --git a/awesome_kanban/static/src/customer_list/customer_list.xml b/awesome_kanban/static/src/customer_list/customer_list.xml new file mode 100644 index 00000000000..faaea70186e --- /dev/null +++ b/awesome_kanban/static/src/customer_list/customer_list.xml @@ -0,0 +1,18 @@ + + + + +
+

Customers

+ Active customers + + + + + +
+
+ +
diff --git a/awesome_kanban/static/src/kanban_controller/kanban_controller.js b/awesome_kanban/static/src/kanban_controller/kanban_controller.js new file mode 100644 index 00000000000..baae7801459 --- /dev/null +++ b/awesome_kanban/static/src/kanban_controller/kanban_controller.js @@ -0,0 +1,32 @@ +import { KanbanController } from "@web/views/kanban/kanban_controller"; + +import { CustomerList } from "../customer_list/customer_list"; + + +export class AwesomeKanbanController extends KanbanController { + static template = "awesome_kanban.AwesomeKanbanController"; + static components = { ...KanbanController.components, CustomerList }; + + setup() { + super.setup(); + this.searchKey = Symbol("isFromAwesomeKanban"); + } + + onCustomerSelected(customer_id, customer_name) { + const customerFilters = this.env.searchModel.getSearchItems((searchItem) => + searchItem.isFromAwesomeKanban + ); + + for (const customerFilter of customerFilters) { + if (customerFilter.isActive) { + this.env.searchModel.toggleSearchItem(customerFilter.id); + } + } + + this.env.searchModel.createNewFilters([{ + description: customer_name, + domain: [["partner_id", "=", customer_id]], + isFromAwesomeKanban: true, + }]) + } +} diff --git a/awesome_kanban/static/src/kanban_controller/kanban_controller.xml b/awesome_kanban/static/src/kanban_controller/kanban_controller.xml new file mode 100644 index 00000000000..ed634cedabd --- /dev/null +++ b/awesome_kanban/static/src/kanban_controller/kanban_controller.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..7a6293d0634 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,19 @@ +import { Component, useState } from "@odoo/owl"; + + +export class Card extends Component { + static template = "my_module.Card"; + + static props = { + title: { type: String }, + slots: { type: Object, optional: true } + } + + setup() { + this.state = useState({ isOpen: true }); + } + + toggleCardBody() { + 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..089392276db --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,12 @@ + + + +
+ +
+
+

+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..fb8427f10ec --- /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 template = "my_module.Counter"; + static props = { + onChange: { type: Function, optional: true } + } + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + this.props.onChange(); + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..ea1829c0ff6 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +
+

Counter:

+ +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..9988f6a3611 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,22 @@ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; + +import { Card } from "./card/card" +import { Counter } from "./counter/counter" +import { TodoList } from "./todo_list/todo_list" + export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "my_module.Playground"; + static components = { Card, Counter, TodoList }; + + value1 = "
some text 1
"; + value2 = markup("
some text 2
"); + + setup() { + this.state = useState({ sum: 0 }); + } + + incrementSum() { + this.state.sum++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..4d956e29eb8 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,24 @@ - - -
- hello world + +
+

+ Hello world: + + +

+

Sum:

-
+ + + + + + + + + + + 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..e414a72032d --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,12 @@ +import { Component } from "@odoo/owl"; + + +export class TodoItem extends Component { + static template = "my_module.TodoItem"; + + static props = { + todo: { type: Object, shape: {id: Number, description: String, isCompleted: Boolean} }, + toggleState: { type: Function }, + removeTodo: { type: Function } + } +} 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..22bbeb8a8ca --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,13 @@ + + + +
+

+ + . + + +

+
+
+
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..70f426ac786 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,38 @@ +import { Component, onMounted, useRef, useState } from "@odoo/owl"; + +import { TodoItem } from "./todo_item" + + +export class TodoList extends Component { + static template = "my_module.TodoList"; + static components = { TodoItem }; + + setup() { + this.state = useState({ todos: [] }); + this.taskCounter = 0; + + this.inputRef = useRef('todo_list_input'); + onMounted(() => { + this.inputRef.el.focus(); + }); + } + + addTodo(ev) { + if (ev.keyCode === 13 && ev.srcElement.value != "") { + this.state.todos.push({id: this.taskCounter++, description: ev.srcElement.value, isCompleted: false}); + ev.srcElement.value = ""; + } + } + + toggleTaskCompletion(toggled_item_id) { + var toggled_item = this.state.todos.find(todo_item => todo_item.id === toggled_item_id); + toggled_item.isCompleted = !toggled_item.isCompleted; + } + + removeTask(task_id) { + const removal_index = this.state.todos.findIndex((todo_item) => todo_item.id === task_id); + if (removal_index >= 0) { + this.state.todos.splice(removal_index, 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..a2a958a0c9b --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,11 @@ + + + +
+ +

+ +

+
+
+
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..5bba2abdc0e --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': 'estate', + 'depends': [ + 'base', + ], + 'application': True, + 'data': [ + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + 'views/res_users_views.xml', + 'security/ir.model.access.csv', + 'data/estate.property.type.csv', + ], + 'demo': [ + 'demo/estate.property.xml', + 'demo/estate.property.offer.xml', + ], +} diff --git a/estate/data/estate.property.type.csv b/estate/data/estate.property.type.csv new file mode 100644 index 00000000000..4d0d7a60f78 --- /dev/null +++ b/estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +"id","name" +property_type_residential,"Residential" +property_type_commercial,"Commercial" +property_type_industrial,"Industrial" +property_type_land,"Land" diff --git a/estate/demo/estate.property.offer.xml b/estate/demo/estate.property.offer.xml new file mode 100644 index 00000000000..4466beb42b4 --- /dev/null +++ b/estate/demo/estate.property.offer.xml @@ -0,0 +1,34 @@ + + + + + 10000 + 14 + + + + + + + 1500000 + 14 + + + + + + + 1500001 + 14 + + + + + + + + + + + + diff --git a/estate/demo/estate.property.xml b/estate/demo/estate.property.xml new file mode 100644 index 00000000000..626ba6ba0b4 --- /dev/null +++ b/estate/demo/estate.property.xml @@ -0,0 +1,60 @@ + + + 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 + + + + + Storefront + new + Storefront in a market + 5050 + 1990-07-08 + 1000000 + 0 + 50 + 2 + False + + + + + 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..a64b0799dc3 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,109 @@ +import datetime +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real estate property model" + _order = "id desc" + + name = fields.Char(required=True, string="Title") + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(copy=False, default=datetime.date.today() + relativedelta(months=3), string="Available From") + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + 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( + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West'), + ] + ) + active = fields.Boolean(default=True) + state = fields.Selection( + required=True, + default="new", + copy=False, + string="status", + selection=[ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled') + ], + ) + property_type_id = fields.Many2one("estate.property.type", string="Property type") + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + salesman_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) + property_tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + total_area = fields.Float(compute="_compute_total_area") + best_price = fields.Float(compute="_compute_best_price", string="Best Offer") + + _check_expected_price_positive = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price of a property cannot be negative', + ) + + _check_selling_price_positive = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price of a property cannot be negative', + ) + + @api.constrains('selling_price', 'expected_price') + def _check_selling_to_expected_price_ratio(self): + for record in self: + if float_compare(record.selling_price, 0.9 * record.expected_price, 2) == -1 and not float_is_zero(record.selling_price, 2): + raise ValidationError("Selling price cannot be less than 90% of expected price") + + @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_price(self): + for record in self: + record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0 + + @api.onchange('garden') + def _onchange_garden(self): + self.garden_area = 10 if self.garden else 0 + self.garden_orientation = 'north' if self.garden else None + + def action_mark_as_sold(self): + for record in self: + if record.state == 'cancelled': + raise UserError("A Cancelled property cannot be sold") + elif not record.offer_ids: + raise UserError("A property without offers cannot be sold") + else: + record.state = 'sold' + return True + + def action_mark_as_cancelled(self): + for record in self: + if record.state == 'sold': + raise UserError("A sold property cannot be cancelled") + else: + record.state = 'cancelled' + return True + + @api.ondelete(at_uninstall=False) + def prevent_deletion_if_not_new_or_cancelled(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("Only New or Cancelled properties can be deleted") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..fdbd3a5f52f --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,65 @@ +import datetime +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "A property offer is an amount a potential buyer offers to the seller" + _order = "price desc" + + price = fields.Float() + status = fields.Selection(copy=False, + selection=[ + ('accepted', 'Accepted'), + ('refused', 'Refused'), + ] + ) + partner_id = fields.Many2one("res.partner", required=True) + property_id = fields.Many2one("estate.property", required=True) + validity = fields.Integer(default=7) + date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline") + property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id", store=True, string="Property type") + active = fields.Boolean(default=True) + + _check_offer_price_positive = models.Constraint( + 'CHECK(price > 0)', + 'The offer price of a property cannot be negative', + ) + + @api.depends('create_date', 'validity') + def _compute_date_deadline(self): + for record in self: + creation_date = record.create_date or datetime.date.today() + record.date_deadline = creation_date + relativedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + record.validity = record.date_deadline.day - record.create_date.day + + def action_accept_offer(self): + for record in self: + if 'accepted' in record.property_id.offer_ids.mapped("status"): + raise UserError("Another offer has already been accepted for this property") + record.status = 'accepted' + record.property_id.state = 'offer_accepted' + record.property_id.buyer_id = record.partner_id + record.property_id.selling_price = record.price + + def action_refuse_offer(self): + for record in self: + record.status = 'refused' + + def create(self, vals_list): + for vals in vals_list: + property_record = self.env["estate.property"].browse(vals["property_id"]) + if property_record.state == 'sold': + raise UserError('Offers cannot be created for sold properties') + if property_record.offer_ids and vals["price"] < max(property_record.offer_ids.mapped("price")): + raise UserError("Newly created offer price must not be lower than the current best offer") + else: + property_record.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..e8e3c079cf8 --- /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 = "Tags describing the property such as 'cozy' and 'renovated'" + _order = "name" + + name = fields.Char(required=True) + color = fields.Integer() + + _tag_name_unique = models.Constraint( + 'UNIQUE(name)', + 'Tag names 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..cbc1fd92240 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,23 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate property type such as 'house'" + _order = "name" + + name = fields.Char(required=True) + property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") + sequence = fields.Integer() + offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") + offer_count = fields.Integer(compute="_compute_offer_count") + + @api.depends("offer_ids") + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) + + _property_type_name_unique = models.Constraint( + 'UNIQUE(name)', + 'Property type names must be unique', + ) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..ecae1ef0fa1 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,11 @@ +from odoo import fields, models + +class ResUsers(models.Model): + _inherit = ["res.users"] + + property_ids = fields.One2many( + "estate.property", + "salesman_id", + string="Real Estate Properties", + domain=['|', ('state', '=', 'new'), ('state', '=', 'offer_received')] + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..89f97c50842 --- /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 diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..dfd37f0be11 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate diff --git a/estate/tests/test_estate.py b/estate/tests/test_estate.py new file mode 100644 index 00000000000..f9918616d62 --- /dev/null +++ b/estate/tests/test_estate.py @@ -0,0 +1,59 @@ +from odoo.exceptions import UserError +from odoo.tests import Form, tagged +from odoo.tests.common import TransactionCase + + +@tagged('post_install', '-at_install') +class EstateTestCase(TransactionCase): + + @classmethod + def setUpClass(cls): + super(EstateTestCase, cls).setUpClass() + + cls.property = cls.env['estate.property'].create({ + 'name': 'property', + 'state': 'new', + 'expected_price': 100000, + }) + + def test_prevent_offer_creation_on_property(self): + self.property.state = 'sold' + self.assertEqual(self.property.state, 'sold') + + with self.assertRaises(UserError): + self.property.offer_ids.create([{ + 'partner_id': self.env.uid, + 'property_id': self.property.id, + 'price': 100000, + }]) + + def test_prevent_sale_without_offer(self): + self.assertEqual(len(self.property.offer_ids), 0, 'Property should not have any offers') + with self.assertRaises(UserError): + self.property.action_mark_as_sold() + + def test_mark_property_as_sold(self): + self.property.offer_ids.create([{ + 'partner_id': self.env.uid, + 'property_id': self.property.id, + 'price': 100000, + }]) + self.property.action_mark_as_sold() + self.assertEqual(self.property.state, 'sold', 'Property should have been updated to sold state') + + def test_property_form_garden_reset(self): + form = Form(self.env['estate.property']) + form.name = 'Garden Test Property' + form.expected_price = 10000 + + form.garden = True + property_with_garden = form.save() + self.assertEqual(property_with_garden.garden, True) + self.assertEqual(property_with_garden.garden_area, 10) + self.assertEqual(property_with_garden.garden_orientation, 'north') + + form.garden = False + property_without_garden = form.save() + self.assertEqual(property_without_garden.garden, False) + self.assertEqual(property_without_garden.garden_area, 0) + self.assertEqual(property_without_garden.garden_orientation, False) diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..f3973e31ac3 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..899883b50a1 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,41 @@ + + + + Offers + estate.property.offer + [('property_type_id', '=', active_id)] + list,form + + + + estate.property.offer.list + estate.property.offer + + + + + + + + +

+ + + + + + + + + + + +
+ +
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..ace8d2abf37 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,127 @@ + + + + Properties + estate.property + list,form,kanban + {'search_default_available': True} + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + + +
Expected Price:
+
+ Best Price: +
+
+ Selling Price: +
+ +
+
+
+
+
+
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..a95c6746a54 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.view.form.inherit.estate + 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..7bdc01a863c --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,7 @@ +{ + 'name': 'estate_account', + 'depends': [ + 'account', + 'estate', + ], +} 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..ad8bdba341c --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,29 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = ["estate.property"] + + def action_mark_as_sold(self): + super().action_mark_as_sold() + for record in self: + if record.state == 'cancelled': + continue + + self.env['account.move'].create({ + "partner_id": record.buyer_id.id, + "move_type": "out_invoice", + "line_ids": [ + Command.create({ + "name": "6% of selling price", + "quantity": 1, + "price_unit": 0.06 * record.selling_price + }), + Command.create({ + "name": "Administrative fees", + "quantity": 1, + "price_unit": 100 + }) + ] + }) + return True diff --git a/importable_estate/__init__.py b/importable_estate/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/importable_estate/__manifest__.py b/importable_estate/__manifest__.py new file mode 100644 index 00000000000..0a48da2bdb4 --- /dev/null +++ b/importable_estate/__manifest__.py @@ -0,0 +1,9 @@ +{ + 'name': 'estate', + 'depends': [ + 'base', + ], + 'data': [ + 'models/estate_property.xml', + ] +} diff --git a/importable_estate/models/estate_property.xml b/importable_estate/models/estate_property.xml new file mode 100644 index 00000000000..3f97478bd8f --- /dev/null +++ b/importable_estate/models/estate_property.xml @@ -0,0 +1,22 @@ + + + Real Estate Property + x_estate.property + + + + + x_name + Property name + char + True + + + + + x_expected_price + Expected price + integer + True + +