diff --git a/estate/DO_NOT_REMOVE.txt b/estate/DO_NOT_REMOVE.txt new file mode 100644 index 00000000000..2f0698240ca --- /dev/null +++ b/estate/DO_NOT_REMOVE.txt @@ -0,0 +1 @@ +this file should not be removed. 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..fc109be364a --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': "Estate", + 'author': "Arthur De Clerck", + 'license': "LGPL-3", + 'depends': ['base'], + 'category': "Real Estate/Brokerage", + 'application': True, + 'data': [ + 'security/ir.model.access.csv', + # 'security/security.xml', + + 'views/estate_property_offer_views.xml', + 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_menus.xml', + ] +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..93a6bd86abd --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..bb7ca1f20cc --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,102 @@ +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare, float_is_zero + +from odoo import api, fields, models + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate property informations" + _order = "id desc" + + name = fields.Char(required=True, string="Title") + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date(copy=False, default=fields.Date.add(fields.Date.today(), months=3), string="Available From") + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer(string="Garden Area (sqm)") + garden_orientation = fields.Selection( + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West'), + ], + help="Orientation precises where the garden is oriented" + ) + state = fields.Selection( + selection=[ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], + required=True, + default='new', + ) + 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="Salesman", default=lambda self: self.env.user) + property_tag_ids = fields.Many2many("estate.property.tag") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers", copy=False) + + total_area = fields.Float(compute="_compute_total_area", string="Total Area (sqm)") + best_price = fields.Float(compute="_compute_best_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 len(record.offer_ids) > 0 else 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 + + active = fields.Boolean(default=True) + + def sell_property(self): + for record in self: + if record.state == "cancelled": + raise UserError("Cancelled properties cannot be sold.") + record.state = "sold" + return True + + def cancel_property(self): + for record in self: + if record.state == "sold": + raise UserError("Sold properties cannot be cancelled.") + record.state = "cancelled" + return True + + _check_positive_expected_price = models.Constraint( + 'CHECK(expected_price >= 0)', + 'The expected price should be positive.' + ) + + _check_positive_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price should be positive.' + ) + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if float_compare(record.selling_price, record.expected_price * 0.9, 2) <= 0 and not float_is_zero(record.selling_price, 2): + raise ValidationError(r'The selling price must be at least 90 % of the expected price.') diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..dc82c444296 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,58 @@ +from odoo.exceptions import UserError + +from odoo import api, fields, models + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Offers for real estate properties" + _order = "price desc" + + price = fields.Float() + status = fields.Selection( + selection=[ + ('accepted', 'Accepted'), + ('refused', 'Refused') + ], + copy=False + ) + partner_id = fields.Many2one("res.partner", string="Partner", required=True) + property_id = fields.Many2one("estate.property", string="Property", required=True) + validity = fields.Integer(default=7, string="Validity (days)") + date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline", readonly=False) + property_type_id = fields.Many2one(related="property_id.property_type_id") + + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for record in self: + if record.create_date: + record.date_deadline = fields.Date.add(record.create_date, days=record.validity) + else: + record.date_deadline = fields.Date.add(fields.Date.today(), 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 = (record.date_deadline - fields.Date.today()).days + + def accept_offer(self): + for record in self: + if any(status for status in record.property_id.offer_ids.mapped('status') if status == "accepted"): + raise UserError("Only one offer can be accepted by property.") + record.status = "accepted" + record.property_id.selling_price = record.price + record.property_id.buyer_id = record.partner_id + record.property_id.state = "offer_accepted" + return True + + def refuse_offer(self): + for record in self: + record.status = "refused" + return True + + _check_price = models.Constraint( + 'CHECK(price >= 0)', + 'The offer price should be positive.' + ) diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..88346e4466f --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Tags for estate properties" + _order = "name" + + name = fields.Char(required=True) + color = fields.Integer() + + _unique_name = models.Constraint( + 'UNIQUE(name)', + 'Each property tag should have a unique name.' + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..dc9c3f7f9de --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,22 @@ +from odoo import fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate property types" + _order = "sequence, name" + + name = fields.Char(required=True) + sequence = fields.Integer('Sequence', default=1, help="Used to order types.") + property_ids = fields.One2many("estate.property", "property_type_id", string="Properties", copy=False) + offer_ids = fields.One2many(related="property_ids.offer_ids") + offer_count = fields.Integer(compute="_compute_offer_count") + + _unique_name = models.Constraint( + 'UNIQUE(name)', + 'Each property type should have a unique name.' + ) + + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..e20ec4dd90b --- /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/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..7769ad52671 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,6 @@ + + + + diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..74326cb4029 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..aae82bef0db --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,44 @@ + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + + +
+
+
+ + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + + + + + + + + + + + + + + + +