diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..7d44af2a4ec 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,11 @@ 'assets': { 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', + ('remove', 'awesome_dashboard/static/src/dashboard/**/*'), ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*', + ] }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..1bf2521fc7e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,98 @@ +/** @odoo-module **/ + +import { Component, useState } from '@odoo/owl'; +import { registry } from '@web/core/registry'; +import { Layout } from '@web/search/layout'; +import { useService } from '@web/core/utils/hooks'; +import { DashboardItem } from './dashboard_item/dashboard_item'; +import { Dialog } from '@web/core/dialog/dialog'; +import { CheckBox } from '@web/core/checkbox/checkbox'; +import { browser } from '@web/core/browser/browser'; + +class AwesomeDashboard extends Component { + static template = 'awesome_dashboard.AwesomeDashboard'; + static components = { Layout, DashboardItem }; + + setup() { + this.showCustomers = this.showCustomers.bind(this); + this.showLeads = this.showLeads.bind(this); + this.action = useService('action'); + this.stats = useState(useService('awesome_dashboard.statistics')); + this.items = registry.category('awesome_dashboard').getAll(); + this.display = { + controlPanel: {}, + }; + this.dialog = useService('dialog'); + this.state = useState({ + disabledItems: + browser.localStorage + .getItem('disabledDashboardItems') + ?.split(',') || [], + }); + } + + openConfiguration() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }); + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } + + showCustomers() { + this.action.doAction('base.action_partner_form'); + } + + showLeads() { + this.action.doAction({ + type: 'ir.actions.act_window', + name: 'Leads', + target: 'current', + res_model: 'crm.lead', + views: [ + [false, 'list'], + [false, 'form'], + ], + }); + } +} + +class ConfigurationDialog extends Component { + static template = 'awesome_dashboard.ConfigurationDialog'; + static components = { Dialog, CheckBox }; + static props = ['close', 'items', 'disabledItems', 'onUpdateConfiguration']; + + setup() { + this.items = useState( + this.props.items.map((item) => { + return { + ...item, + checked: !this.props.disabledItems.includes(item.id), + }; + }) + ); + } + + done() { + this.props.close(); + } + + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items) + .filter((item) => !item.enabled) + .map((item) => item.id); + + browser.localStorage.setItem( + 'disabledDashboardItems', + JSON.stringify(newDisabledItems) + ); + this.props.onUpdateConfiguration(newDisabledItems); + } +} + +registry.category('lazy_components').add('AwesomeDashboard', AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..2e0c3d6162d --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,5 @@ +.o_dashboard { + background-color: gray; + font-weight: bold; + font-size: 1.5rem; +} \ 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..b395fdd6427 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + +
+ + + + + + +
+
+
+ + + + Which cards do you wish to see? + + + + + + + + + + +
\ 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..84e1db91491 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,18 @@ +import { Component } from '@odoo/owl'; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + static props = { + size: { + type: Number, + optional: true, + }, + slots: { + type: Object, + 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..e18b7cd916c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,16 @@ + + + +
+
+ +
+
+ +
+
+
+
\ 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..00a8662f39e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,65 @@ +import { NumberCard } from './number_card/number_card'; +import { PieChartCard } from './pie_chart_card/pie_chart_card'; +import { registry } from '@web/core/registry'; + +const items = [ + { + id: 'average_quantity', + description: 'Average amount of t-shirt by order this month', + Component: NumberCard, + props: (data) => ({ + title: 'Average amount of t-shirt by order this month', + value: data.average_quantity, + }), + }, + { + id: 'average_time', + description: 'Average time for an order', + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time, + }), + }, + { + id: 'number_new_orders', + description: 'New orders this month', + Component: NumberCard, + props: (data) => ({ + title: 'Number of new orders this month', + value: data.nb_new_orders, + }), + }, + { + id: 'cancelled_orders', + description: 'Cancelled orders this month', + Component: NumberCard, + props: (data) => ({ + title: 'Number of cancelled orders this month', + value: data.nb_cancelled_orders, + }), + }, + { + id: 'amount_new_orders', + description: 'amount orders this month', + Component: NumberCard, + props: (data) => ({ + title: 'Total amount of new orders this month', + value: data.total_amount, + }), + }, + { + id: 'pie_chart', + description: 'Shirt orders by size', + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: 'Shirt orders by size', + values: data.orders_by_size, + }), + }, +]; + +items.forEach((item) => { + registry.category('awesome_dashboard').add(item.id, item); +}); diff --git a/awesome_dashboard/static/src/dashboard/dashboard_service.js b/awesome_dashboard/static/src/dashboard/dashboard_service.js new file mode 100644 index 00000000000..041b2dac15a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_service.js @@ -0,0 +1,27 @@ +import { registry } from '@web/core/registry'; +import { rpc } from '@web/core/network/rpc'; +import { reactive } from '@odoo/owl'; + +const dashboardService = { + start() { + let stats = reactive({ + isReady: false, + }); + + async function loadData() { + const result = await rpc('/awesome_dashboard/statistics'); + Object.assign(stats, result, { isReady: true }); + setTimeout(() => { + loadData(); + }, 1000 * 10); + } + + loadData(); + + return stats; + }, +}; + +registry + .category('services') + .add('awesome_dashboard.statistics', dashboardService); diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js new file mode 100644 index 00000000000..ff4a68acf06 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,13 @@ +import { Component } from '@odoo/owl'; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + } + } +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..3b67b1a3a1c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
\ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..142416833be --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,15 @@ +import { Component } from '@odoo/owl'; +import { PieChart } from '../../pie_chart/pie_chart'; + +export class PieChartCard extends Component { + static template = 'awesome_dashboard.PieChartCard'; + static components = { PieChart }; + static props = { + title: { + type: String, + }, + values: { + type: Object, + }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..16f8b721330 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + \ 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..e75bb2bb47e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,14 @@ +import { registry } from '@web/core/registry'; +import { LazyComponent } from '@web/core/assets'; +import { Component, xml } from '@odoo/owl'; + +class AwesomeDashboardLoader extends Component { + static template = xml` + + `; + static components = { LazyComponent }; +} + +registry + .category('actions') + .add('awesome_dashboard.dashboard', AwesomeDashboardLoader); \ No newline at end of file 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..a25bd35d918 --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.js @@ -0,0 +1,62 @@ +import { + Component, + onWillStart, + useRef, + onMounted, + onWillUnmount, +} from '@odoo/owl'; +import { loadJS } from '@web/core/assets'; +import { getColor } from '@web/core/colors/colors'; + +export class PieChart extends Component { + static template = 'awesome_dashboard.PieChart'; + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef('canvas'); + this.chart = null; + this.renderChart = this.renderChart.bind(this); + this.getChartData = this.getChartData.bind(this); + onWillStart(() => loadJS('/web/static/lib/Chart/Chart.js')); + onWillUnmount(() => { + if (this.chart) { + this.chart.destroy(); + } + }); + onMounted(() => { + this.renderChart(); + }); + } + + getChartData() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + const colors = labels.map((_, index) => getColor(2 ** (index + 2))); + const chartData = { + labels, + datasets: [ + { + label: this.props.label, + data, + backgroundColor: colors, + hoverOffset: 1, + }, + ], + }; + return chartData; + } + + renderChart() { + if(this.chart) { + this.chart.destroy(); + } + const config = { + type: 'pie', + data: this.getChartData(), + }; + this.chart = new Chart(this.canvasRef.el, config); + } +} 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..eda87fabf12 --- /dev/null +++ b/awesome_dashboard/static/src/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
\ 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..460c13a3583 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,26 @@ +import { Component, useState } from '@odoo/owl'; + +export class Card extends Component { + static template = 'awesome_owl.Card'; + static props = { + title: { + type: String, + optional: false, + }, + slots: { + type: Object, + optional: true, + } + } + + setup() { + this.isBodyOpen = useState({ + value: true, + }); + this.toggleBodyOpen = this.toggleBodyOpen.bind(this); + } + + toggleBodyOpen() { + this.isBodyOpen.value = !this.isBodyOpen.value; + } +} \ 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..4a861f67ff9 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,14 @@ + + + +
+
+

+ +
+
+ +
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..692c532a89e --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +import { Component, useState } from '@odoo/owl'; + +export class Counter extends Component { + static template = 'awesome_owl.Counter'; + static props = { + onChange: { + type: Function, + optional: true, + }, + }; + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + this.props.onChange && this.props.onChange(); + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..16bb489fd21 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + +

+ Counter: + +

+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..e752b15dea4 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,25 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from '@odoo/owl'; +import { Counter } from './counter/counter'; +import { Card } from './card/card'; +import { TodoList } from './todolist/todo_list'; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = 'awesome_owl.playground'; + static components = { Counter, Card, TodoList }; + static props = {}; + + setup() { + this.escapedValue = 'Hello, world!'; + this.notEscapedValue = markup('Hello, world!'); + this.countersSum = useState({ + value: 0, + }); + this.increaseSum = this.increaseSum.bind(this); + } + + increaseSum() { + this.countersSum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..ce41f52afca 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,26 @@ - + - -
+
hello world
+
+
+ + +

Counters Sum:

+
+
+
+ +

Card content 1

+
+ + + +
+
+ +
- - + \ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todo_item.js b/awesome_owl/static/src/todolist/todo_item.js new file mode 100644 index 00000000000..a8f3fc6a611 --- /dev/null +++ b/awesome_owl/static/src/todolist/todo_item.js @@ -0,0 +1,23 @@ +import { Component } from '@odoo/owl'; + +export class TodoItem extends Component { + static template = 'awesome_owl.TodoItem'; + static props = { + todo: { + type: { + id: Number, + description: String, + isCompleted: Boolean, + }, + optional: false, + }, + toggleTodo: { + type: Function, + optional: false, + }, + removeTodo: { + type: Function, + optional: false, + }, + }; +} \ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todo_item.xml b/awesome_owl/static/src/todolist/todo_item.xml new file mode 100644 index 00000000000..566952279b9 --- /dev/null +++ b/awesome_owl/static/src/todolist/todo_item.xml @@ -0,0 +1,31 @@ + + + +
+
+ + +
+ ID: +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/todolist/todo_list.js b/awesome_owl/static/src/todolist/todo_list.js new file mode 100644 index 00000000000..1949bd8dee9 --- /dev/null +++ b/awesome_owl/static/src/todolist/todo_list.js @@ -0,0 +1,51 @@ +import { Component, useState } from '@odoo/owl'; +import { TodoItem } from './todo_item'; +import { useAutoFocus } from '../utils'; + +export class TodoList extends Component { + static template = 'awesome_owl.TodoList'; + static components = { TodoItem }; + static props = { + todos: { + type: Array, + optional: true, + }, + }; + + setup() { + this.todos = useState([]); + this.addTask = this.addTask.bind(this); + this.nextTodoId = this.todos.length + 1; + useAutoFocus('add_task_input'); + this.toggleTodo = this.toggleTodo.bind(this); + this.removeTodo = this.removeTodo.bind(this); + } + + addTask(ev) { + ev.preventDefault(); + if (ev.key !== 'Enter') { + return; + } + const input = ev.target; + const description = input.value.trim(); + if (!description) { + return; + } + this.todos.push({ + id: this.nextTodoId++, + description, + isCompleted: false, + }); + input.value = ''; + } + + toggleTodo(todoId) { + const toBeToggled = this.todos.find(todo => todo.id === todoId); + toBeToggled.isCompleted = !toBeToggled.isCompleted; + } + + removeTodo(todoId) { + const toBeRemovedIndex = this.todos.findIndex(todo => todo.id === todoId); + this.todos.splice(toBeRemovedIndex, 1); + } +} diff --git a/awesome_owl/static/src/todolist/todo_list.xml b/awesome_owl/static/src/todolist/todo_list.xml new file mode 100644 index 00000000000..d0ba75abe28 --- /dev/null +++ b/awesome_owl/static/src/todolist/todo_list.xml @@ -0,0 +1,17 @@ + + + + +
+
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..d88b6f1a6cd --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { onMounted, useRef } from '@odoo/owl'; + +export const useAutoFocus = (inputFieldRefName) => { + const addTaskInputRef = useRef(inputFieldRefName); + onMounted(() => { + addTaskInputRef.el.focus(); + }); +} \ 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..e23e965ffd2 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': 'Real Estate', + 'version': '1.0', + 'description': 'anything', + 'summary': 'anything again', + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_res_users_views.xml', + 'views/estate_menus.xml', + ], + 'depends': [ + 'base', + ], + 'application': True, + 'installable': True, + 'license': 'AGPL-3' +} diff --git a/estate/constants.py b/estate/constants.py new file mode 100644 index 00000000000..abc18e1560a --- /dev/null +++ b/estate/constants.py @@ -0,0 +1,5 @@ +# selling prices for the properties should be at least 90% of the expected price +PROPERTY_SELLING_PRICE_THRESHOLD = 0.9 + +# epsilon to define the rounding precision when comparing floats +PROPERTY_PRICE_PRECISION_EPSILON = 1e-6 diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..7b3fc844702 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_offer +from . import estate_property_tag +from . import estate_property_type +from . import estate_property_user diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..7c47b2af0dd --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,112 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare, float_is_zero + +from ..constants import PROPERTY_PRICE_PRECISION_EPSILON, PROPERTY_SELLING_PRICE_THRESHOLD + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'model for the properties in our app' + _order = 'id desc' + + name = fields.Char(required = True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date( + copy = False, + default = fields.Date.add(fields.Date.today(), months = 3) + ) + expected_price = fields.Float(required = True) + selling_price = fields.Float(readonly = True, copy = False) + bedrooms = fields.Integer(default = 2) + living_area = fields.Integer() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection( + string = "Garden Orientation", + selection = [ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West'), + ], + help = 'garden orientation is used to choose the orientation of the garden attached to the property' + ) + active = fields.Boolean(default = True) + state = fields.Selection( + string = "State", + selection = [ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], + default = 'new', + required = True, + copy = False, + ) + property_type_id = fields.Many2one("estate.property.type", string = "Property Type") + buyer_id = fields.Many2one("res.partner", string = "Buyer", copy = False) + salesperson_id = fields.Many2one("res.users", string = "Salesperson", default = lambda self: self.env.user) + property_tag_ids = fields.Many2many("estate.property.tag", string = "Property Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string = "Offers") + total_area = fields.Float(compute = "_compute_total_area") + 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.price') + def _compute_best_offer(self): + for record in self: + record.best_offer = max(record.offer_ids.mapped('price'), default = 0.0) + + @api.onchange('garden') + def _onchange_garden(self): + if not self.garden: + self.garden_area = 0 + self.garden_orientation = '' + else: + self.garden_orientation = 'north' + self.garden_area = 10 + + def action_cancel_property(self): + if self.filtered(lambda record: record.state == 'sold'): + raise UserError('Sold properties cannot be cancelled') + self.state = 'cancelled' + return True + + def action_sell_property(self): + if self.filtered(lambda record: record.state == 'cancelled'): + raise UserError('Cancelled properties cannot be sold') + if not self.filtered(lambda record: record.state == 'offer_accepted'): + raise UserError('You must accept an offer before you can sell the property') + self.state = 'sold' + return True + + @api.constrains('selling_price') + def _check_selling_price(self): + for record in self: + if float_is_zero(record.selling_price, precision_rounding = PROPERTY_PRICE_PRECISION_EPSILON): + continue + if float_compare( + record.selling_price, record.expected_price * PROPERTY_SELLING_PRICE_THRESHOLD, + precision_rounding = PROPERTY_PRICE_PRECISION_EPSILON + ) < 0: + raise UserError('The selling price must be at least 90% of the the expected price') + + @api.ondelete(at_uninstall = False) + def _ondelete_property(self): + if self.filtered(lambda record: record.state not in ('new', 'cancelled')): + raise UserError('Only new or canceled properties can be deleted') + + _sql_constraints = [ + ('positive_expected_price', 'CHECK(expected_price > 0)', 'Expected price must be positive'), + ('positive_selling_price', 'CHECK(selling_price >= 0)', 'Selling price must be positive'), + ] diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..4f90a7f0d50 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,67 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare, float_is_zero + +from ..constants import PROPERTY_PRICE_PRECISION_EPSILON + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'the offer of the property being sold' + _order = 'price desc' + + price = fields.Float() + status = fields.Selection(selection = [('accepted', 'Accepted'), ('refused', 'Refused')], copy = False) + partner_id = fields.Many2one('res.partner', string = 'Partner', required = True) + property_id = fields.Many2one('estate.property', string = 'Property', required = True) + validity = fields.Integer(default = 7) + date_deadline = fields.Date(compute = '_compute_date_deadline', inverse = '_inverse_date_deadline') + property_type_id = fields.Many2one(related = 'property_id.property_type_id', store = True) + + @api.depends('validity') + def _compute_date_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = fields.Date.add(record.create_date, days = record.validity) + + def _inverse_date_deadline(self): + for record in self: + if record.create_date and record.date_deadline: + create_date = fields.Date.from_string(record.create_date) + record.validity = (record.date_deadline - create_date).days + + def action_accept_offer(self): + self.ensure_one() + if self.property_id.buyer_id: + raise UserError('This property already has an accepted offer') + self.property_id.selling_price = self.price + self.property_id.state = 'offer_accepted' + self.status = 'accepted' + self.property_id.buyer_id = self.partner_id + return True + + def action_refuse_offer(self): + self.ensure_one() + if self.property_id.buyer_id == self.partner_id: + self.property_id.buyer_id = False + self.property_id.state = 'offer_received' + self.property_id.selling_price = 0 + self.status = 'refused' + return True + + @api.model_create_multi + def create(self, vals_list): + property_offers = [vals for vals in vals_list if vals.get('property_id')] + for offer_vals in property_offers: + property_id = self.env['estate.property'].browse(offer_vals.get('property_id')) + max_price = max(property_id.offer_ids.mapped('price'), default = 0.0) + if float_compare( + offer_vals.get('price'), max_price, precision_rounding = PROPERTY_PRICE_PRECISION_EPSILON + ) < 0: + raise UserError('The offer must be at least %s' % max_price) + property_id.state = 'offer_received' + return super().create(vals_list) + + _sql_constraints = [ + ('price_positive', 'CHECK(price > 0)', 'Price must be positive') + ] diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..9fe79efa85c --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'the tag of the property being sold' + _order = 'name' + color = fields.Integer() + + name = fields.Char(required = True) + + _sql_constraints = [ + ('name_uniq', 'unique(name)', 'Tag name must be unique!') + ] diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..89c44cea1f7 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,22 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'the type of the property being sold' + _order = 'sequence, name' + sequence = fields.Integer(default = 1) + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string = 'Offers') + offer_count = fields.Integer(compute='_compute_offer_count') + + name = fields.Char(required = True) + property_ids = fields.One2many('estate.property', 'property_type_id', string = 'Properties') + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) + + _sql_constraints = [ + ('name_uniq', 'unique(name)', 'Property type name must be unique!') + ] diff --git a/estate/models/estate_property_user.py b/estate/models/estate_property_user.py new file mode 100644 index 00000000000..492668a5895 --- /dev/null +++ b/estate/models/estate_property_user.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class EstatePropertyUser(models.Model): + _inherit = 'res.users' + + property_ids = fields.Many2many( + 'estate.property', string = 'Properties', domain = "[('state', 'in', ['new', 'offer_received'])]" + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..78458c1cb61 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 +estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 +estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 +estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..a982d2a89c7 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..a64214b8ce5 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,56 @@ + + + + estate.property.offer.form + estate.property.offer + +
+ + +

+ + + +

+ + + + + + + + +
+

+ +

+ + + + + + + + + + + + + + + + + + + + estate.property.type.list + estate.property.type + + + + + + + + + + Property Types + estate.property.type + list,form + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..b45464284c3 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,145 @@ + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.kanban + estate.property + + + + + +
+ +
+ Expected Price: + +
+
+ Best Price: + +
+
+ Selling Price: + +
+
+
+
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + Properties + estate.property + kanban,list,form + {'search_default_available': True} + +
diff --git a/estate/views/estate_res_users_views.xml b/estate/views/estate_res_users_views.xml new file mode 100644 index 00000000000..9f08fbd9027 --- /dev/null +++ b/estate/views/estate_res_users_views.xml @@ -0,0 +1,17 @@ + + + + res.users.view.inherit.show.properties + res.users + + + + + + + + + + + + \ No newline at end of file diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..9a7e03eded3 --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..1c346467585 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,14 @@ +{ + 'name': 'Real Estate Account', + 'version': '1.0', + 'description': 'a model to enable creation of invoices for sold properties', + 'data': [], + 'depends': [ + 'base', + 'estate', + 'account', + ], + 'application': True, + 'installable': True, + 'license': 'LGPL-3', +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..f4c8fd6db6d --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property \ No newline at end of file diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..14b4f33081d --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,28 @@ +from odoo import fields, models, Command + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sell_property(self): + for record in self: + record.env["account.move"].create( + { + "partner_id": record.buyer_id.id, + "move_type": "out_invoice", + "invoice_line_ids": [ + Command.create({ + "name": "6% of the selling price", + "price_unit": record.selling_price * 0.06, + "quantity": 1, + }), + Command.create({ + "name": "Administration Fee", + "price_unit": 20, + "quantity": 1, + }) + ] + }, + ) + + return super().action_sell_property()