diff --git a/real_estate/estate/__init__.py b/real_estate/estate/__init__.py
new file mode 100644
index 000000000..9a7e03ede
--- /dev/null
+++ b/real_estate/estate/__init__.py
@@ -0,0 +1 @@
+from . import models
\ No newline at end of file
diff --git a/real_estate/estate/__manifest__.py b/real_estate/estate/__manifest__.py
new file mode 100644
index 000000000..c765eb7b8
--- /dev/null
+++ b/real_estate/estate/__manifest__.py
@@ -0,0 +1,15 @@
+{
+ 'name': 'Real Estate',
+ 'depends': ['base'],
+ 'application': True,
+ 'data':[
+ 'security/ir.model.access.csv',
+
+ 'views/estate_property_views.xml',
+ 'views/estate_property_tag.xml',
+ 'views/estate_property_offer_views.xml',
+
+ 'views/estate_menus.xml',
+ ],
+ 'license': 'LGPL-3',
+}
\ No newline at end of file
diff --git a/real_estate/estate/models/__init__.py b/real_estate/estate/models/__init__.py
new file mode 100644
index 000000000..09b2099fe
--- /dev/null
+++ b/real_estate/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
\ No newline at end of file
diff --git a/real_estate/estate/models/estate_property.py b/real_estate/estate/models/estate_property.py
new file mode 100644
index 000000000..3628aa33a
--- /dev/null
+++ b/real_estate/estate/models/estate_property.py
@@ -0,0 +1,70 @@
+from odoo import fields, models, api
+from datetime import datetime
+from dateutil.relativedelta import relativedelta
+
+class EstateProperty(models.Model):
+ _name = "estate.property"
+ _description = "Real Estate Properties"
+
+ name = fields.Char('Name',required=True)
+ description = fields.Text('Description')
+ property_type_id= fields.Many2one("estate.property.type")
+ postcode = fields.Char()
+ date_availability = fields.Date(copy=False, default=lambda self: (datetime.now() + relativedelta(months=3)))
+ expected_price = fields.Float(required=True)
+ selling_price = fields.Float(readonly=True, copy=False)
+ bedrooms = fields.Integer(default=2)
+ living_area = fields.Integer()
+ facades = fields.Integer()
+ garage = fields.Boolean('Garage')
+ garden = fields.Boolean()
+ garden_area = fields.Integer(string='Jardin Area')
+ garden_orientation = fields.Selection(
+ string='Garden Orientation',
+ selection=[('north','North'), ('south','South'), ('east','East'),('west','West')])
+ active = fields.Boolean('Active', default=True)
+ state = fields.Selection(
+ string='Estado',
+ selection=[('new','New'),('offer_received','Offer Received'),('offer_accepted','Offer Accepted'),('sold','Sold'),('cancelled','Cancelled')],
+ required=True,
+ copy=False,
+ default="new"
+ )
+ buyer_id = fields.Many2one("res.partner", copy=False) #en odoo se usaria mas partner_id
+ salesperson_id = fields.Many2one("res.users", default=lambda self: self.env.user) #en odoo se usaria mas user_id
+ # un campo many2one por convencion se indica con sufijo _id
+ tag_ids = fields.Many2many('estate.property.tag')
+ # many2many fields have the _ids suffix
+ offer_ids = fields.One2many("estate.property.offer", "property_id")
+
+ # Exercise total area chapter 8
+ total_area = fields.Float(compute='_compute_total_area')
+
+ @api.depends('living_area', 'garden_area')
+ def _compute_total_area(self):
+ for record in self:
+ record.total_area = record.living_area + record.garden_area
+
+ # Exercise best offer chapter 8
+ best_offer = fields.Float(compute='_compute_best_offer')
+
+ @api.depends('offer_ids.price')
+ def _compute_best_offer(self):
+ for record in self:
+ record.best_offer = max(record.offer_ids.mapped('price') or [0])
+
+
+ # Error: max(record.offer_ids.mapped('price')) devuelve una lista, si es vacia da el siguiente error:
+ # File "/home/odoo/custom/repositories/real_estate/estate/models/estate_property.py", line 55, in _compute_best_offer
+ # record.best_offer = max(record.offer_ids.mapped('price'))
+ # ValueError: max() arg is an empty sequence
+
+ # Exercise garden area and orientation chapter 8
+ @api.onchange('garden')
+ def _onchange_garden(self):
+ if self.garden:
+ self.garden_area = 10
+ self.garden_orientation = 'north'
+ else:
+ self.garden_area = False
+ self.garden_orientation = False
\ No newline at end of file
diff --git a/real_estate/estate/models/estate_property_offer.py b/real_estate/estate/models/estate_property_offer.py
new file mode 100644
index 000000000..69a03f70c
--- /dev/null
+++ b/real_estate/estate/models/estate_property_offer.py
@@ -0,0 +1,44 @@
+from odoo import fields, models, api
+from dateutil.relativedelta import relativedelta
+
+
+class EstatePropertyOffer(models.Model):
+ _name = "estate.property.offer"
+ _description = "Property Offers"
+
+ price = fields.Float()
+ status = fields.Selection(
+ string="status",
+ copy=False,
+ selection=[('accepted','Accepted'),('refused','Refused')],
+ )
+ partner_id = fields.Many2one('res.partner',required=True)
+ property_id = fields.Many2one('estate.property',required=True)
+
+ #exercise validity date for offers chapter 8
+ validity = fields.Integer(default=7)
+ date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline')
+
+# Where date_deadline is a computed field which is defined as the sum of two fields from the offer: the create_date and the validity.
+ @api.depends('create_date','validity')
+ def _compute_date_deadline(self):
+ for record in self:
+ if record.create_date:
+ record.date_deadline = record.create_date + relativedelta(days=record.validity)
+ else:
+ False
+#otra opc:
+ # 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:
+ # False
+
+# #Define an appropriate inverse function so that the user can set either the date or the 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:
+ False
\ No newline at end of file
diff --git a/real_estate/estate/models/estate_property_tag.py b/real_estate/estate/models/estate_property_tag.py
new file mode 100644
index 000000000..c95fe2604
--- /dev/null
+++ b/real_estate/estate/models/estate_property_tag.py
@@ -0,0 +1,7 @@
+from odoo import fields, models
+
+class EstatePropertyTag(models.Model):
+ _name = "estate.property.tag"
+ _description = "Estate Property Tags"
+
+ name = fields.Char(required=True)
\ No newline at end of file
diff --git a/real_estate/estate/models/estate_property_type.py b/real_estate/estate/models/estate_property_type.py
new file mode 100644
index 000000000..b6306e34a
--- /dev/null
+++ b/real_estate/estate/models/estate_property_type.py
@@ -0,0 +1,7 @@
+from odoo import fields, models
+
+class EstatePropertyType(models.Model):
+ _name = "estate.property.type"
+ _description = "Estate Property Types"
+
+ name = fields.Char(required=True)
\ No newline at end of file
diff --git a/real_estate/estate/security/ir.model.access.csv b/real_estate/estate/security/ir.model.access.csv
new file mode 100644
index 000000000..3fc6d5561
--- /dev/null
+++ b/real_estate/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
+estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
+estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1
+estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
+estate.access_estate_property_offer,Estate Properties Offers,estate.model_estate_property_offer,base.group_user,1,1,1,1
\ No newline at end of file
diff --git a/real_estate/estate/views/estate_menus.xml b/real_estate/estate/views/estate_menus.xml
new file mode 100644
index 000000000..83b02c955
--- /dev/null
+++ b/real_estate/estate/views/estate_menus.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/real_estate/estate/views/estate_property_offer_views.xml b/real_estate/estate/views/estate_property_offer_views.xml
new file mode 100644
index 000000000..929679529
--- /dev/null
+++ b/real_estate/estate/views/estate_property_offer_views.xml
@@ -0,0 +1,34 @@
+
+
+ estate.property.offer.tree
+ estate.property.offer
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.offer.form
+ estate.property.offer
+
+
+
+
+
+
\ No newline at end of file
diff --git a/real_estate/estate/views/estate_property_tag.xml b/real_estate/estate/views/estate_property_tag.xml
new file mode 100644
index 000000000..9a9bac368
--- /dev/null
+++ b/real_estate/estate/views/estate_property_tag.xml
@@ -0,0 +1,7 @@
+
+
+
+ Properties Tags
+ estate.property.tag
+
+
\ No newline at end of file
diff --git a/real_estate/estate/views/estate_property_views.xml b/real_estate/estate/views/estate_property_views.xml
new file mode 100644
index 000000000..545f41b0a
--- /dev/null
+++ b/real_estate/estate/views/estate_property_views.xml
@@ -0,0 +1,111 @@
+
+
+
+ Properties
+ estate.property
+
+
+
+
+ estate.property.tree
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ estate.property.form
+ estate.property
+
+
+
+
+
+
+
+ estate.property.view.search
+ estate.property
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Properties Type
+ estate.property.type
+
+
+
\ No newline at end of file