diff --git a/README.md b/README.md
index a0158d919ee..0fbe0e2b416 100644
--- a/README.md
+++ b/README.md
@@ -9,3 +9,13 @@ tutorial's solutions, and one for the
[Master the Odoo web framework](https://www.odoo.com/documentation/latest/developer/tutorials/master_odoo_web_framework.html)
tutorial's solutions. For example, `17.0`, `17.0-discover-js-framework-solutions` and
`17.0-master-odoo-web-framework-solutions`.
+
+
+./odoo-bin --addons-path="addons/,../enterprise/,../tutorials" -d rd-demo -u estate --dev xml
+
+dropdb rd-demo
+createdb rd-demo
+psql -d rd-demo
+
+
+lsof -i :8069
diff --git a/estate/__init__.py b/estate/__init__.py
new file mode 100644
index 00000000000..a9e3372262c
--- /dev/null
+++ b/estate/__init__.py
@@ -0,0 +1,2 @@
+
+from . import models
diff --git a/estate/__manifest__.py b/estate/__manifest__.py
new file mode 100644
index 00000000000..129e77353cc
--- /dev/null
+++ b/estate/__manifest__.py
@@ -0,0 +1,20 @@
+{
+ 'name': 'My Estate',
+ 'version': '1.9',
+ 'summary': 'Test module to remember how it works mdr',
+ 'website': 'https://www.odoo.com/app/estate',
+ 'depends': [
+ 'base',
+ ],
+ 'data': [
+ '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',
+ ],
+ 'installable': True,
+ 'application': True,
+ 'author': 'brbu',
+}
diff --git a/estate/models/__init__.py b/estate/models/__init__.py
new file mode 100644
index 00000000000..449b55018ae
--- /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
diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py
new file mode 100644
index 00000000000..366c18fd5c1
--- /dev/null
+++ b/estate/models/estate_property.py
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError, ValidationError
+from odoo.tools.float_utils import float_compare, float_is_zero
+
+
+class EstateProperty(models.Model):
+ _name = "estate.property"
+ _description = "Properties of the estate"
+
+ name = fields.Char(required=True, string="Title")
+ description = fields.Text()
+ tag_ids = fields.Many2many("estate.property.tag", string="Tags")
+
+ property_type_id = fields.Many2one("estate.property.type", string="Property Type")
+ salesperson_id = fields.Many2one("res.users", default=lambda self: self.env.user)
+ buyer_id = fields.Many2one("res.partner", copy=False)
+ offer_ids = fields.One2many("estate.property.offer", "property_id", copy=False)
+ best_offer = fields.Float(compute="_compute_best_offer", string="Best Offer", store=True)
+
+ postcode = fields.Char()
+ date_availability = fields.Date(copy=False, string="Available From", default=lambda self: fields.Date.add(fields.Date.today(), months=3))
+ expected_price = fields.Float(required=True, string="Expected Price")
+ selling_price = fields.Float(readonly=True, string="Selling Price", copy=False)
+
+ bedrooms = fields.Integer(default=2)
+ living_area = fields.Integer(string="Living Area (sqm)")
+ facade = fields.Integer(string="Façade")
+ garage = fields.Boolean(string="Garage")
+ garden = fields.Boolean(string="Garden")
+ garden_area = fields.Integer(string="Garden Area (sqm)")
+ garden_orientation = fields.Selection(
+ string="Garden Orientation",
+ selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")],
+ )
+ total_area = fields.Integer(string="Total Area (sqm)", compute="_compute_total_area", store=True)
+
+ active = fields.Boolean(default=True)
+ state = fields.Selection(
+ string="Status",
+ selection=[("new","New"), ("offer_received","Offer Received"), ("offer_accepted","Offer Accepted"), ("sold","Sold"), ("cancelled","Cancelled")],
+ required=True,
+ copy=False,
+ default="new",
+ )
+
+ @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_offer(self):
+ for record in self:
+ if record.offer_ids:
+ record.best_offer = max(record.offer_ids.mapped("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 = None
+
+ def action_sold(self):
+ for record in self:
+ if record.state == "cancelled":
+ raise UserError("A cancelled property cannot be sold !")
+ record.state = "sold"
+ return True
+
+ def action_cancelled(self):
+ for record in self:
+ if record.state == "sold":
+ raise UserError("A sold property cannot be cancelled !")
+ record.state = "cancelled"
+ return True
+
+ _positive_expected_price = models.Constraint(
+ 'CHECK(expected_price > 0)',
+ 'The expected price should be strictly positive.',
+ )
+
+ _positive_selling_price = models.Constraint(
+ 'CHECK(selling_price >= 0)',
+ 'The selling price should be strictly positive.',
+ )
+
+ @api.constrains("selling_price", "expected_price")
+ def _check_selling_price(self):
+ for record in self:
+ if not float_is_zero(record.selling_price, 2) and float_compare(record.selling_price, record.expected_price*0.9, 2) == -1:
+ raise ValidationError(_("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..f5140c3d34a
--- /dev/null
+++ b/estate/models/estate_property_offer.py
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+from odoo import models, fields, api, _
+
+
+class EstatePropertyOffer(models.Model):
+ _name = "estate.property.offer"
+ _description = "Property offers for the estate"
+
+ price = fields.Float()
+ status = fields.Selection(
+ string="Status",
+ selection=[("accepted", "Accepted"), ("refused", "Refused")],
+ copy=False,
+ readonly=True,
+ )
+ validity = fields.Integer(string="Validity (days)", default=7)
+ date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True)
+
+ partner_id = fields.Many2one("res.partner", copy=False)
+ property_id = fields.Many2one("estate.property", string="Property", copy=False)
+
+ @api.depends("create_date", "validity")
+ def _compute_date_deadline(self):
+ for record in self:
+ record.date_deadline = fields.Date.add(record.create_date, days=record.validity)
+
+ @api.depends("date_deadline", "create_date")
+ def _inverse_date_deadline(self):
+ for record in self:
+ record.validity = (record.date_deadline - record.create_date).days
+
+ def action_accept(self):
+ for record in self:
+ for other_offer in record.property_id.offer_ids:
+ if other_offer.status == "accepted" :
+ other_offer.status = None
+ Warning("An other offer acceptation was cancelled : only one offer can be accepted at a time !")
+ record.status = "accepted"
+ record.property_id.buyer_id = record.partner_id
+ record.property_id.selling_price = record.price
+ return True
+
+ def action_reset(self):
+ for record in self:
+ if record.status == "accepted":
+ record.property_id.buyer_id = None
+ record.property_id.selling_price = 0
+ record.status = None
+ return True
+
+ def action_refuse(self):
+ for record in self:
+ if record.status == "accepted":
+ record.property_id.buyer_id = None
+ record.property_id.selling_price = 0
+ record.status = "refused"
+ return True
+
+ _positive_offer_price = models.Constraint(
+ 'CHECK(price > 0)',
+ 'The offer prices should be strictly positive.',
+ )
\ No newline at end of file
diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py
new file mode 100644
index 00000000000..30bc7367a92
--- /dev/null
+++ b/estate/models/estate_property_tag.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+from odoo import models, fields
+
+
+class EstatePropertyTag(models.Model):
+ _name = "estate.property.tag"
+ _description = "Property tags for the estate"
+
+ name = fields.Char(required=True)
+
+ _name_uniq = models.Constraint(
+ 'unique(name)',
+ 'The nae 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..1bc64f42792
--- /dev/null
+++ b/estate/models/estate_property_type.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+from odoo import models, fields
+
+
+class EstatePropertyType(models.Model):
+ _name = "estate.property.type"
+ _description = "Property types of the estate"
+
+ name = fields.Char(required=True)
+
+ _name_uniq = models.Constraint(
+ 'unique(name)',
+ 'The nae 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..49bca99cac8
--- /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/views/estate_menus.xml b/estate/views/estate_menus.xml
new file mode 100644
index 00000000000..7621a785134
--- /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..ee6d46eb474
--- /dev/null
+++ b/estate/views/estate_property_offer_views.xml
@@ -0,0 +1,35 @@
+
+
+
+
+ estate.property.offer.list
+ estate.property.offer
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.offer.form
+ estate.property.offer
+
+
+
+
+
+
diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml
new file mode 100644
index 00000000000..48096ec30c2
--- /dev/null
+++ b/estate/views/estate_property_tag_views.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ estate.property.tag.list
+ estate.property.tag
+
+
+
+
+
+
+
+
+ estate.property.tag.form
+ estate.property.tag
+
+
+
+
+
+
+ estate.property.tag.search
+ estate.property.tag
+
+
+
+
+
+
+
+
+ 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..0c392c30d4d
--- /dev/null
+++ b/estate/views/estate_property_type_views.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ estate.property.type.list
+ estate.property.type
+
+
+
+
+
+
+
+
+ estate.property.type.form
+ estate.property.type
+
+
+
+
+
+
+ estate.property.type.search
+ estate.property.type
+
+
+
+
+
+
+
+
+ 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..a21251c85ea
--- /dev/null
+++ b/estate/views/estate_property_views.xml
@@ -0,0 +1,114 @@
+
+
+
+ estate.property.list
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.form
+ estate.property
+
+
+
+
+
+
+ estate.property.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Properties
+ estate.property
+ list,form
+
+
+