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..81784e94540 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "Real Estate", + "depends": ["base"], + "data": [ + "security/estate_security.xml", + "security/ir.model.access.csv", + "views/estate_property_views.xml", + "views/estate_property_type_views.xml", + "views/estate_property_tag_views.xml", + "views/estate_property_offer_views.xml", + "views/estate_menus.xml", + "data/demo_types.xml", + "data/demo_tags.xml", + "data/demo_property.xml", + ], + "application": True, + "author": "dhruvi kalariya", + "license": "LGPL-3", + "installable": True, +} diff --git a/estate/data/demo_property.xml b/estate/data/demo_property.xml new file mode 100644 index 00000000000..b4196de22df --- /dev/null +++ b/estate/data/demo_property.xml @@ -0,0 +1,38 @@ + + + + House in ahemedabad + 700000 + near sg highway + 123456 + 123456 + 3 + 180 + 2 + True + True + 120 + south + True + + + + + + Flat in surat + 500000 + near station + 543210 + 123456 + 3 + 180 + 2 + True + True + 120 + west + True + + + + diff --git a/estate/data/demo_tags.xml b/estate/data/demo_tags.xml new file mode 100644 index 00000000000..48db146711d --- /dev/null +++ b/estate/data/demo_tags.xml @@ -0,0 +1,22 @@ + + + + Renovated + + + + Cozy + + + + Luxury + + + + With Pool + + + + Sea View + + diff --git a/estate/data/demo_types.xml b/estate/data/demo_types.xml new file mode 100644 index 00000000000..f8f0793baf6 --- /dev/null +++ b/estate/data/demo_types.xml @@ -0,0 +1,14 @@ + + + + Residential + + + + Commercial + + + + Industrial + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..2f1821a39c1 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,4 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..50605270e6c --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,124 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + + name = fields.Char(string="Title", required=True, default="Unknown") + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + date_availability = fields.Date( + string="Available From", + copy=False, + default=lambda self: fields.Date.context_today(self) + relativedelta(months=3), + ) + expected_price = fields.Float( + string="Expected Price", required=True, digits=(16, 2) + ) + 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="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") + 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", + copy=False, + default="new", + readonly=True, + ) + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + salesperson_id = fields.Many2one( + "res.users", + string="Salesperson", + default=lambda self: self.env.user, + ) + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + total_area = fields.Integer( + string="Total Area (sqm)", compute="_compute_total_area" + ) + best_price = fields.Float(string="Best Price", compute="_compute_best_price") + + _check_expected_price = models.Constraint( + "CHECK(expected_price > 0)", + "A property expected price must be strictly positive.", + ) + _check_selling_price = models.Constraint( + "CHECK(selling_price >= 0)", "A property selling price must be positive." + ) + + @api.constrains("expected_price", "selling_price") + def _check_price_difference(self): + for record in self: + if ( + not float_is_zero(record.selling_price, precision_digits=2) + and float_compare( + record.selling_price, + record.expected_price * 0.9, + precision_digits=2, + ) + < 0 + ): + raise ValidationError( + "The selling price cannot be lower than 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 + + @api.depends("offer_ids.price") + def _compute_best_price(self): + for record in self: + record.best_price = ( + max(record.offer_ids.mapped("price")) if record.offer_ids else 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 + + def action_sold(self): + for record in self: + if record.state == "cancelled": + raise UserError("You can not sold a cancelled property.") + record.state = "sold" + return True + + def action_cancel(self): + for record in self: + if record.state == "sold": + raise UserError("You can not cancel a sold property.") + record.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..c438f91d3e1 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,75 @@ +from datetime import timedelta + +from odoo import api, fields, models + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real Estate Property Offer" + + price = fields.Float(string="Price") + + _check_price = models.Constraint( + "CHECK(price > 0)", "An offer price must be strictly positive." + ) + status = fields.Selection( + [ + ("accepted", "Accepted"), + ("rejected", "Rejected"), + ], + string="Status", + copy=False, + ) + partner_id = fields.Many2one("res.partner", string="Partner", required=True) + property_id = fields.Many2one( + "estate.property", string="Property", required=True, ondelete="cascade" + ) + validity = fields.Integer(string="Validity", default=7) + date_deadline = fields.Date( + string="Deadline", + compute="_compute_date_deadline", + inverse="_inverse_date_deadline", + ) + + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for offer in self: + start_date = ( + offer.create_date.date() if offer.create_date else fields.Date.today() + ) + offer.date_deadline = start_date + timedelta(days=offer.validity) + + def _inverse_date_deadline(self): + for offer in self: + if offer.date_deadline: + start_date = ( + offer.create_date.date() + if offer.create_date + else fields.Date.today() + ) + offer.validity = (offer.date_deadline - start_date).days + + @api.onchange("date_deadline") + def _onchange_date_deadline(self): + self._inverse_date_deadline() + + @api.model_create_multi + def create(self, vals_list): + 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_accept(self): + for offer in self: + offer.status = "accepted" + offer.property_id.selling_price = offer.price + offer.property_id.buyer_id = offer.partner_id + offer.property_id.state = "offer_accepted" + return True + + def action_reject(self): + for offer in self: + offer.status = "rejected" + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..d3eef70d6de --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,18 @@ +from random import randint + +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Real Estate Property Tag" + + def _default_color(self): + return randint(1, 11) + + name = fields.Char(string="Name", required=True) + color = fields.Integer( + string="Color Index", default=lambda self: self._default_color() + ) + + _check_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..09e4aaf6683 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Real Estate Property Type" + + name = fields.Char(string="Type", required=True) + + _check_name = models.Constraint("UNIQUE(name)", "Type name must be unique") diff --git a/estate/security/estate_security.xml b/estate/security/estate_security.xml new file mode 100644 index 00000000000..bcfbd7bb73b --- /dev/null +++ b/estate/security/estate_security.xml @@ -0,0 +1,28 @@ + + + + Real Estate + + + + Access + + + + Agent + + + + + + Buyer + + + + + + Owner + + + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..5800cb94f40 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,20 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property,estate_property_access,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_agent,estate_property_agent,model_estate_property,estate.res_groups_agent,1,1,1,1 +access_estate_property_buyer,estate_property_buyer,model_estate_property,estate.res_groups_buyer,1,0,0,0 +access_estate_property_owner,estate_property_owner,model_estate_property,estate.res_groups_owner,1,1,1,1 + +access_estate_property_type,estate_property_type_access,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_type_agent,estate_property_type_agent,model_estate_property_type,estate.res_groups_agent,1,1,1,1 +access_estate_property_type_buyer,estate_property_type_buyer,model_estate_property_type,estate.res_groups_buyer,1,0,0,0 +access_estate_property_type_owner,estate_property_type_owner,model_estate_property_type,estate.res_groups_owner,1,1,1,1 + +access_estate_property_tag,estate_property_tag_access,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_tag_agent,estate_property_tag_agent,model_estate_property_tag,estate.res_groups_agent,1,1,1,1 +access_estate_property_tag_buyer,estate_property_tag_buyer,model_estate_property_tag,estate.res_groups_buyer,1,0,0,0 +access_estate_property_tag_owner,estate_property_tag_owner,model_estate_property_tag,estate.res_groups_owner,1,1,1,1 + +access_estate_property_offer,estate_property_offer_access,model_estate_property_offer,base.group_user,1,1,1,1 +access_estate_property_offer_agent,estate_property_offer_agent,model_estate_property_offer,estate.res_groups_agent,1,1,1,1 +access_estate_property_offer_buyer,estate_property_offer_buyer,model_estate_property_offer,estate.res_groups_buyer,1,0,0,0 +access_estate_property_offer_owner,estate_property_offer_owner,model_estate_property_offer,estate.res_groups_owner,1,1,1,1 diff --git a/estate/static/description/icon.png b/estate/static/description/icon.png new file mode 100644 index 00000000000..49aa15839db Binary files /dev/null and b/estate/static/description/icon.png differ diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..6929b0344ec --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..24a6a5da355 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,36 @@ + + + + estate.property.offer.list + estate.property.offer + + + + + + +