Skip to content

Commit

Permalink
You'll have to re-write this commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
aboo-odoo committed Oct 25, 2024
1 parent d6d9aeb commit c592c35
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 108 deletions.
1 change: 1 addition & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

'views/estate_property_views.xml',
'views/estate_settings_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_menu_views.xml'
],
'installable': True,
Expand Down
4 changes: 2 additions & 2 deletions estate/demo/estate_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<field name="garden">True</field>
<field name="garden_area">420</field>
<field name="garden_orientation">south</field>
<field name="property_type" ref="estate_property_type_2" />
<field name="type_id" ref="estate_property_type_2" />
<field name="salesperson" ref="base.user_demo"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_1'), ref('estate_property_tag_2')])]"/>
<field name="offer_ids" eval="[(6, 0, [ref('estate_property_offer_1')])]"/>
Expand All @@ -78,7 +78,7 @@
<field name="garage">False</field>
<field name="garden">False</field>
<field name="garden_area">0</field>
<field name="property_type" ref="estate_property_type_1"/>
<field name="type_id" ref="estate_property_type_1"/>
<field name="salesperson" ref="base.user_admin"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_3')])]"/>
<field name="offer_ids" eval="[(6, 0, [ref('estate_property_offer_2'), ref('estate_property_offer_4'), ref('estate_property_offer_3')])]"/>
Expand Down
3 changes: 1 addition & 2 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import estate_property_infos
from . import estate_property
from . import estate_property_infos, estate_property, estate_property_offer
30 changes: 24 additions & 6 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Estate_Property(models.Model):
_name = "estate_property"
_description = "Estate properties"
_order = "id desc"
active = False

name = fields.Char(required=True, string="Title")
Expand Down Expand Up @@ -56,10 +57,12 @@ class Estate_Property(models.Model):

garden_orientation = fields.Selection(
[("north", "North"), ("south", "South"), ("west", "West"), ("east", "East")],
string="Garden Orientation"
string="Garden Orientation",
)

property_type = fields.Many2one("estate_property_type", string="Property Type")
type_id = fields.Many2one(
"estate_property_type", required=True, string="Property Type"
)

buyer = fields.Many2one("res.partner", copy=False, string="Buyer")

Expand All @@ -73,10 +76,21 @@ class Estate_Property(models.Model):

total_area = fields.Integer(compute="_compute_total_area", string="Total Area")

best_offer = fields.Float(compute="_compute_best_offer", default=0.0, string="Best Offer")
best_offer = fields.Float(
compute="_compute_best_offer", default=0.0, string="Best Offer"
)

_sql_constraints = [
("check_positive_expected_price", "CHECK(expected_price >= 0.0)", "Expected Price should be a positive number."), ("check_positive_selling_price", "CHECK(selling_price >= 0.0)", "Selling Price should be a positive number.")
(
"check_positive_expected_price",
"CHECK(expected_price >= 0.0)",
"Expected Price should be a positive number.",
),
(
"check_positive_selling_price",
"CHECK(selling_price >= 0.0)",
"Selling Price should be a positive number.",
),
]

@api.depends("garden_area", "living_area")
Expand All @@ -101,8 +115,12 @@ def _onchange_garden(self):
@api.constrains("selling_price", "expected_price")
def _check_expected_vs_selling_price(self):
for record in self:
if (record.selling_price > 0.0) and (record.selling_price < 0.9 * record.expected_price):
raise exceptions.ValidationError(r"Cannot sell for less than 90% of expected price.")
if (record.selling_price > 0.0) and (
record.selling_price < 0.9 * record.expected_price
):
raise exceptions.ValidationError(
r"Cannot sell for less than 90% of expected price."
)

def action_sold(self):
for record in self:
Expand Down
85 changes: 9 additions & 76 deletions estate/models/estate_property_infos.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from odoo import api, exceptions, fields, models
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo import fields, models


class Estate_Property_Type(models.Model):
_name = "estate_property_type"
_description = "Estate property Types"
active = False
_order = "name"

name = fields.Char(
required=True,
string="Type"
)

property_ids = fields.One2many(
"estate_property",
"type_id",
string="Estate Properties"
)

_sql_constraints = [
("check_unique_type", "UNIQUE(name)", "Property types must be unique.")
]
Expand All @@ -21,6 +25,7 @@ class Estate_Property_Type(models.Model):
class Estate_Property_Tag(models.Model):
_name = "estate_property_tag"
_description = "Estate property Tags"
_order = "name"

name = fields.Char(
required=True,
Expand All @@ -35,75 +40,3 @@ class Estate_Property_Tag(models.Model):
_sql_constraints = [
("check_unique_tag", "UNIQUE(name)", "Property tags must be unique.")
]


class Estate_Property_Offer(models.Model):
_name = "estate_property_offer"
_description = "Estate Property Offers"

price = fields.Float(
string="Price"
)

status = fields.Selection(
[("accepted", "Accepted"), ("refused", "Refused")],
readonly=True,
copy=False,
string="Status"
)

partner_id = fields.Many2one(
'res.partner',
required=True,
string="Partner"
)

property_id = fields.Many2one(
'estate_property',
string="Property"
)

validity = fields.Integer(
default=7,
string="Validity (days)"
)

deadline = fields.Date(
compute="_compute_deadline",
copy=False,
string="Deadline"
)

_sql_constraints = [
("check_positive_price", "CHECK(price > 0.0)", "Offer Price should be a positive number (higher than 0).")
]

@api.depends("validity")
def _compute_deadline(self):
for record in self:
record.deadline = date.today() + relativedelta(days=+record.validity)

def _inverse_deadline(self):
for record in self:
record.validity = relativedelta(date.today(), record.deadline)

def action_accept(self):
for record in self:
if not any(offer_status == "accepted" for offer_status in record.property_id.offer_ids.mapped("status")):
# Set values in the Property itself
record.property_id.selling_price = record.price
record.property_id.buyer = record.partner_id

record.status = "accepted"
else:
raise exceptions.UserError("An offer has already been accepted.")
return True

def action_refuse(self):
for record in self:
if record.status == "accepted":
# Set values in the Property itself
record.property_id.selling_price = 0.0
record.property_id.buyer = None
record.status = "refused"
return True
76 changes: 76 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from odoo import api, exceptions, fields, models
from datetime import date
from dateutil.relativedelta import relativedelta


class Estate_Property_Offer(models.Model):
_name = "estate_property_offer"
_description = "Estate Property Offers"
_order = "price desc"

price = fields.Float(
string="Price"
)

status = fields.Selection(
[("accepted", "Accepted"), ("refused", "Refused")],
readonly=True,
copy=False,
string="Status"
)

partner_id = fields.Many2one(
'res.partner',
required=True,
string="Partner"
)

property_id = fields.Many2one(
'estate_property',
string="Property"
)

validity = fields.Integer(
default=7,
string="Validity (days)"
)

deadline = fields.Date(
compute="_compute_deadline",
copy=False,
string="Deadline"
)

_sql_constraints = [
("check_positive_price", "CHECK(price > 0.0)", "Offer Price should be a positive number (higher than 0).")
]

@api.depends("validity")
def _compute_deadline(self):
for record in self:
record.deadline = date.today() + relativedelta(days=+record.validity)

def _inverse_deadline(self):
for record in self:
record.validity = relativedelta(date.today(), record.deadline)

def action_accept(self):
for record in self:
if not any(offer_status == "accepted" for offer_status in record.property_id.offer_ids.mapped("status")):
# Set values in the Property itself
record.property_id.selling_price = record.price
record.property_id.buyer = record.partner_id

record.status = "accepted"
else:
raise exceptions.UserError("An offer has already been accepted.")
return True

def action_refuse(self):
for record in self:
if record.status == "accepted":
# Set values in the Property itself
record.property_id.selling_price = 0.0
record.property_id.buyer = None
record.status = "refused"
return True
Binary file added estate/static/description/icon.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion estate/views/estate_menu_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- SUBHEADERS: Settings -->
<menuitem
id="menu_estate_property_types"
name="Property types"
name="Property Types"
sequence="1"
parent="estate.menu_estate_settings"
action="estate_property_types_view"
Expand Down
27 changes: 27 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<!-- List view -->
<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 editable="top">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
<button name="action_accept" type="object" string="Accept" icon="fa-check"/>
<button name="action_refuse" type="object" string="Refuse" icon="fa-times"/>
<field name="status"/>
</list>
</field>
</record>

<record id="estate_property_offer_view" model="ir.actions.act_window">
<field name="name">Offers</field>
<field name="res_model">estate_property_offer</field>
<field name="view_mode">list</field>
</record>

</odoo>
27 changes: 11 additions & 16 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@

<field name="arch" type="xml">
<form string="Estate Property">
<header>
<button name="action_sold" type="object" string="Sold" />
<button name="action_cancel" type="object" string="Cancel" />
<field name="status" widget="statusbar"
statusbar_visible="new,offer_received,offer_accepted,sold"
options="{'clickable': 1}" type="selection" />
</header>

<sheet>
<div class="oe_title">
<button name="action_sold" type="object" string="Sold"/>
<button name="action_cancel" type="object" string="Cancel"/>
<h1>
<field name="name" string="Property" placeholder="Property Name"
required="True" />
</h1>
<field name="tag_ids" widget="many2many_tags"/>
<field name="tag_ids" widget="many2many_tags" />
</div>

<separator />

<group>
<group>
<field name="property_type" />
<field name="type_id" />
<field name="postcode" />
<field name="date_availability" />
</group>
Expand All @@ -70,22 +76,11 @@
<field name="garden_area" />
<field name="garden_orientation" />
<field name="total_area" />
<field name="status" />
</group>
</page>

<page string="Offers">
<field name="offer_ids">
<list default_order="status,price desc" editable="top">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
<button name="action_accept" type="object" string="Accept" icon="fa-check"/>
<button name="action_refuse" type="object" string="Refuse" icon="fa-times"/>
<field name="status"/>
</list>
</field>
<field name="offer_ids" />
</page>

<page string="Other Info">
Expand Down
Loading

0 comments on commit c592c35

Please sign in to comment.