Skip to content

[ADD] estate: added core functionalities & enhanced awesome dashboard #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions automated_estate_auction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controller
30 changes: 30 additions & 0 deletions automated_estate_auction/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Automated Real Estate Auction",
"version": "1.0",
"depends": ["base", "estate", "mail"],
"description": "Automate auction process to reduce delays",
"data": [
"security/ir.model.access.csv",
"data/estate_property_mail_template.xml",
"views/estate_property_offer_placed_views.xml",
"views/estate_property_make_offer_views.xml",
"views/estate_property_detail_website.xml",
"views/estate_property_list_website.xml",
"views/estate_property_views.xml",
"data/ir_cron.xml",
],
"assets": {
"web.assets_frontend": [
"automated_estate_auction/static/src/js/auction_countdown.js"
],
"web.assets_backend": [
"automated_estate_auction/static/src/component/auction_state_widget.js",
"automated_estate_auction/static/src/component/auction_state_widget.scss",
"automated_estate_auction/static/src/component/auction_state_widget.xml",
],
},
"sequence": 1,
"application": True,
"license": "OEEL-1",
"installable": True,
}
1 change: 1 addition & 0 deletions automated_estate_auction/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_website
94 changes: 94 additions & 0 deletions automated_estate_auction/controller/estate_website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from odoo import http
from odoo.addons.estate.controllers.estate_website import EstatePropertyWebsite


class EstatePropertyWebsiteAddon(EstatePropertyWebsite):
@http.route(
["/estate-properties", "/estate-properties/page/<int:page>"],
type="http",
auth="public",
website=True,
)
def estate_properties_list(self, page=1, property_sell_type="all", **kwargs):
response = super().estate_properties_list(page, **kwargs)
properties = response.qcontext.get("properties")

if property_sell_type and property_sell_type != "all":
properties = properties.filtered(
lambda p: p.property_sell_type == property_sell_type
)

total_pages = len(properties)
pager = http.request.website.pager(
url="/estate-properties",
total=total_pages,
page=page,
step=1,
scope=5,
url_args={
**kwargs,
"property_sell_type": property_sell_type,
},
)
response.qcontext.update(
{
"properties": properties,
"pager": pager,
"property_sell_type": property_sell_type,
}
)
return response

@http.route(
"/estate-properties/<int:property_id>", type="http", auth="public", website=True
)
def estate_property_detail(self, property_id, **kwargs):
super().estate_property_detail(property_id, **kwargs)
property_model = http.request.env["estate.property"]
property_obj = property_model.browse(property_id)
return http.request.render(
"automated_estate_auction.estate_property_detail_template_addon",
{
"property": property_obj,
},
)

@http.route(
"/estate-properties/<int:property_id>/create_offer",
type="http",
auth="public",
website=True,
)
def estate_property_create_offer(self, property_id, **kwargs):
property_model = http.request.env["estate.property"]
property_obj = property_model.browse(property_id)
return http.request.render(
"automated_estate_auction.estate_property_offer_page_view",
{
"property_name": property_obj.name,
"property_id": property_id,
},
)

@http.route(
"/estate-properties/thank-you",
type="http",
auth="public",
website=True,
methods=["POST"],
)
def estate_property_offer_placed(self, **kwargs):
offer_model = http.request.env["estate.property.offer"]
property_id = int(kwargs["property_id"])

response = offer_model.create(
{
"property_id": property_id,
"price": float(kwargs["offer_price"]),
"partner_id": http.request.env.user.partner_id.id,
}
)
if response:
return http.request.render(
"automated_estate_auction.estate_property_offer_placed_view",
)
25 changes: 25 additions & 0 deletions automated_estate_auction/data/estate_property_mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mail_template_accept_offer" model="mail.template">
<field name="name">Offer Email Acceptance Template</field>
<field name="model_id" ref="estate.model_estate_property_offer" />
<field name="email_from">{{ object.property_id.company_id.email }}</field>
<field name="email_to">{{ object.partner_id.email }}</field>
<field name="subject">Congralutions! Offer Update for Property {{ object.property_id.name }}</field>
<field name="body_html" type="html">
<t t-out="object.property_id.name" />
<t t-out="object.property_id.selling_price" />
</field>
</record>
<record id="mail_template_reject_offer" model="mail.template">
<field name="name">Offer Email Rejection Template</field>
<field name="model_id" ref="estate.model_estate_property_offer" />
<field name="email_from">{{ object.property_id.company_id.email }}</field>
<field name="email_to">{{ object.partner_id.email }}</field>
<field name="subject">Sorry for rejection of {{ object.property_id.name }} property</field>
<field name="body_html" type="html">
<t t-out="object.property_id.name" />
<t t-out="object.property_id.selling_price" />
</field>
</record>
</odoo>
13 changes: 13 additions & 0 deletions automated_estate_auction/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="ir_cron_check_auction_time" model="ir.cron">
<field name="name">Check remaining auction time</field>
<field name="model_id" ref="automated_estate_auction.model_estate_property" />
<field name="user_id" ref="base.user_root" />
<field name="state">code</field>
<field name="code">model.method_to_check_auction_remaining_time()</field>
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="active" eval="True" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions automated_estate_auction/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import estate_property
from . import estate_property_offer
58 changes: 58 additions & 0 deletions automated_estate_auction/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from odoo import fields, models
import datetime


class EstateProperty(models.Model):
_inherit = "estate.property"

property_sell_type = fields.Selection(
[("auction", "Auction"), ("regular", "Regular")]
)
auction_state = fields.Selection(
[
("template", "Template"),
("auction", "Auction"),
("sold", "Sold"),
],
default="template",
)
auction_end_time = fields.Datetime(string="End Time")
highest_offer = fields.Float(string="Highest Offer", readonly=True)
highest_bidder = fields.Many2one(
comodel_name="res.partner", string="Highest Bidder", readonly=True
)

def action_start_auction(self):
self.auction_state = "auction"

def method_to_check_auction_remaining_time(self):
properties = self.env["estate.property"].search(
[
("property_sell_type", "=", "auction"),
("auction_state", "=", "auction"),
("auction_end_time", "<=", datetime.datetime.now()),
]
)
for record in properties:
record.auction_state = "sold"
record.state = "sold"

highest_offer_obj = None
highest_price = 0.0

sorted_offers = record.offer_ids.sorted(key=lambda o: o.price, reverse=True)

if sorted_offers:
highest_offer_obj = sorted_offers[0]
highest_price = highest_offer_obj.price

record.highest_offer = highest_price
record.highest_bidder = highest_offer_obj.partner_id

highest_offer_obj.action_accept_offer()

for offer in sorted_offers[1:]:
offer.action_reject_offer()
else:
record.selling_price = 0.0
record.buyer_id = False
32 changes: 32 additions & 0 deletions automated_estate_auction/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from odoo import fields, models


class EstatePropertyOffer(models.Model):
_inherit = "estate.property.offer"

property_sell_type = fields.Selection(related="property_id.property_sell_type")

def action_accept_offer(self):
accepted_offer = self
super().action_accept_offer()

template_accepted = self.env.ref(
"automated_estate_auction.mail_template_accept_offer"
)

template_accepted.send_mail(accepted_offer.id, force_send=True)

template_rejected = self.env.ref(
"automated_estate_auction.mail_template_reject_offer"
)

other_offers = self.env["estate.property.offer"].search(
[
("property_id", "=", accepted_offer.property_id.id),
("id", "!=", accepted_offer.id),
]
)
for offer in other_offers:
template_rejected.send_mail(offer.id, force_send=True)

return True
2 changes: 2 additions & 0 deletions automated_estate_auction/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
Loading