From 94d5319b6ab11e3e408d6a27bf93cccf94142c66 Mon Sep 17 00:00:00 2001 From: Odoo Date: Mon, 21 Oct 2024 15:31:19 +0200 Subject: [PATCH] [ADD] Estate Module --- awesome_owl/static/src/card/card.js | 16 ++ awesome_owl/static/src/card/card.xml | 13 ++ awesome_owl/static/src/counter/counter.js | 15 ++ awesome_owl/static/src/counter/counter.xml | 7 + awesome_owl/static/src/playground.js | 3 + awesome_owl/static/src/playground.xml | 8 +- awesome_owl/views/templates.xml | 2 +- estate/__init__.py | 1 + estate/__manifest__.py | 24 +++ estate/demo/demo.xml | 13 ++ estate/models/__init__.py | 5 + estate/models/estate_property.py | 111 ++++++++++++++ estate/models/estate_property_offer.py | 74 +++++++++ estate/models/estate_property_tag.py | 15 ++ estate/models/estate_property_type.py | 27 ++++ estate/models/res_users.py | 9 ++ estate/security/ir.model.access.csv | 5 + estate/views/estate_menu.xml | 15 ++ estate/views/estate_property_offer_views.xml | 25 +++ estate/views/estate_property_tag_views.xml | 38 +++++ estate/views/estate_property_type_views.xml | 60 ++++++++ estate/views/estate_property_views.xml | 152 +++++++++++++++++++ estate/views/res_users_views.xml | 15 ++ estate_account/__init__.py | 1 + estate_account/__manifest__.py | 18 +++ estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 32 ++++ 27 files changed, 702 insertions(+), 3 deletions(-) create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/demo/demo.xml create mode 100644 estate/models/__init__.py create mode 100644 estate/models/estate_property.py create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tag.py create mode 100644 estate/models/estate_property_type.py create mode 100644 estate/models/res_users.py create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/views/estate_menu.xml create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tag_views.xml create mode 100644 estate/views/estate_property_type_views.xml create mode 100644 estate/views/estate_property_views.xml create mode 100644 estate/views/res_users_views.xml create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 0000000000..6a8fa5f963 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,16 @@ +/** @odoo-module */ + +import { Component } from "@odoo/owl"; + +export class Card extends Component {} + +Card.template = "awesome_owl.Card"; +Card.props = { + slots: { + type: Object, + shape: { + default: Object, + title: { type: Object, optional: true }, + }, + }, +}; \ 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 0000000000..f26ebaa691 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,13 @@ + + + +
+
+ +
+
+

+
+
+
+
\ 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 0000000000..e01f2b41b9 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,15 @@ +/** @odoo-module **/ + +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++; + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 0000000000..a5f3b84a5f --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,7 @@ + + + +

Counter:

+ +
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07b..699daa949a 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,10 @@ /** @odoo-module **/ import { Component } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card" export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Counter, Card } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f..51013c18f1 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,9 +1,13 @@ - - +
hello world + + + awesome card + awesome text +
diff --git a/awesome_owl/views/templates.xml b/awesome_owl/views/templates.xml index aa54c1a724..f69600718a 100644 --- a/awesome_owl/views/templates.xml +++ b/awesome_owl/views/templates.xml @@ -12,4 +12,4 @@ - + \ No newline at end of file diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /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 0000000000..03fd00bbf9 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,24 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Estate', + 'category': 'Tutorials/Estate', + 'summary': 'Real estate application', + 'description': "", + 'depends': [ + 'base_setup', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_offer_views.xml', + 'views/res_users_views.xml', + 'views/estate_menu.xml', + ], + 'installable': True, + 'application': True, + 'auto_install': False, + 'license': 'OEEL-1' +} diff --git a/estate/demo/demo.xml b/estate/demo/demo.xml new file mode 100644 index 0000000000..69e79ee6ea --- /dev/null +++ b/estate/demo/demo.xml @@ -0,0 +1,13 @@ + + + + + Mass cancel + + + list + code + action = records.action_cancel() + + + \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 0000000000..9a2189b638 --- /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 0000000000..9d14fdfc6e --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,111 @@ +from odoo import api, models, fields +from datetime import date +from dateutil.relativedelta import relativedelta +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + + name = fields.Char("Estate Name", required=True) + description = fields.Text("Description") + postcode = fields.Char("Postalcode") + date_availability = fields.Date('Date Availability', default=lambda self: date.today() + relativedelta(months=3)) + expected_price = fields.Float('Expected Price', required=True) + selling_price = fields.Float('Selling Price', readonly=True) + bedrooms = fields.Integer("Bedrooms", default=2) + living_area = fields.Integer("Living Area (sqm)") + facades = fields.Integer("Facades") + garage = fields.Boolean("Garage") + garden = fields.Boolean("Garden") + garden_area = fields.Integer("Garden Area (sqm)") + garden_orientation = fields.Selection(selection=[ + ('north', 'NORTH'), + ('south', 'SOUTH'), + ('west', 'WEST'), + ('east', 'EAST') + ]) + active = fields.Boolean("Active", default=True) + state = fields.Selection(selection=[ + ('new', 'NEW'), + ('offer_received', 'OFFER RECEIVED'), + ('offer_accepted', 'OFFER ACCEPTED'), + ('sold', 'SOLD'), + ('cancelled', 'CANCELLED') + ], default='new') + property_type_id = fields.Many2one('estate.property.type', string='Real Estate Type') + buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False) + salesperson_id = fields.Many2one('res.partner', string='Salesperson', default=lambda self: self.env.user) + tag_ids = fields.Many2many('estate.property.tag', string='Real Estate Tag') + offer_ids = fields.One2many('estate.property.offer', inverse_name='property_id') + total_area = fields.Float('Total Area (sqm)', compute='_compute_total_area', readonly=True) + best_offer = fields.Float('Best Offer', compute='_compute_best_offer', readonly=True) + _order = 'id desc' + + _sql_constraints = [ + ('expected_price', 'CHECK(expected_price > 0)', + 'The expected price should be strictly greater than 0.'), + ('selling_price', 'CHECK(selling_price >= 0)', + 'The selling price should be zero or strictly greater than 0 if an offer is accepted.'), + ] + + def action_reset_to_draft(self): + for record in self: + if record.state == 'sold': + raise UserError("You cannot reset a sold property to draft.") + record.state = 'new' + + def action_open_offers(self): + self.ensure_one() + return { + 'name': 'Property Offer', + 'views': [(self.env.ref('estate.estate_property_offer_view_list').id, 'list')], + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', self.offer_ids.ids)], + 'res_model': 'estate.property.offer' + } + + def action_cancel(self): + if self.state != 'cancelled': + self.state = 'cancelled' + + def action_sold(self): + if self.state == 'cancelled': + raise UserError("You can't sold an estate marked as CANCELLED") + self.state = 'sold' + + @api.ondelete(at_uninstall=False) + def on_delete(self, vals_list): + for val in vals_list: + if val and val['state'] == 'new' or val['state'] == 'cancelled': + raise UserError('You can not delete a new or cancelled property') + + @api.constrains('expected_price', 'selling_price') + def _check_expected_price(self): + for record in self: + if float_compare(record.expected_price * 0.9, record.selling_price, 3) == 1 and record.selling_price != 0: + raise ValidationError("The selling price must be at least the 90% of the expected price.") + + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + (record.garden_area or 0) + + @api.depends("offer_ids.price") + def _compute_best_offer(self): + for record in self: + if record.offer_ids: + record.best_offer = max(offer.price for offer in record.offer_ids) + else: + record.best_offer = 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 = None diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 0000000000..53beada3c2 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,74 @@ +from odoo import api, models, fields +from dateutil.relativedelta import relativedelta +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real Estate Property Offer" + + price = fields.Float("Offer Price", required=True) + status = fields.Selection(selection=[ + ('accepted', 'ACCEPTED'), + ('refused', 'REFUSED') + ]) + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', required=True) + validity = fields.Integer('Validity', default=7) + date_deadline = fields.Date('Date Deadline', compute='_compute_date_deadline', inverse='_inverse_date_deadline', store=True) + property_type_id = fields.Many2one( + "estate.property.type", related="property_id.property_type_id", string="Property Type", store=True + ) + _order = 'price desc' + + _sql_constraints = [ + ('price', 'CHECK(price > 0)', + 'The price of an offer should be strictly grater than 0.') + ] + + @api.model_create_multi + def create(self, vals_list): + for val in vals_list: + if val.get("property_id") and val.get("price"): + prop = self.env["estate.property"].browse(val["property_id"]) + + if prop.offer_ids: + max_offer = max(prop.mapped("offer_ids.price")) + if float_compare(val["price"], max_offer, precision_rounding=0.01) <= 0: + raise UserError("The offer must be higher than %.2f" % max_offer) + prop.state = "offer_received" + return super().create(vals_list) + + def action_accept(self): + for offer in self.property_id.offer_ids: + if offer.status == 'accepted': + raise UserError("An offer has already been accepted for this property.") + if self.status != 'accepted': + if self.property_id.state == 'sold': + raise UserError("You can't accept an offer for a property already sold") + self.status = 'accepted' + self.property_id.state = 'offer_accepted' + self.property_id.selling_price = self.price + self.property_id.buyer_id = self.partner_id.id + else: + raise UserError("You can't accept an offer already accepted") + + def action_refuse(self): + if not self.status: + self.status = 'refused' + else: + raise UserError("You can't refuse an offer already refused or already accepted") + + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.context_today(record) + record.date_deadline = create_date + relativedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + if record.create_date: + record.validity = (record.date_deadline - record.create_date.date()).days + else: + record.validity = 0 diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 0000000000..2af0fb96ef --- /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 = "Real Estate Property Tag" + + name = fields.Char("Estate Tag", required=True) + color = fields.Integer('Color') + _order = 'name desc' + + _sql_constraints = [ + ('name', 'UNIQUE(name)', + 'The name of the tag should be unique.') + ] diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 0000000000..a30c908825 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,27 @@ +from odoo import models, fields + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Real Estate Property Type" + + name = fields.Char("Estate Type", required=True) + property_ids = fields.One2many('estate.property', inverse_name='property_type_id') + sequence = fields.Integer('Sequence', default=1, help="Used to order types on the business needs") + offer_ids = fields.One2many('estate.property.offer', inverse_name='property_type_id') + _order = 'name desc' + + _sql_constraints = [ + ('name', 'UNIQUE(name)', + 'The name of the type should be unique.') + ] + + def action_open_offers(self): + self.ensure_one() + return { + 'name': 'Property Offer', + 'views': [(False, 'list')], + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', self.offer_ids.ids)], + 'res_model': 'estate.property.offer' + } diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 0000000000..c523163974 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", inverse_name="salesperson_id", 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 0000000000..c79331f2f1 --- /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 \ No newline at end of file diff --git a/estate/views/estate_menu.xml b/estate/views/estate_menu.xml new file mode 100644 index 0000000000..f87085959e --- /dev/null +++ b/estate/views/estate_menu.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 0000000000..5933a2cc98 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,25 @@ + + + + + estate.property.offer.view.list + estate.property.offer + + + + + + + +
+

+ +

+
+ + + + + + + + + + + + + + + +
+
+ + + + + Properties Type + estate.property.type + list,form,search + +
\ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 0000000000..8e6948423f --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,152 @@ + + + + estate.property.view.search + estate.property + + + + + + + + + + + + + + + + + estate.property.view.kanban + estate.property + + + + + + + + +

+ Expected Price: + +

+

+ Best Offer: + +

+

+ Selling price: + +

+ +
+
+
+
+
+ + + estate.property.view.list + estate.property + + + + + + + + + + + + + + + estate.property.view.form + estate.property + +
+
+
+ +
+ +
+
+
+

+ +

+ +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +