diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index a1cd72893d7..5e14e8beec8 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -25,6 +25,9 @@ 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' + ] }, - 'license': 'AGPL-3' + 'license': 'AGPL-3', } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index c4fb245621b..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..d99a6f632f1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,88 @@ +import { _t } from "@web/core/l10n/translation"; +import { Component, useState } from "@odoo/owl"; +import { Layout } from "@web/search/layout"; +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; +import { DashboardItem } from "./item/dashboard_item"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; + + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem}; + setup(){ + this.action = useService("action"); + this.statistics = useService("awesome_dashboard.statistics"); + this.dialog = useService("dialog"); + this.results = useState(this.statistics.stats); + this.items = registry.category("awesome_dashboard").getAll(); + 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; + } + openCustomers() { + this.action.doAction({ + type: "ir.actions.act_window", + res_model: "res.partner", + name: _t("Customers"), + views: [ + [false, "kanban"], + ], + }); + } + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + res_model: "crm.lead", + name: _t("Leads"), + 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, + enabled: !this.props.disabledItems.includes(item.id), + } + })); + } + done() { + this.props.close(); + } + onChange(checked, changedItem) { + changedItem.enabled = checked; + const newDisabledItems = Object.values(this.items).filter( + (item) => !item.enabled + ).map((item) => item.id) + browser.localStorage.setItem( + "disabledDashboardItems", + newDisabledItems, + ); + this.props.onUpdateConfiguration(newDisabledItems); + } +} + +registry.category("lazy_components").add("awesome_dashboard.dashboard", 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..90e1493325f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: grey; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..006b541538c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + +
+ + + + + +
+
+
+ + + Which cards do you whish to see ? + + + + + + + + + + +
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..9396b035122 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,67 @@ +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./piechart_card/piechart_card"; +import { registry } from "@web/core/registry"; +import { _t } from "@web/core/l10n/translation"; + + +const items = [ + { + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: _t("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: _t("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: _t("Number of new orders this month"), + value: data.nb_new_orders, + }) + }, + { + id: "cancelled_orders", + description: "Cancelled orders this month", + Component: NumberCard, + props: (data) => ({ + title: _t("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: _t("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: _t("Shirt orders by size"), + data: data.orders_by_size, + }) + } +] + +items.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); 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..5dc7b0866aa --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/item/dashboard_item.js @@ -0,0 +1,15 @@ +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 }, + }; + get width() { + const size = this.props.size || 1; + return `width: ${18 * size}rem;`; + } +} 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..f58d2a1203f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/item/dashboard_item.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
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..5c3344d6277 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,10 @@ +import { Component } from "@odoo/owl"; + + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { type: String }, + value: { type: Number }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..cd2c0143bce --- /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/piechart/piechart.js b/awesome_dashboard/static/src/dashboard/piechart/piechart.js new file mode 100644 index 00000000000..9ec803cd839 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart/piechart.js @@ -0,0 +1,37 @@ +import { Component, onWillStart, onMounted, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + + setup() { + this.canvasRef = useRef("canvas"); + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }); + onMounted(() => { + this.renderChart(); + }); + } + + renderChart() { + const ctx = this.canvasRef.el.getContext("2d"); + const data = this.props.data || {}; + new Chart(ctx, { + type: "pie", + data: { + labels: ["S", "M", "XL"], + datasets: [ + { + data: [ + data.s || 0, + data.m || 0, + data.xl || 0, + ], + }, + ], + }, + }); + } +} diff --git a/awesome_dashboard/static/src/dashboard/piechart/piechart.xml b/awesome_dashboard/static/src/dashboard/piechart/piechart.xml new file mode 100644 index 00000000000..0b1834f0b4e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart/piechart.xml @@ -0,0 +1,3 @@ + + + diff --git a/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.js b/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.js new file mode 100644 index 00000000000..2c81708847c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.js @@ -0,0 +1,14 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "../piechart/piechart"; + + +export class PieChartCard extends Component { + static components = { PieChart }; + static template = "awesome_dashboard.PieChartCard"; + + static components = { PieChart }; + static props = { + title: { type: String }, + values: { type: Object }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.xml b/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.xml new file mode 100644 index 00000000000..7116b6e20b0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart_card/piechart_card.xml @@ -0,0 +1,11 @@ + + + +
+
+
+ +
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/statistics_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js new file mode 100644 index 00000000000..14b7c87d01e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,21 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + + +const statisticsService = { + start() { + const stats = reactive({}); + async function loadStatistics() { + const result = await rpc("/awesome_dashboard/statistics"); + Object.assign(stats, result); + } + loadStatistics(); + setInterval(loadStatistics, 600000); + return { + stats, + }; + }, +}; + +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..0767cf3fbf1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,22 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + + +class AwesomeDashboardAction extends Component { + static components = { LazyComponent }; + + static template = xml` + + `; +} + +registry.category("actions").add( + "awesome_dashboard.dashboard", + AwesomeDashboardAction +); diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..350de94cfc9 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,20 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + + setup(){ + this.state = useState({ + isOpen: true, + }); + } + + toggle() { + this.state.isOpen = !this.state.isOpen; + } + + static props = { + title : String, + slots: Object, + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..65435d111bc --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,18 @@ + + +
+
+ + +
+ +
+ +
+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..1140c493eb4 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,16 @@ +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.Counter"; + + setup() { + this.state = useState({ value: 0 }); + } + + increment() { + this.state.value++; + if (this.props.onincrement) { + this.props.onincrement(); + } + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..6db9b2fc5bc --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,10 @@ + + +
+ Counter: + +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..4a8ffec4d47 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,17 @@ -import { Component } from "@odoo/owl"; +import { Component, 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.sum = useState({ value: 0 }); + } + + incrementSum() { + this.sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..1c1c63f2564 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,15 @@ - - + + +
- hello world + + + "The sum is :" +
+
+
-
diff --git a/awesome_owl/static/src/todo/todoList.xml b/awesome_owl/static/src/todo/todoList.xml new file mode 100644 index 00000000000..b17927f3461 --- /dev/null +++ b/awesome_owl/static/src/todo/todoList.xml @@ -0,0 +1,14 @@ + + Todo Input: +
+ + + +
+
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..ed750cfde13 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,21 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + id: Number, + description: String, + isCompleted: Boolean, + toggleTodo: Function, + removeTodo: Function, + }; + + onToggle() { + this.props.toggleTodo(this.props.id); + } + + onRemove(){ + this.props.removeTodo(this.props.id); + } +} 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..2caf9553de9 --- /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.inputRef = useAutofocus("InputValue") + this.todos = useState([]); + this.nextId = 1 + this.inputValue = useState({ text: "" }); + this.removeTodo = this.removeTodo.bind(this); + } + + addTodo(ev) + { + if (ev.keyCode != 13) return + this.todos.push({ + id : this.nextId++, + description : this.inputValue.text, + isCompleted : false + }) + this.inputValue.text = "" + } + + toggleTodo = (id) => { + const todo = this.todos.find(t => t.id == id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(id) { + const index = this.todos.findIndex(todo => todo.id === id); + if (index !== -1) { + this.todos.splice(index, 1); + } + } +} diff --git a/awesome_owl/static/src/todo/todoitem.xml b/awesome_owl/static/src/todo/todoitem.xml new file mode 100644 index 00000000000..ee3e5838559 --- /dev/null +++ b/awesome_owl/static/src/todo/todoitem.xml @@ -0,0 +1,14 @@ + +
+ + + id: - + description: - + iscompleted: + + +
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..46a5a66101c --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,11 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(refName) { + const ref = useRef(refName); + + onMounted(() => { + ref.el.focus(); + }); + + return ref; +} 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..e8409c57acc --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,26 @@ +{ + 'name': "Estate", + 'version': '0.1', + 'summary': "Real Estate Advertisement", + 'description': """ + This module allows you to manage real estate advertisements, including + properties, agents, and customer inquiries. + """, + 'author': "aykhu", + 'license': 'LGPL-3', + 'website': "https://www.odoo.com/app/estate", + 'category': 'Tutorials', + 'application': True, + 'depends': ['base', 'calendar', 'mail'], + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_issue_views.xml', + 'views/estate_property_visit_views.xml', + '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_menus.xml', + 'views/res_users_views.xml', + ], +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..7be08b9c0b5 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,7 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import res_users +from . import estate_property_visit +from . import estate_property_issues diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..277e6be3c67 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,162 @@ +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 = 'Estate Property' + _order = "id desc" + _inherit = ['mail.thread', 'mail.activity.mixin'] + + name = fields.Char(string='Title', required=True, default='Unknown') + description = fields.Text(string='Description') + postcode = fields.Char(string='Postal Code') + date_availability = fields.Date( + string='Available From', copy=False, default=lambda self: fields.Date.today() + relativedelta(months=3) + ) + expected_price = fields.Float(string='Expected Price', required=True) + selling_price = fields.Float( + string='Selling Price', readonly=True, copy=False + ) + living_area = fields.Integer(string='Living Area (sq m)') + bedrooms = fields.Integer(string='Bedrooms', default=2) + facades = fields.Integer(string='Facades') + has_garage = fields.Boolean(string="Has Garage ?") + has_garden = fields.Boolean(string="Has Garden ?") + garden_area = fields.Integer(string="Garden Area (sq m)") + active = fields.Boolean(string="Is Active ?", default=True) + garden_orientation = fields.Selection( + string="Garden Orientation", + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West') + ], + ) + state = fields.Selection( + string="Status", + selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled") + ], + required=True, default="new", copy=False + ) + property_type_id = fields.Many2one( + "estate.property.type", ondelete='cascade', string="Property Type" + ) + salesperson_id = fields.Many2one( + "res.users", string="Sales Person", default=lambda self: self.env.user + ) + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + property_tags_ids = fields.Many2many( + "estate.property.tag", string="Property Tags" + ) + offer_ids = fields.One2many("estate.property.offer", "property_id") + total_area = fields.Float(compute="_compute_total_area") + best_price = fields.Float( + string="Best Offer", compute="_compute_best_price", store=True + ) + visit_ids = fields.One2many('estate.property.visit', 'property_id') + issue_ids = fields.One2many('estate.property.issue', 'property_id') + issue_count = fields.Integer(compute='_compute_issue_count') + + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', 'Price must be strictly 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.depends('visit_ids') + def _compute_issue_count(self): + data = dict(self.env['estate.property.issue']._read_group( + [('property_id', 'in', self.ids)], + groupby=['property_id'], + aggregates=['__count'] + )) + + for record in self: + record.issue_count = data.get(record, 0) + # record.issue_count = len(record.issue_ids) + + @api.onchange('has_garden') + def _onchange_garden(self): + if self.has_garden: + self.garden_area = 10 + self.garden_orientation = 'north' + else: + self.garden_area = None + self.garden_orientation = None + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if float_is_zero(record.selling_price, precision_digits=2): + continue + min_price = record.expected_price * 0.9 + if float_compare( + record.selling_price, + min_price, + precision_digits=2 + ) < 0: + raise ValidationError(_( + "The selling price cannot be lower than 90% of the expected price." + )) + + def action_property_sold(self): + if self.state == "cancelled": + raise UserError(_("Cancelled property cannot be set as sold.")) + elif self.issue_ids.priority == '3' and self.issue_ids.state != "resolved": + raise UserError(_("High priority issue is still not resolved")) + else: + self.state = "sold" + return True + + def action_set_sold_rainbow_man(self): + self.action_property_sold() + + return { + 'effect': { + 'fadeout': 'slow', + 'img_url': '/web/static/img/smile.svg', + 'type': 'rainbow_man', + } + } + + def action_property_cancelled(self): + if self.state == "sold": + raise UserError(_("Sold property cannot be set as cancelled")) + else: + self.state = "cancelled" + return True + + def action_accept_best_offer(self): + best_offer = self.offer_ids.filtered_domain( + [('price', '=', self.best_price)]) + best_offer.action_offer_accepted() + return True + + @api.ondelete(at_uninstall=False) + def delete_state_check(self): + for record in self: + if record.state not in ('new', 'cancelled'): + raise UserError( + _("Only New or Cancelled properties can be deleted")) + return True diff --git a/estate/models/estate_property_issues.py b/estate/models/estate_property_issues.py new file mode 100644 index 00000000000..6ec1a6ef11c --- /dev/null +++ b/estate/models/estate_property_issues.py @@ -0,0 +1,88 @@ +from datetime import timedelta + +from odoo import api, fields, models + +AVAILABLE_PRIORITIES = [ + ('1', 'Low'), + ('2', 'Medium'), + ('3', 'High'), +] + + +class EstatePropertyIssues(models.Model): + _name = 'estate.property.issue' + _description = "Raise and Manage issues in properties" + + name = fields.Char(required=True) + property_id = fields.Many2one('estate.property', required=True) + reported_by = fields.Many2one('res.partner') + assigned_to = fields.Many2one('res.users') + issue_type = fields.Selection( + selection=[ + ('plumbing', 'Plumbing'), + ('electrical', 'Electrical'), + ('structural', 'Structural'), + ('other', 'other'), + ], + required=True + ) + state = fields.Selection( + string="Status", + selection=[ + ("new", "New"), + ("in_progress", "In progress"), + ("resolved", "Resolved"), + ("cancelled", "Cancelled") + ], + default="new", + ) + priority = fields.Selection( + AVAILABLE_PRIORITIES, compute="_compute_priority" + ) + resolved_date = fields.Date() + description = fields.Text() + is_overdue = fields.Boolean(compute="_compute_is_overdue", default=False) + + @api.depends('issue_type') + def _compute_priority(self): + for record in self: + if record.issue_type not in ('electrical', 'structural'): + record.priority = '1' + if record.issue_type == 'electrical': + record.priority = '2' + if record.issue_type == 'structural': + record.priority = '3' + + @api.depends('create_date', 'priority', 'resolved_date') + def _compute_is_overdue(self): + priority_days = { + '3': 2, + '2': 5, + '1': 10, + } + + for record in self: + start_date = record.create_date.date() if record.create_date else fields.Date.today() + resolve_date = record.resolved_date or fields.Date.today() + limit_days = priority_days.get(record.priority) + + if (resolve_date - start_date) > timedelta(days=limit_days): + record.is_overdue = True + else: + record.is_overdue = False + + @api.onchange('assigned_to') + def _check_state(self): + for record in self: + if record.assigned_to and record.state == "new": + record.state = "in_progress" + + def action_set_resolved(self): + self.state = 'resolved' + if not self.resolved_date: + self.resolved_date = fields.Date.today() + return True + + def action_set_cancelled(self): + self.state = 'cancelled' + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..ebcb794c133 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,79 @@ +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 = "Estate Property Offer" + _order = "price desc" + + price = fields.Float(string="Offer Price", required=True) + status = fields.Selection( + selection=[ + ("accepted", "Accepted"), + ("refused", "Refused"), + ], + string="Status", + copy=False, + ) + partner_id = fields.Many2one("res.partner", required=True) + property_id = fields.Many2one("estate.property", required=True) + validity = fields.Integer(string="Validity (days)", default=7) + date_deadline = fields.Date( + string="Deadline", compute='_compute_date_deadline', inverse="_inverse_deadline", + ) + property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) + + _check_offer_price = models.Constraint( + 'CHECK (price > 0)', 'Offer price must be strictly positive' + ) + + @api.depends('create_date', 'validity') + def _compute_date_deadline(self): + for record in self: + start_date = ( + record.create_date.date() if record.create_date else fields.Date.today() + ) + record.date_deadline = start_date + relativedelta(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 + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + current_price = vals.get('price') + property_id = self.env['estate.property'].browse(vals['property_id']) + for offer in property_id.offer_ids: + if current_price < offer.price: + raise UserError(_("Offer Price cannot be less than previous offer prices")) + + offers = super().create(vals_list) + + for offer in offers: + if offer.property_id.state == 'new': + offer.property_id.state = 'offer_received' + + return offers + + def action_offer_accepted(self): + if self.price < self.property_id.best_price: + raise UserError(_("Another higher price offer exists")) + self.status = "accepted" + self.property_id.selling_price = self.price + self.property_id.buyer_id = self.partner_id + self.property_id.state = "offer_accepted" + + offers = self.property_id.offer_ids.filtered(lambda x: x.status != "accepted") + offers.write({'status': 'refused'}) + return True + + def action_offer_refused(self): + self.status = "refused" + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..2bb729a1af9 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class EstatePropertyTags(models.Model): + _name = "estate.property.tag" + _description = "Estate Property Tag" + _order = "name" + + name = fields.Char(string="Name", required=True) + color = fields.Integer() + + _unique_tag_name = models.Constraint('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..cdbc264d72a --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,20 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate Property Type" + _order = "name" + + name = fields.Char(string="Name", required=True) + property_ids = fields.One2many("estate.property", "property_type_id") + sequence = fields.Integer() + offer_ids = fields.One2many("estate.property.offer", "property_type_id") + offer_count = fields.Integer(compute='_compute_offer_count') + + _unique_type_name = models.Constraint('UNIQUE(name)', "Type name must be unique") + + @api.depends('offer_count') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/estate_property_visit.py b/estate/models/estate_property_visit.py new file mode 100644 index 00000000000..24f346e3f02 --- /dev/null +++ b/estate/models/estate_property_visit.py @@ -0,0 +1,38 @@ +from datetime import timedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class EstatePropertyVisit(models.Model): + _name = "estate.property.visit" + _description = "Schedule for properties" + + salesperson_id = fields.Many2one(related="property_id.salesperson_id") + customer_name = fields.Many2one('res.partner') + visit_date = fields.Datetime(default=fields.Datetime.now()) + property_id = fields.Many2one('estate.property', required=True) + + @api.model_create_multi + def create(self, vals_list): + + visits = super().create(vals_list) + + for visit in visits: + stop_time = visit.visit_date + timedelta(hours=+1) + self.env['calendar.event'].create({ + 'name': 'Property Visit', + 'start': visit.visit_date, + 'stop': stop_time, + }) + + return visits + + @api.constrains('visit_date', 'property_id') + def _check_visit_time(self): + for record in self: + for visit in record.property_id.visit_ids: + if record.id == visit.id or record.visit_date.date() != visit.visit_date.date(): + continue + if record.visit_date - visit.visit_date < timedelta(hours=1): + raise UserError(_("2 visits cannot have same time")) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..a2cc9714f47 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _name = 'res.users' + _inherit = ['res.users'] + + property_ids = fields.One2many( + 'estate.property', 'salesperson_id', domain=[('state', 'not in', ('sold', 'cancelled'))] + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..662aadba025 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +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 +estate.access_estate_visit,access_estate_property_visit,estate.model_estate_property_visit,base.group_user,1,1,1,1 +estate.access_estate_issue,access_estate_property_issue,estate.model_estate_property_issue,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..f2de1677bc3 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_issue_views.xml b/estate/views/estate_property_issue_views.xml new file mode 100644 index 00000000000..ebbfa10dba9 --- /dev/null +++ b/estate/views/estate_property_issue_views.xml @@ -0,0 +1,64 @@ + + + + + Estate Property Issue + estate.property.issue + list,form + [('property_id', '=', active_id)] + + + + estate.property.issue.form + estate.property.issue + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + estate.property.issue.list + estate.property.issue + + + + + + + + + + + + +
diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..a3e0898a041 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,41 @@ + + + + Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + estate.property.offer.list + estate.property.offer + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + estate.property.type.list + estate.property.type + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..0311a910d8c --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,146 @@ + + + + Estate Property + estate.property + list,form,kanban + {'search_default_available_properties':1} + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +
+ +
+

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + estate.property.kanban + estate.property + + + + + +
+ +
+ +
+ Expected Price : +
+
+ Best Price : +
+
+ Selling Price : +
+ +
+
+
+
+
+
+
+ +
diff --git a/estate/views/estate_property_visit_views.xml b/estate/views/estate_property_visit_views.xml new file mode 100644 index 00000000000..6a6166c76a4 --- /dev/null +++ b/estate/views/estate_property_visit_views.xml @@ -0,0 +1,44 @@ + + + + + Estate Property Visit + estate.property.visit + list,form,calendar + [('property_id', '=', active_id)] + + + + estate.property.visit.list + estate.property.visit + + + + + + + + + + estate.property.visit.form + estate.property.visit + +
+ + + + +
+ + + estate.property.visit.calendar + estate.property.visit + + + + + + + + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..b3fca2a5e0a --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + 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..b4d4ff5cfad --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,6 @@ +{ + 'name': 'Estate Account', + 'author': "Ayush Khubchandani (aykhu)", + 'license': 'LGPL-3', + 'depends': ['estate', 'account'] +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..02b688798a3 --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_account diff --git a/estate_account/models/estate_account.py b/estate_account/models/estate_account.py new file mode 100644 index 00000000000..38c75f295ef --- /dev/null +++ b/estate_account/models/estate_account.py @@ -0,0 +1,26 @@ +from odoo import Command, models + + +class EstateAccount(models.Model): + _inherit = 'estate.property' + + def action_property_sold(self): + + super().action_property_sold() + + self.env['account.move'].create([{ + 'partner_id': self.salesperson_id.id, + 'move_type': 'out_invoice', + 'invoice_line_ids': [ + Command.create({ + 'name': '6% commision', + 'price_unit': self.selling_price * 0.06, + 'quantity': 1, + }), + Command.create({ + 'name': 'Administrative fees', + 'price_unit': 100, + 'quantity': 1, + }) + ] + }]) diff --git a/sale_renting_deposit/__init__.py b/sale_renting_deposit/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_renting_deposit/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_renting_deposit/__manifest__.py b/sale_renting_deposit/__manifest__.py new file mode 100644 index 00000000000..8a1eb9810d1 --- /dev/null +++ b/sale_renting_deposit/__manifest__.py @@ -0,0 +1,16 @@ +{ + 'name': 'Renting Deposit', + 'author': "Ayush Khubchandani (aykhu)", + 'license': 'LGPL-3', + 'depends': ['sale_renting', 'website_sale'], + 'data': [ + 'views/product_template_views.xml', + 'views/res_config_settings_views.xml', + 'views/website_sale_view.xml', + ], + 'assets': { + 'web.assets_frontend': [ + 'sale_renting_deposit/static/src/js/deposit_rental.js', + ], + }, +} diff --git a/sale_renting_deposit/models/__init__.py b/sale_renting_deposit/models/__init__.py new file mode 100644 index 00000000000..ab748108c8d --- /dev/null +++ b/sale_renting_deposit/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import res_config_settings +from . import sale_order_lines diff --git a/sale_renting_deposit/models/product_template.py b/sale_renting_deposit/models/product_template.py new file mode 100644 index 00000000000..d0a3bb1886c --- /dev/null +++ b/sale_renting_deposit/models/product_template.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + deposit_required = fields.Boolean(help="Enable if this product requires deposit.") + deposit_amount = fields.Float(help="This specifies deposit for 1 unit of this product.") diff --git a/sale_renting_deposit/models/res_config_settings.py b/sale_renting_deposit/models/res_config_settings.py new file mode 100644 index 00000000000..41e07de379d --- /dev/null +++ b/sale_renting_deposit/models/res_config_settings.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + deposit_product_id = fields.Many2one( + "product.product", + string="Deposit Product", + config_parameter="sale_renting.deposit_product_id" + ) diff --git a/sale_renting_deposit/models/sale_order_lines.py b/sale_renting_deposit/models/sale_order_lines.py new file mode 100644 index 00000000000..7392904e56c --- /dev/null +++ b/sale_renting_deposit/models/sale_order_lines.py @@ -0,0 +1,54 @@ +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + is_deposit_line = fields.Boolean(default=False) + deposit_origin_line_id = fields.Many2one('sale.order.line', ondelete='cascade') + + def _get_line_header(self): + if self.is_deposit_line and self.name: + return self.name + return super()._get_line_header() + + @api.model_create_multi + def create(self, vals_list): + order_lines = super().create(vals_list) + for line in order_lines: + if (line.product_id.deposit_required and not line.is_deposit_line): + deposit_product_param = self.env["ir.config_parameter"].sudo().get_param( + "sale_renting.deposit_product_id" + ) + deposit_product_id = int(deposit_product_param) + deposit_amount = line.product_id.deposit_amount + self.create({ + 'order_id': line.order_id.id, + 'product_id': deposit_product_id, + 'product_uom_qty': line.product_uom_qty, + 'price_unit': deposit_amount, + 'name': f"Deposit for {line.product_id.name}", + 'is_deposit_line': True, + 'deposit_origin_line_id': line.id, + }) + return order_lines + + def write(self, vals): + res = super().write(vals) + deposit_lines = self.env['sale.order.line'].search( + [('deposit_origin_line_id', 'in', self.ids)] + ) + for line in self: + if line.is_deposit_line: + continue + deposit_line = deposit_lines.filtered( + lambda l: l.deposit_origin_line_id == line + ) + if not deposit_line: + continue + deposit_line.write({ + 'product_uom_qty': line.product_uom_qty, + 'price_unit': line.product_id.deposit_amount, + 'name': f"Deposit for {line.product_id.name}", + }) + return res diff --git a/sale_renting_deposit/static/src/js/deposit_rental.js b/sale_renting_deposit/static/src/js/deposit_rental.js new file mode 100644 index 00000000000..36bda5c2001 --- /dev/null +++ b/sale_renting_deposit/static/src/js/deposit_rental.js @@ -0,0 +1,18 @@ +document.addEventListener('change', function (ev) { + const input = ev.target; + if (!input.matches('.js_main_product input[name="add_qty"]')) { + return; + } + const productEl = input.closest('.js_product'); + const depositEl = productEl?.querySelector('.o_deposit_wrapper'); + if (!depositEl) { + return; + } + const depositUnit = parseFloat(depositEl.dataset.depositUnit) || 0; + const quantity = parseFloat(input.value) || 0; + const total = (depositUnit * quantity).toFixed(2); + const target = depositEl.querySelector('.o_deposit_amount_value'); + if (target) { + target.textContent = total; + } +}); diff --git a/sale_renting_deposit/views/product_template_views.xml b/sale_renting_deposit/views/product_template_views.xml new file mode 100644 index 00000000000..e681c1ff387 --- /dev/null +++ b/sale_renting_deposit/views/product_template_views.xml @@ -0,0 +1,16 @@ + + + + + product.template.inherit.stock.rental + product.template + + + + + + + + + + diff --git a/sale_renting_deposit/views/res_config_settings_views.xml b/sale_renting_deposit/views/res_config_settings_views.xml new file mode 100644 index 00000000000..b3954d974aa --- /dev/null +++ b/sale_renting_deposit/views/res_config_settings_views.xml @@ -0,0 +1,19 @@ + + + + + res.config.settings.view.form.inherit.rental + res.config.settings + + + + +
+
+
+
+
+ +
diff --git a/sale_renting_deposit/views/website_sale_view.xml b/sale_renting_deposit/views/website_sale_view.xml new file mode 100644 index 00000000000..6e1238590cf --- /dev/null +++ b/sale_renting_deposit/views/website_sale_view.xml @@ -0,0 +1,27 @@ + + + + + +