diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index c4fb245621b..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.js b/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.js new file mode 100644 index 00000000000..e7ea8ad4741 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.js @@ -0,0 +1,30 @@ +import { Component, useState } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { registry } from "@web/core/registry"; + +export class ConfigDialog extends Component { + static template = "awesome_dashboard.ConfigDialog"; + static components = { Dialog }; + + setup() { + this.items = registry.category("awesome_dashboard").get("DashboardItems"); + this.state = useState({ + hiddenIds: this.props.hiddenIds, + }); + } + + toggleItem(id) { + console.log(this.state.hiddenIds); + const idIndex = this.state.hiddenIds.indexOf(id); + if (idIndex >= 0) { + this.state.hiddenIds.splice(idIndex, 1); + } else { + this.state.hiddenIds.push(id); + } + } + + onApply() { + this.props.onApply(this.state.hiddenIds); + this.props.close(); + } +} diff --git a/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.xml b/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.xml new file mode 100644 index 00000000000..71f7f8ab6e1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.xml @@ -0,0 +1,23 @@ + + + + +
Which cards fo you wish to see?
+
+ + + +
+ + + + +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..34b3ce9fccf --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,59 @@ +import { Component, useState } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { browser } from "@web/core/browser/browser"; +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { _t } from "@web/core/l10n/translation"; +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 = { Layout, DashboardItem }; + + setup() { + this.actionService = useService("action"); + this.statisticsService = useService("awesome_dashboard.statistics"); + this.statistics = useState(this.statisticsService.statistics); + this.items = registry.category("awesome_dashboard").get("DashboardItems"); + this.dialog = useService("dialog"); + this.state = useState({ + hiddenIds: browser.localStorage.getItem("dashboard_hidden_ids")?.split(",") || [], + }); + } + + get displayedItems() { + return this.items.filter((item) => !this.state.hiddenIds.includes(item.id)); + } + + openConfiguration() { + this.dialog.add(ConfigDialog, { + items: this.items, + hiddenIds: this.state.hiddenIds, + onApply: (newHiddenIds) => { + this.state.hiddenIds = newHiddenIds; + browser.localStorage.setItem("dashboard_hidden_ids", newHiddenIds); + }, + }); + } + + openCustomers() { + this.actionService.doAction("base.action_partner_form"); + } + + openLeads() { + this.actionService.doAction({ + type: "ir.actions.act_window", + name: _t("Leads"), + target: "current", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + }); + } +} + +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..b2fd98b1e85 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: pink; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..156de67e88a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + +
+ + + + + + +
+
+
+
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..9bacd822da6 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,19 @@ +import { Component } from "@odoo/owl"; + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem"; + + static props = { + size: { + type: Number, + }, + slots: { + type: Object, + optional: true, + }, + }; + + static defaultProps = { + size: 1, + }; +} 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..28e3e417fbe --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
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..8605036414a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,63 @@ +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; + +export const items = [ + { + id: "average_quantity", + description: "Average quantity", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of t-shirts by order this month", + value: data.average_quantity, + }), + }, + { + id: "average_time", + description: "Average time", + Component: NumberCard, + props: (data) => ({ + title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'", + value: data.average_time, + }), + }, + { + 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: "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: "total_amount", + description: "Total orders", + Component: NumberCard, + props: (data) => ({ + title: "Total amount of new orders this month", + value: data.total_amount, + }), + }, + { + id: "tshirt_sizes", + description: "T-Shirt orders chart", + Component: PieChartCard, + size: 1, + props: (data) => ({ + title: "T-Shirt Sizes By Amount Sold", + data: data.orders_by_size, + }), + }, +]; + +registry.category("awesome_dashboard").add("DashboardItems", items); 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..e9d3ca44c99 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,9 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { String }, + value: { Number }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..417c99b7091 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + +
+

+
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..624c457627f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,37 @@ +import { Component, onWillStart, useRef, onMounted } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static props = { + data: { type: Object }, + title: { type: String }, + }; + + setup() { + this.canvasRef = useRef("canvas"); + + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }); + + onMounted(() => { + this.drawChart(); + }); + } + + drawChart() { + new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: Object.keys(this.props.data), + datasets: [ + { + label: this.props.title, + data: Object.values(this.props.data), + }, + ], + }, + }); + } +} 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..2002f234a40 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,9 @@ + + + +
+ + +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/services/statistics.service.js b/awesome_dashboard/static/src/dashboard/services/statistics.service.js new file mode 100644 index 00000000000..5e7ec2e0e6b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/services/statistics.service.js @@ -0,0 +1,24 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +export const statisticsService = { + start(env) { + const stats = reactive({ data: {} }); + + async function fetch() { + const result = await rpc("/awesome_dashboard/statistics"); + Object.assign(stats.data, result); + } + + fetch(); + + setInterval(fetch, 10000); + + return { + statistics: stats.data, + }; + }, +}; + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..0465b7e9fed --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,15 @@ +import { Component, xml } from "@odoo/owl"; +import { LazyComponent } from "@web/core/assets"; +import { registry } from "@web/core/registry"; + +export class DashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; +} + +registry.category("actions").add("awesome_dashboard.dashboard", DashboardLoader); diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..2124d1dfd1d --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,25 @@ +import { Component, useState } from "@odoo/owl"; + + +export class Card extends Component { + static template = "awesome_owl.Card"; + + static props = { + title: { + type: String, + validate: val => (val.length > 0), + }, + slots: { + type: Object, + optional: true, + }, + }; + + setup() { + this.state = useState({ isOpen: true }); + }; + + toggleOpen() { + 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..4010598b642 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,13 @@ + + + +
+
+
+ + + +
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..5de66df5f61 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,24 @@ +import { Component, useState } from "@odoo/owl"; + + +export class Counter extends Component { + static template = "awesome_owl.Counter"; + + static props = { + onChange: { + type: Function, + optional: true, + }, + }; + + setup() { + this.state = useState({ value: 1 }); + }; + + increment() { + this.state.value++; + if (this.props.onChange) { + this.props.onChange(); + } + }; +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..62205b5ebfa --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,12 @@ + + + +
+
+

+ Counter: +

+
+
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..ae703c6c4c7 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 { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo/todo_list"; + export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + + setup() { + this.htmlContent1 = "
This is second card text - not marked up
"; + this.htmlContent2 = markup("
This is third card text - marked up
"); + this.state = useState({ + sum: 2, + }); + }; + + incrementSum() { + this.state.sum++; + }; } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..8cd345d56dc 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -3,7 +3,20 @@
- hello world + Testing multiple counters: + + +
Total Sum:
+
+
+ Testing multiple cards: + This is the first card. + + + +
+
+
diff --git a/awesome_owl/static/src/todo/todo_item.js b/awesome_owl/static/src/todo/todo_item.js new file mode 100644 index 00000000000..7f2545a1fe0 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,37 @@ +import { Component, useState } from "@odoo/owl"; + + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + todo: { + type: Object, + shape: { + id: { type: Number }, + description: { type: String }, + isCompleted: { type: Boolean }, + } + }, + toggleState: { + type: Function, + optional: true, + }, + removeTodo: { + type: Function, + optional: true, + } + }; + + change() { + if (this.props.toggleState) { + this.props.toggleState(this.props.todo.id); + } + }; + + remove() { + if (this.props.removeTodo) { + this.props.removeTodo(this.props.todo.id); + } + }; +} diff --git a/awesome_owl/static/src/todo/todo_item.xml b/awesome_owl/static/src/todo/todo_item.xml new file mode 100644 index 00000000000..bbf97eaaf66 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,18 @@ + + + +
+ + + +
+
+
diff --git a/awesome_owl/static/src/todo/todo_list.js b/awesome_owl/static/src/todo/todo_list.js new file mode 100644 index 00000000000..12b7581930b --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,41 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item"; +import { useAutoFocus } from "../utils"; + + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.todos = useState([]); + useAutoFocus("todoInput"); + }; + + addTodo(ev) { + const description = ev.target.value; + if (ev.keyCode === 13 && description.length > 0) { + const newTodo = { + id: this.todos.length + 1, + description: description, + isCompleted: false, + }; + this.todos.push(newTodo); + ev.target.value = ""; + } + }; + + toggleTodo(id) { + const todo = this.todos.find(t => t.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + }; + + removeTodo(id) { + const index = this.todos.findIndex(t => t.id === id); + if (index !== -1) { + this.todos.splice(index, 1); + } + }; +} diff --git a/awesome_owl/static/src/todo/todo_list.xml b/awesome_owl/static/src/todo/todo_list.xml new file mode 100644 index 00000000000..523694c1c46 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,16 @@ + + + +
+
+

Todo List

+
+ +
+ + + +
+
+
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..14a3166d22a --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { onMounted, useRef } from "@odoo/owl"; + +export function useAutoFocus(refName) { + let inputRef = useRef(refName); + onMounted(() => { + inputRef.el?.focus(); + }); +} diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..4a65ffd401c --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,16 @@ +{ + 'name': 'Real Estate', + 'depends': ['base'], + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + ], + 'application': True, + 'author': 'Dilya Anvarbekova', + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9a2189b6382 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..c72040c84b0 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,103 @@ +from odoo import models, fields, api +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 = 'Estate Property Information' + _order = 'id desc' + + name = fields.Char(string='Property Name', required=True) + description = fields.Text(string='Description') + postcode = fields.Char(string='Postcode') + date_availability = fields.Date(string='Available From', copy=False, default=(fields.Date.add(fields.Date.today(), months=3))) + expected_price = fields.Float(string='Expected Price', required=True) + selling_price = fields.Float(string='Selling Price', readonly=True, copy=False) + bedrooms = fields.Integer(string='Bedrooms', default=2) + living_area = fields.Integer(string='Living Area (sqm)') + facades = fields.Integer(string='Number of Facades') + garage = fields.Boolean(string='Garage') + garden = fields.Boolean(string='Garden') + garden_area = fields.Integer(string='Garden Area') + garden_orientation = fields.Selection([('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], string='Garden Orientation') + active = fields.Boolean(string='Active', default=True) + state = fields.Selection( + [ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled') + ], + string='Status', + 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) + tag_ids = fields.Many2many('estate.property.tag', string='Tags') + offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') + + total_area = fields.Integer(compute="_compute_total_area") + best_price = fields.Float(compute="_compute_best_price") + + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + "The property expected selling price must be strictly positive." + ) + _check_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + "The property selling price must be positive." + ) + + @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_price(self): + for record in self: + if record.offer_ids: + record.best_price = max(record.offer_ids.mapped('price')) + else: + record.best_price = 0.0 + + @api.onchange('garden') + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = 'north' + else: + self.garden_area = 0 + self.garden_orientation = False + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price_expected_price(self): + for record in self: + if not float_is_zero(record.selling_price, precision_digits=2) \ + and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) < 0: + raise ValidationError("The selling price must be at least 90% of the expected price.") + + @api.ondelete(at_uninstall=False) + def _check_state_on_delete(self): + for record in self: + if record.state not in ["new", "cancelled"]: + raise UserError("Cannot delete a property that is not new or cancelled.") + + def action_cancel_property(self): + for record in self: + if record.state == 'sold': + raise UserError("Sold properties cannot be cancelled.") + else: + record.state = 'cancelled' + + def action_sell_property(self): + for record in self: + if record.state == 'cancelled': + raise UserError("Cancelled properties cannot be sold.") + else: + record.state = 'sold' diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..07a2db11e62 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,57 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Estate Property Offer Information' + _order = 'price desc' + + price = fields.Float(string='Price') + status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string='Status', copy=False) + partner_id = fields.Many2one('res.partner', string='Partner', required=True) + property_id = fields.Many2one('estate.property', string='Property', required=True) + property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', string='Property Type', store=True) + validity = fields.Integer(string="Validity (days)", default=7) + date_deadline = fields.Date(string="Deadline", compute="_compute_deadline", inverse="_inverse_deadline") + + _check_offer_price = models.Constraint( + 'CHECK(price > 0)', + 'The offer price must be strictly positive.' + ) + + @api.model + def create(self, vals_list): + for vals in vals_list: + prop = self.env['estate.property'].browse(vals.get('property_id')) + if prop.offer_ids: + if vals.get('price') <= max(prop.offer_ids.mapped('price')): + raise UserError("The new offer price cannot be lower than existing offers.") + prop.state = 'offer_received' + return super().create(vals_list) + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + start_date = record.create_date.date() if record.create_date else fields.Date.today() + record.date_deadline = fields.Date.add(start_date, days=record.validity) + + def _inverse_deadline(self): + for record in self: + start_date = record.create_date.date() if record.create_date else fields.Date.today() + record.validity = (record.date_deadline - start_date).days + + def action_accept_offer(self): + for record in self: + if "accepted" in record.property_id.offer_ids.mapped('status'): + raise UserError("An offer has already been accepted for this property.") + record.status = 'accepted' + record.property_id.selling_price = record.price + record.property_id.state = 'offer_accepted' + record.property_id.buyer_id = record.partner_id + + def action_refuse_offer(self): + for record in self: + if record.status == 'accepted': + raise UserError("You cannot refuse an accepted offer.") + record.status = 'refused' diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..efc7476466b --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import models, fields + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate Property Tag Information' + _order = 'name asc' + + name = fields.Char(string='Tag Name', required=True) + color = fields.Integer(string="Color") + + _check_tag_name_unique = models.Constraint( + 'UNIQUE(name)', + 'The tag name must be unique.' + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..618d9fd427e --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,24 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate Property Type Information' + _order = 'sequence, name asc' + + name = fields.Char(string='Property Type', required=True) + property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') + sequence = fields.Integer(string='Sequence', default=1) + offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") + + offer_count = fields.Integer(compute='_compute_offer_count', string='Offer Count') + + _check_type_name_unique = models.Constraint( + 'UNIQUE(name)', + 'The property type name must be unique.' + ) + + @api.depends('property_ids.offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..a5a2c4dcf77 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', + 'salesperson_id', + string='Assigned 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..49bca99cac8 --- /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/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..acd4195c3ad --- /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..98c6d27b00a --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,43 @@ + + + Property Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + 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..1e818de003a --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,135 @@ + + + estate.property.kanban + estate.property + + + + + +
+ + + +
+ Expected Price: +
+
+ Best Offer: +
+
+ Selling Price: +
+
+ +
+
+
+
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + Estate Properties + estate.property + kanban,list,form + {'search_default_available': True} + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..4db7a533946 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,14 @@ + + + res.users.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..c908eeb22ba --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,14 @@ +{ + 'name': 'Real Estate Accounting', + 'depends': [ + 'base', + 'estate', + 'account', + ], + 'data': [ + 'security/ir.model.access.csv', + ], + 'application': True, + 'author': 'Dilya Anvarbekova', + 'license': 'LGPL-3', +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..3a400e163c6 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,26 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sell_property(self): + res = super().action_sell_property() + for record in self: + self.env['account.move'].create({ + 'partner_id': record.buyer_id.id, + 'move_type': 'out_invoice', + 'invoice_line_ids': [ + Command.create({ + 'name': "Commission (6%)", + 'quantity': 1.0, + 'price_unit': record.selling_price * 0.06, + }), + Command.create({ + 'name': "Administrative Fees", + 'quantity': 1.0, + 'price_unit': 100.00, + }) + ] + }) + return res diff --git a/estate_account/security/ir.model.access.csv b/estate_account/security/ir.model.access.csv new file mode 100644 index 00000000000..d9d6ba57cc5 --- /dev/null +++ b/estate_account/security/ir.model.access.csv @@ -0,0 +1,2 @@ +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