diff --git a/DO_NOT_REMOVE_THIS.txt b/DO_NOT_REMOVE_THIS.txt
new file mode 100644
index 00000000000..e69de29bb2d
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..d7bc26e9e7e
--- /dev/null
+++ b/estate/__manifest__.py
@@ -0,0 +1,22 @@
+{
+ 'name': "Estate",
+
+ 'author': "Odoo",
+ 'website': "https://www.odoo.com",
+
+ 'category': 'Tutorials',
+ 'version': '0.1',
+
+ 'depends': ['base', 'web'],
+ 'data': [
+ 'views/estate_property_tag_views.xml',
+ 'views/estate_property_type_views.xml',
+ 'views/estate_property_search_view.xml',
+ 'views/estate_property_views.xml',
+ 'views/estate_menus.xml',
+ 'security/ir.model.access.csv',
+ ],
+ 'application': True,
+ 'installable': True,
+ 'license': 'AGPL-3'
+}
diff --git a/estate/models/__init__.py b/estate/models/__init__.py
new file mode 100644
index 00000000000..ef0cd554275
--- /dev/null
+++ b/estate/models/__init__.py
@@ -0,0 +1,4 @@
+from . import estate
+from . import property_type
+from . import property_tag
+from . import offer
diff --git a/estate/models/estate.py b/estate/models/estate.py
new file mode 100644
index 00000000000..a1a2309e913
--- /dev/null
+++ b/estate/models/estate.py
@@ -0,0 +1,94 @@
+from odoo import api, fields, models
+from odoo.exceptions import UserError, ValidationError
+from odoo.tools.float_utils import float_compare, float_is_zero
+
+
+class Estate(models.Model):
+ _name = 'estate.property'
+ _description = 'Estate Property'
+
+ name = fields.Char("Property Name", required=True)
+ description = fields.Text("Description")
+ postcode = fields.Char("Postcode")
+ date_availability = fields.Date("Available From", default=fields.Date.add(fields.Date.today(), months=3))
+ expected_price = fields.Float("Expected Price", required=True)
+ selling_price = fields.Float("Selling Price", readonly=True, copy=False)
+ bedrooms = fields.Integer("Bedrooms", default=2)
+ living_area = fields.Integer("Living Area (sqm)")
+ facades = fields.Integer("Facades")
+ garage = fields.Boolean("Garage", default=True)
+ garden = fields.Boolean("Garden", default=True)
+ garden_area = fields.Integer("Garden Area (sqm)")
+ garden_orientation = fields.Selection(
+ string="Garden Orientation",
+ selection=[('north', "North"), ('south', "South"), ('east', "East"), ('west', "West")],
+ required=True)
+ status = fields.Selection(
+ string="Status",
+ selection=[('new', "New"), ('offer_received', "Offer Received"), ('offer_accepted', "Offer Accepted"), ('sold', "Sold"), ('canceled', "Canceled")],
+ default='new',
+ required=True)
+ active = fields.Boolean("Active", default=True)
+ 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="Salesperson", default=lambda self: self.env.user)
+ tag_ids = fields.Many2many('estate.property.tag', string="Tags")
+ offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
+ total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area')
+ best_price = fields.Float("Best Offer", 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 record.offer_ids else 0.0
+
+ @api.onchange('offer_ids')
+ def _onchange_property_status(self):
+ for record in self:
+ if record.status == 'new' and len(record.offer_ids) > 0:
+ record.status = 'offer_received'
+ else:
+ record.status = record.status
+
+ @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_mark_sold(self):
+ for record in self:
+ if record.status == 'canceled':
+ raise UserError("Canceled properties cannot be sold.")
+ record.status = 'sold'
+
+ def action_mark_cancel(self):
+ for record in self:
+ if record.status == 'sold':
+ raise UserError("Sold properties cannot be canceled.")
+ record.status = 'canceled'
+
+ _check_expected_price = models.Constraint(
+ 'CHECK(expected_price > 0)',
+ 'The expected price must be strictly positive'
+ )
+
+ _check_selling_price = models.Constraint(
+ 'CHECK(selling_price >= 0)',
+ 'The selling price must be positive'
+ )
+
+ @api.constrains('selling_price')
+ def _check_selling_price(self):
+ for record in self:
+ if not float_is_zero(record.selling_price, precision_digits=2):
+ if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) < 0:
+ raise ValidationError('The selling price must be atleast 90% of the expected price! You must reduce the expected price to accept the offer')
diff --git a/estate/models/offer.py b/estate/models/offer.py
new file mode 100644
index 00000000000..bd6b50cb2ce
--- /dev/null
+++ b/estate/models/offer.py
@@ -0,0 +1,51 @@
+from odoo import api, fields, models
+
+
+class Offer(models.Model):
+ _name = 'estate.property.offer'
+ _description = 'Estate Property Offer'
+
+ price = fields.Float("Offer Price")
+ status = fields.Selection(
+ string="Status",
+ 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('Validity (days)', default=7)
+ date_deadline = fields.Date("Deadline", compute='_compute_date_deadline', inverse="_inverse_date_deadline")
+
+ @api.depends('validity', 'create_date')
+ def _compute_date_deadline(self):
+ for record in self:
+ create_date = record.create_date if record.create_date else fields.Date.today()
+ record.date_deadline = fields.Date.add(create_date, days=record.validity)
+
+ def _inverse_date_deadline(self):
+ for record in self:
+ create_date = record.create_date if record.create_date else fields.Date.today()
+ record.validity = (record.date_deadline - create_date.date()).days
+
+ def action_accept_offer(self):
+ for record in self:
+ record.status = 'accepted'
+ record.property_id.selling_price = record.price
+ record.property_id.buyer_id = record.partner_id
+ record.property_id.status = 'offer_accepted'
+
+ # Reject other offers
+ other_offers = record.property_id.offer_ids.filtered(lambda o: o.id != record.id)
+ other_offers.action_reject_offer()
+
+ def action_reject_offer(self):
+ for record in self:
+ record.status = 'refused'
+ if record.property_id.status == 'offer_accepted' and record.property_id.buyer_id == record.partner_id:
+ record.property_id.selling_price = 0.0
+ record.property_id.buyer_id = False
+ record.property_id.status = 'offer_received'
+
+ _check_price = models.Constraint(
+ 'CHECK(price > 0)',
+ 'The offer price must be strictly positive'
+ )
diff --git a/estate/models/property_tag.py b/estate/models/property_tag.py
new file mode 100644
index 00000000000..c99f324472f
--- /dev/null
+++ b/estate/models/property_tag.py
@@ -0,0 +1,13 @@
+from odoo import fields, models
+
+
+class PropertyTag(models.Model):
+ _name = 'estate.property.tag'
+ _description = 'Estate Property Tag'
+
+ name = fields.Char("Tag Name", required=True)
+
+ _unique_name = models.Constraint(
+ 'UNIQUE(name)',
+ 'The property tag name must be unique'
+ )
diff --git a/estate/models/property_type.py b/estate/models/property_type.py
new file mode 100644
index 00000000000..589715eb881
--- /dev/null
+++ b/estate/models/property_type.py
@@ -0,0 +1,13 @@
+from odoo import fields, models
+
+
+class PropertyType(models.Model):
+ _name = 'estate.property.type'
+ _description = 'Estate Property Type'
+
+ name = fields.Char("Property Type", required=True)
+
+ _unique_name = models.Constraint(
+ 'UNIQUE(name)',
+ 'The property type name 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..839f297bb3c
--- /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_model,access_estate_model,model_estate_property,base.group_user,1,1,1,1
+access_property_type_model,access_property_type_model,model_estate_property_type,base.group_user,1,1,1,1
+access_property_tag_model,access_property_tag_model,model_estate_property_tag,base.group_user,1,1,1,1
+access_property_offer_model,access_property_offer_model,model_estate_property_offer,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..e0a8ba1b98a
--- /dev/null
+++ b/estate/views/estate_menus.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/estate/views/estate_property_search_view.xml b/estate/views/estate_property_search_view.xml
new file mode 100644
index 00000000000..c9b909a1460
--- /dev/null
+++ b/estate/views/estate_property_search_view.xml
@@ -0,0 +1,22 @@
+
+
+ estate.property.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml
new file mode 100644
index 00000000000..0ec3dc550e0
--- /dev/null
+++ b/estate/views/estate_property_tag_views.xml
@@ -0,0 +1,8 @@
+
+
+
+ Property Tags
+ estate.property.tag
+ list,form
+
+
diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml
new file mode 100644
index 00000000000..6384061b8ee
--- /dev/null
+++ b/estate/views/estate_property_type_views.xml
@@ -0,0 +1,8 @@
+
+
+
+ Property Types
+ estate.property.type
+ list,form
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml
new file mode 100644
index 00000000000..49628b0757a
--- /dev/null
+++ b/estate/views/estate_property_views.xml
@@ -0,0 +1,94 @@
+
+
+
+ View Records
+ estate.property
+ list,form
+
+
+
+ estate.property.tree
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.form
+ estate.property
+
+
+
+
+