Skip to content

Commit

Permalink
[ADD] estate: Add The Sprinkles
Browse files Browse the repository at this point in the history
-Add the property type form view and showing all the property of this type
-Using of widgets creating statusbar to display state of the property
-Creating a record to view "estate.property" to Descending ID
-Creating a record to view "estate.property.offer" to Descending price
-Add the sequence
-Creating conditional display of buttons and fields
-Add tag colors
-Creating garden_area and orientation invisible
-Adding colour to accept and refuse button
-Creating offer is readonly when offer in sold,accept,cancel state
-Create the estate.property.offer and estate.property.tag list views editable.
-Create  the field date_availability on the estate.property list view optional
and hidden by default.
-Adding available filter by-default
-Add a filter_domain to the living area to include properties with an area equal
to or greater than the given value.
-Add state button for property type offer
  • Loading branch information
krku-odoo committed Aug 12, 2024
1 parent f0ae4ec commit 947622a
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 185 deletions.
3 changes: 2 additions & 1 deletion estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"license": "LGPL-3",
"category": "Real Estate",
"summary": "Manage properties",
"depends": ["base_setup"],
"depends": ["base_setup", "mail"],
"data": [
"security/ir.model.access.csv",
"views/real_estate_property.xml",
"views/estate_property_tree_views.xml",
"views/estate_property_offer_view.xml",
"views/property_type_views.xml",
"views/property_tag.xml",
"views/real_estate_menu.xml",
Expand Down
12 changes: 8 additions & 4 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
class MyModel(models.Model):
_name = "estate_property"
_description = "Real Estate"
_inherit = ["mail.thread", "mail.activity.mixin"]
_order = "id desc"

name = fields.Char(string="Title", required=True)
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
date_availability = fields.Date(string="Available From")
expected_price = fields.Float(string="Expected Price")
selling_price = fields.Float(string="Selling Price", default="0.00")
selling_price = fields.Float(string="Selling Price")
bedrooms = fields.Integer(string="Bedrooms")
living_area = fields.Integer(string="Living Area (sqm)")
facades = fields.Integer(string="Facades")
Expand All @@ -34,8 +36,9 @@ class MyModel(models.Model):
("offer received", "Offer Received"),
("offer accepted", "Offer Accepted"),
("sold", "Sold"),
("canceled", "Canceled"),
("cancelled", "Cancelled"),
],
tracking=True,
default="new",
)

Expand Down Expand Up @@ -100,9 +103,10 @@ def _compute_best_offer(self):
record.best_offer = 0.0

_sql_constraints = [
("property_name", "unique(name)", "The property name must be unique!"),
(
"selling_price",
"CHECK(selling_price >= 0)",
"check(selling_price >= 0)",
"A property selling price must be strictly positive.",
),
(
Expand All @@ -113,7 +117,7 @@ def _compute_best_offer(self):
]

@api.constrains("selling_price", "expected_price")
def _check_selling_price(self):
def _check_selling(self):
for record in self:
if record.selling_price > 0:
price_per = (record.expected_price * 90) / 100
Expand Down
18 changes: 15 additions & 3 deletions estate/models/property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Estate Property Offer"
_order = "price desc"

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

partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate_property", string="Property", required=True)
validity = fields.Integer(string="Validity (days)", default=7)
deadline_date = fields.Date(
string="Deadline", compute="_compute_deadline", inverse="_inverse_deadline"
)
property_type_id = fields.Many2one(
related="property_id.property_type_id", store=True
)

@api.depends("property_id.create_date", "validity")
def _compute_deadline(self):
Expand All @@ -32,10 +36,13 @@ def _compute_deadline(self):

def _inverse_deadline(self):
for record in self:
if record.property_id.create_date:
if record.property_id.create_date and record.deadline_date:
flag = fields.Date.from_string(record.deadline_date)
flag1 = fields.Date.from_string(record.property_id.create_date)
record.validity = (flag - flag1).days
if flag and flag1:
record.validity = (flag - flag1).days
else:
record.validity = 7
else:
record.validity = 7

Expand All @@ -52,3 +59,8 @@ def action_accepted(self):
_sql_constraints = [
("price", "CHECK(price >= 0)", "A price must be strictly positive.")
]
# @api.constrains('property_id.bedrooms')
# def _check_bedrooms(self):
# for record in self:
# if record.property_id.bedrooms < 0:
# raise ValidationError("You have to set bedrooms")
2 changes: 2 additions & 0 deletions estate/models/property_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
class PropertyTag(models.Model):
_name = "real.estate.property.tag"
_description = "Property Type"
_order = "name"

name = fields.Char(required=True)
color = fields.Integer()

_sql_constraints = [("name", "UNIQUE(name)", "A property tag name must be unique")]
15 changes: 14 additions & 1 deletion estate/models/property_type.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
from odoo import models, fields
from odoo import api, models, fields


class PropertyType(models.Model):
_name = "real.estate.property.type"
_description = "Property Type"
_order = "name"

name = fields.Char(string="Property Type", required=True)
description = fields.Text(string="Description")

property_ids = fields.One2many(
"estate_property", "property_type_id", string="Offers"
)
# nickname = fields.Char(related='property_ids.partner_id.name', store=True)
offer_ids = fields.One2many("estate.property.offer", "property_type_id", store=True)
sequence = fields.Integer("Sequence")
offer_count = fields.Integer(compute="_compute_offer_count")
_sql_constraints = [("name", "UNIQUE(name)", "A property type name must be unique")]

@api.depends("offer_ids")
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
50 changes: 50 additions & 0 deletions estate/views/estate_property_offer_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<odoo>
<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">
Offer
</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">
tree,form
</field>
<field name="domain">
[('property_type_id', '=', active_id)]
</field>
</record>
<record id="view_estate_property_offer_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 editable="bottom" decoration-bf="status=='accepted'" decoration-success="status=='accepted'" decoration-danger="status=='refused'">
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field name="deadline_date" />
<button name="action_accepted" type="object" icon="fa-check" title="done" invisible="status in ('accepted', 'refused')" />
<button name="action_refused" type="object" icon="fa-times" title="cancel" invisible="status in ('accepted', 'refused')" />
<field name="status" column_invisible="1" />
</tree>
</field>
</record>
<record id="view_estate_property_offer_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 string="Properties Form">
<sheet>
<group>
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field name="deadline_date" />
<field name="status" />
</group>
</sheet>
</form>
</field>
</record>
</odoo>
Loading

0 comments on commit 947622a

Please sign in to comment.