Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions real_estate/estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions real_estate/estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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',
}
4 changes: 4 additions & 0 deletions real_estate/estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
70 changes: 70 additions & 0 deletions real_estate/estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions real_estate/estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions real_estate/estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions real_estate/estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions real_estate/estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions real_estate/estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<menuitem id="real_estate_menu" name="Real Estate">
<!-- ADVERSTISEMENTS -->
<menuitem id="advertisements_menu" name="Advertisements">
<menuitem id="estate_property_menu" action="estate_property_action"/>
</menuitem>
</menuitem>
<!-- CONFIGURATION -->
<menuitem id="settings_menu" name="Settings" sequence="100" parent="real_estate_menu"/>
<menuitem id="estate_property_type_menu" action="estate_property_type_action" parent="settings_menu"/>
<menuitem id="estate_property_tag_menu" action="estate_property_tag_action" sequence="100" parent="settings_menu"/>
</odoo>
34 changes: 34 additions & 0 deletions real_estate/estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<odoo>
<record id="estate_property_offer_view_tree" model="ir.ui.view">
<field name="name">estate.property.offer.tree</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<tree>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</tree>
</field>
</record>

<record id="estate_property_offer_view_form" model="ir.ui.view">
<field name="name">estate.property.offer.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</group>
</sheet>
</form>
</field>
</record>

</odoo>
7 changes: 7 additions & 0 deletions real_estate/estate/views/estate_property_tag.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo>
<!-- action - exercise chapter 8 -->
<record id="estate_property_tag_action" model="ir.actions.act_window">
<field name="name">Properties Tags</field>
<field name="res_model">estate.property.tag</field>
</record>
</odoo>
111 changes: 111 additions & 0 deletions real_estate/estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<odoo>
<!-- action - exercise chapter 5 -->
<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
</record>

<!-- vista lista - exercise chapter 6 y <field name="property_type_id"/> chapter 7-->
<record id="estate_property_view_tree" model="ir.ui.view">
<field name="name">estate.property.tree</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<tree>
<field name="name" string="Title"/>
<field name="property_type_id"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="postcode"/>
<field name="bedrooms"/>
<field name="living_area" string="Living Area (sqm)"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="date_availability" string="Available From"/>
<field name="state"/>
</tree>
</field>
</record>

<!-- vista form - exercise chapter 6 y campo <field name="property_type_id"/> chapter 7-->
<record id="estate_property_view_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form>
<field name="active" invisible="1"/>
<sheet>
<widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
<div class="oe_title">
<h1 class="mb32">
<field name="name" class="mb16"/>
</h1>
<field name="tag_ids" widget="many2many_tags"/>
</div>
<group>
<group>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="date_availability" string="Available From"/>
</group>
<group>
<field name="expected_price"/>
<field name="best_offer"/>
<field name="selling_price"/>
</group>
</group>
<notebook>
<page string="Description">
<group>
<field name="description"/>
<field name="bedrooms"/>
<field name="living_area" string="Living Area (sqm)"/>
<field name="facades"/>
<field name="garage"/>
<field name="garden"/>
<field name="garden_area" string="Garden Area (sqm)"/>
<field name="garden_orientation"/>
<field name="total_area"/>
<field name="state"/>
</group>
</page>
<page string="Offers">
<field name="offer_ids"/>
</page>
<page string="Other info">
<group>
<field name="buyer_id"/>
<field name="salesperson_id"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<!-- vista search - exercise chapter 6 y <field name="property_type_id"/> chapter 7-->
<record id="estate_property_view_search" model="ir.ui.view">
<field name="name">estate.property.view.search</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<search>
<field name="name" string="Title"/>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="expected_price"/>
<field name="bedrooms"/>
<field name="living_area" string="Living Area (sqm)"/>
<field name="facades"/>
<filter name="groupby_postcode" context="{'group_by': 'postcode'}"/>
<filter string="Available Properties" name="state" domain="['|', ('state', '=', 'new'),('state', '=', 'offer_received')]"/>
<!-- <filter string="Available Properties" name="state" domain="[('state', 'not in',['sold', 'cancelled'])]"/> -->
</search>
</field>
</record>

<!-- action - exercise chapter 7 -->
<record id="estate_property_type_action" model="ir.actions.act_window">
<field name="name">Properties Type</field>
<field name="res_model">estate.property.type</field>
</record>

</odoo>