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..1fa7f08539c --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "estate", + "category": "", + "depends": [ + "base", + ], + "application": True, + "author": "Odoo S.A.", + "license": "LGPL-3", + "data": [ + "security/ir.model.access.csv", + "views/estate_property.xml", + "views/estate_property_offers.xml", + "views/estate_property_types.xml", + "views/estate_property_menus.xml", + ], +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..e34761630d1 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,6 @@ +from . import ( + estate_property, + estate_property_type, + estate_property_tags, + estate_property_offers, +) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..86bc80ce3c4 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,125 @@ +from odoo import models, fields, api +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" + _order = "name" + + name = fields.Char(required=True, default="Unknown") + property_type_id = fields.Many2one("estate.property.type", string="Type") + description = fields.Text() + tag_ids = fields.Many2many("estate.property.tags", string="Tags") + salesman_id = fields.Many2one("res.users", default=lambda self: self.env.user.id) + buyer_id = fields.Many2one( + "res.partner", default=lambda self: self.env.user.id, copy=False + ) + postcode = fields.Char() + date_availability = fields.Date(copy=False) + expected_price = fields.Float(required=True, default=15.6) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + total_area = fields.Float(compute="_compute_total_area") + best_price = fields.Float(compute="_compute_best_price") + garden_orientation = fields.Selection( + [ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West"), + ], + string="Garden Orientation", + ) + active = fields.Boolean(default=True) + state = fields.Selection( + [ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + required=True, + copy=False, + default="new", + readonly=True, + ) + offer_ids = fields.One2many( + "estate.property.offers", "property_id", string="Offers" + ) + _check_expected_price = models.Constraint( + "CHECK(expected_price > 0)", "Expected price must be positive." + ) + _check_selling_price = models.Constraint( + "CHECK(selling_price > 0)", "Property selling price must be positive." + ) + + @api.constrains("selling_price") + def _check_selling_price(self): + if float_compare(self.selling_price, (self.expected_price * 0.9), 2) == -1: + raise ValidationError( + "Selling Price must not be less than 90% of expected price." + ) + + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for realEstateProperty in self: + realEstateProperty.total_area = ( + realEstateProperty.living_area + realEstateProperty.garden_area + ) + + # @api.onchange("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") + def _compute_best_price(self): + self.best_price = max(self.offer_ids.mapped("price")) if self.offer_ids else 0 + + # @api.depends("offer_ids") + # def _compute_best_price(self): + # if self.offer_ids: + # price_list=[] + # price_list.append(offer.price) + # for i in range(len(price_list)): + # for j in range(len(price_list)): + # if price_list[i]>=price_list[j]: + # self.best_price= price_list[i] + # else: + # self.best_price=0 + # self.best_price = 0 + # if self.offer_ids: + # for offer in self.offer_ids: + # if offer.price > self.best_price: + # self.best_price = offer.price + + @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 = "" + + def set_sold(self): + if self.state == "cancelled": + raise UserError("Cancelled Properties Cannot be Sold") + else: + self.state = "sold" + return True + + def set_cancel(self): + if self.state == "sold": + raise UserError("Sold Properties cannot be Cancelled") + else: + self.state = "cancelled" + return True diff --git a/estate/models/estate_property_offers.py b/estate/models/estate_property_offers.py new file mode 100644 index 00000000000..f7d5da44ed6 --- /dev/null +++ b/estate/models/estate_property_offers.py @@ -0,0 +1,54 @@ +from datetime import timedelta + +from odoo import models, fields, api + + +class EstatePropertyOffers(models.Model): + _name = "estate.property.offers" + _description = "Property Offers" + + price = fields.Float(string="Price") + status = fields.Selection( + [("accepted", "Accepted"), ("refused", "Refused")], + string="Status", + copy="False", + ) + partner_id = fields.Many2one("res.partner", string="Customer", required=True) + property_id = fields.Many2one("estate.property", string="Property", required=True) + validity = fields.Integer(string="Validity", default=7) + date_deadline = fields.Date( + string="Date Deadline", + compute="_compute_date_deadline", + inverse="_inverse_date_deadline", + ) + _check_offer_price = models.Constraint( + "CHECK(price > 0)", "Offer price must be positive." + ) + + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = record.create_date.date() + timedelta( + days=record.validity + ) + else: + record.date_deadline = fields.Date.today() + timedelta( + days=record.validity + ) + + def _inverse_date_deadline(self): + for record in self: + record.validity = (record.date_deadline - record.create_date.date()).days + + def set_accepted(self): + for record in self: + record.status = "accepted" + record.property_id.selling_price = record.price + record.property_id.buyer_id.name = record.partner_id.name + return True + + def set_refused(self): + for record in self: + record.status = "refused" + return True diff --git a/estate/models/estate_property_tags.py b/estate/models/estate_property_tags.py new file mode 100644 index 00000000000..92918cf2fa5 --- /dev/null +++ b/estate/models/estate_property_tags.py @@ -0,0 +1,15 @@ +from odoo import models, fields + + +class EstatePropertyTags(models.Model): + _name = "estate.property.tags" + _description = "Estate Property Tags" + + name = fields.Char(string="Name", required=True) + property_id = fields.Many2one( + comodel_name="estate.property", + string="Property", + ) + _check_tag_name = models.Constraint( + "UNIQUE(name)", "Property 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..2d174524ae7 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,12 @@ +from odoo import models, fields + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Types of estate property" + + name = fields.Char(string="Name", required=True) + _check_property_type = models.Constraint( + "UNIQUE(name)", + "Property type must be unique", + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..0a3f912bc06 --- /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,estate.property.type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag,estate.property.tag,model_estate_property_tags,base.group_user,1,1,1,1 +access_estate_property_offer,estate.property.offer,model_estate_property_offers,base.group_user,1,1,1,1 diff --git a/estate/views/estate_property.xml b/estate/views/estate_property.xml new file mode 100644 index 00000000000..4ce097a527e --- /dev/null +++ b/estate/views/estate_property.xml @@ -0,0 +1,128 @@ + + + + + Properties + estate.property + list,form + + + + + Property Tags + estate.property.tags + list,form + + + + + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +
+

+ +

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