Skip to content
Open
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
4 changes: 4 additions & 0 deletions estate/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"xml.symbols.enabled": false,
"python.languageServer": "None"
}
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
'name': 'Estate',
'depends': ['base'],
'application': True,
'author': 'toher',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this is usually Odoo, since we work here.

'license': 'LGPL-3',

'data': [
'security/ir.model.access.csv',
'view/estate_property_offer_view.xml',
'view/estate_property_views.xml',
'view/estate_property_type_view.xml',
'view/estate_property_tag_view.xml',
'view/res_users.xml',
'view/estate_menus.xml',
],
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_type
from . import estate_tag
from . import estate_offer
from . import res_user
70 changes: 70 additions & 0 deletions estate/models/estate_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import timedelta

from odoo.exceptions import UserError

from odoo import api, fields, models


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Offer"
_order = "price desc"

price = fields.Float()
status = fields.Selection(
string="Status",
selection=[
("accepted", "Accepted"),
("refused", "Refused"),
("new", "New")
],
copy=False,
default="new"
)
Comment thread
Tom-Hermann marked this conversation as resolved.
partner_id = fields.Many2one("res.partner", string="Buyer", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(string="Validity", default=7)
date_deadline = fields.Date(string="Deadline", compute="_compute_dead_line", inverse="_inverse_validity")

_check_positif_price = models.Constraint(
'CHECK(price > 0)',
'The price must be positive'
)

property_type_id = fields.Many2one(related="property_id.property_type_id", store=True)

@api.model
def create(self, vals_list):
for vals in vals_list:
property = self.env["estate.property"].browse(vals["property_id"])
property.set_offer_received()
all_prices = property.proterty_offer_ids.mapped('price')
max_price = all_prices[0] if all_prices else 0
if max_price and max_price >= vals['price']:
raise UserError(self.env._("New offer can't be lower than an other offer"))
return super().create(vals_list)

@api.depends("validity")
def _compute_dead_line(self):
for offer in self:
offer.date_deadline = fields.Date.today() + timedelta(days=offer.validity)

def _inverse_validity(self):
for offer in self:
difference = (offer.create_date.date() - fields.Date.today())
offer.validity = difference.days

def action_accept_offer(self):
for offer in self:
if offer.status == "refused":
raise UserError(self.env._("Can't accept an refused offer"))
offer.status = "accepted"
offer.property_id.accept_offer()
return True

def action_refuse_offer(self):
for offer in self:
if offer.status == "accepted":
raise UserError(self.env._("Can't refuse an accepted offer"))
offer.status = "refused"
return True
133 changes: 133 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from datetime import timedelta

from odoo.tools import float_utils

from odoo import api, exceptions, fields, models


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Estate Property Module"
_order = "id desc"

_check_positif_expected_price = models.Constraint(
'CHECK(expected_price > 0)',
'The expected price must be strictly positive'
)
_check_positif_selling_price = models.Constraint(
'CHECK(selling_price >= 0)',
'The selling price must be positive'
)
Comment thread
Tom-Hermann marked this conversation as resolved.

# Base Fields
name = fields.Char(string="Title", required=True)
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
expected_price = fields.Float(string="Expected Price", required=True)
selling_price = fields.Float(string="Selling Price", copy=False, readonly=True)
best_price = fields.Integer(string="Best Price", compute="_compute_best_price")
expected_date = fields.Date(
string="Expected Date",
required=True,
copy=False,
default=lambda _: (fields.Date.today() + timedelta(days=90)),
)
bedroom = fields.Integer(string="Number of Bedroom", default=2)
living_area = fields.Integer(string="Living area (square metter)")
facades = fields.Integer(string="Number of facades")
garage = fields.Boolean(string="Have a garage?")
garden = fields.Boolean(string="Have a garden?")
garden_area = fields.Integer(string="Garden area (square metter)")
garden_orientation = fields.Selection(
string="Garden's orientation",
selection=[
("north", "North"),
("south", "South"),
("east", " East"),
("west", "West"),
],
)
total_area = fields.Integer(string="Total Area", compute="_compute_total_area")
state = fields.Selection(
Comment thread
Tom-Hermann marked this conversation as resolved.
string="Estate's state",
Comment thread
Tom-Hermann marked this conversation as resolved.
selection=[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", " Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
default="new",
copy=False
)
salesman_id = fields.Many2one(
"res.users",
string="Salesman",
default=lambda self: self.env.user
)
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
property_type_id = fields.Many2one("estate.property.type", string="Type")
property_tag_ids = fields.Many2many("estate.property.tag", string="Tag")
proterty_offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
active = fields.Boolean(default=True)

@api.depends('garden_area', 'living_area')
def _compute_total_area(self):
for record in self:
record.total_area = record.living_area + record.garden_area

@api.depends('proterty_offer_ids.price')
def _compute_best_price(self):
for record in self:
all_prices = record.proterty_offer_ids.mapped('price')
record.best_price = all_prices[0] if all_prices 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 = ''

@api.constrains("selling_price", "expected_price")
def _check_price_expectation(self):
for record in self:
if float_utils.float_is_zero(record.selling_price, 2):
return True
Comment thread
Tom-Hermann marked this conversation as resolved.
if float_utils.float_compare(record.selling_price, record.expected_price * 0.9, 2) == -1:
raise exceptions.ValidationError(self.env._("Selling price can't be smaller than 90% of the expected price"))
return True

@api.ondelete(at_uninstall=False)
def delete(self):
for record in self:
if record.state not in {"new", "cancelled"}:
raise exceptions.UserError(self.env._(f"Can't delete an advertise in {record.state} state"))

def action_sold_adv(self):
for advertisements in self:
if advertisements.state == "cancelled":
raise exceptions.UserError(self.env._("Can't sold an canceled advertise"))
advertisements.state = "sold"
return True

def action_cancel_adv(self):
for advertisements in self:
if advertisements.state == "sold":
raise exceptions.UserError(self.env._("Can't cancel an sold advertise"))
advertisements.state = "cancelled"
return True

def accept_offer(self):
Comment thread
Tom-Hermann marked this conversation as resolved.
for advertise in self:
accepted_offer = advertise.proterty_offer_ids.filtered(lambda r: r.status == 'accepted')
advertise.buyer_id = accepted_offer.partner_id
advertise.selling_price = accepted_offer.price
advertise.state = 'offer_accepted'
(advertise.proterty_offer_ids - accepted_offer).action_refuse_offer()

def set_offer_received(self):
for advertise in self:
advertise.state = "offer_received"
15 changes: 15 additions & 0 deletions estate/models/estate_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class PropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Estate Tag"
_order = "name"

_check_unique_name = models.Constraint(
'UNIQUE(name)',
"Another tag already exists with the same name!"
)

name = fields.Char(string="Tag")
color = fields.Integer()
23 changes: 23 additions & 0 deletions estate/models/estate_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from odoo import api, fields, models


class EstateType(models.Model):
_name = "estate.property.type"
_description = "Estate Type"
_order = "sequence"

_check_unique_name = models.Constraint(
'UNIQUE(name)',
"Another type already exists with the same name!"
)

name = fields.Char(string="Type", required=True)
property_ids = fields.One2many('estate.property', 'property_type_id')
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
offer_count = fields.Integer(compute="_compute_offer_count")
Comment on lines +14 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
7 changes: 7 additions & 0 deletions estate/models/res_user.py
Comment thread
Tom-Hermann marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class ResUsers(models.Model):
_inherit = "res.users"

property_ids = fields.One2many("estate.property", "salesman_id")
Comment thread
Tom-Hermann marked this conversation as resolved.
5 changes: 5 additions & 0 deletions 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
access_estate_model,access_estate_model,model_estate_property,base.group_user,1,1,1,1
access_estate_type_model,access_state_type_model,model_estate_property_type,base.group_user,1,1,1,1
access_estate_tag_model,access_state_tag_model,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_offer_model,access_state_offer_model,model_estate_property_offer,base.group_user,1,1,1,1
14 changes: 14 additions & 0 deletions estate/view/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<menuitem id="estate_menu_root" name="Estate Root">
<menuitem id="estate_advertisements_menu" name="Advertisements">
<menuitem id="estate_model_menu_action" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_settings_menu" name="Settings">
<menuitem id="estate_type_menu_action" action="estate_type_action"/>
<menuitem id="estate_tag_menu_action" action="estate_tag_action"/>
</menuitem>
</menuitem>

</odoo>
27 changes: 27 additions & 0 deletions estate/view/estate_property_offer_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_offers_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>

<record id="estate_property_offer_view_list" model="ir.ui.view">
<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list string="Property Offers"
decoration-danger="status == 'refused'"
decoration-success="status == 'accepted'"
create="false">
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field name="date_deadline" />
<button name="action_accept_offer" string="Confirm" type="object" icon="fa-check" invisible="status != 'new'"/>
<button name="action_refuse_offer" string="Cancel" type="object" icon="fa-times" invisible="status != 'new'"/>
</list>
</field>
</record>
</odoo>
19 changes: 19 additions & 0 deletions estate/view/estate_property_tag_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="estate_tag_action" model="ir.actions.act_window">
<field name="name">Estate Tag</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
</record>

<!-- List view -->
<record id="estate_property_tag_view_list" model="ir.ui.view">
<field name="name">estate.property.tag.list</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list string="Tags" editable="bottom">
<field name="name"/>
</list>
</field>
</record>
</odoo>
Loading