Skip to content

Commit

Permalink
[IMP] estate: add sold/cancel and accept/refuse buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
romaincarlier4 committed Dec 18, 2024
1 parent 59731a6 commit f107512
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


class EstateProperty(models.Model):
Expand Down Expand Up @@ -73,3 +74,17 @@ def _onchange_garden(self):
else:
self.garden_area = 0
self.garden_orientation = ""

def action_property_sold(self):
self.ensure_one()
if self.state == "cancelled":
raise UserError("Cancelled properties cannot be sold.")
self.state = "sold"
return True

def action_property_cancelled(self):
self.ensure_one()
if self.state == "sold":
raise UserError("Sold properties cannot be cancelled.")
self.state = "cancelled"
return True
21 changes: 21 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from odoo import api, fields, models
from odoo.tools.date_utils import date
from odoo.exceptions import UserError


class EstatePropertyOffer(models.Model):
Expand Down Expand Up @@ -28,3 +29,23 @@ def _compute_date_deadline(self):
def _inverse_date_deadline(self):
for record in self:
record.validity = (record.date_deadline - record.create_date.date()).days

def action_accept_offer(self):
self.ensure_one()
other_records = self.search([("id", "!=", str(self.id))])
for rec in other_records:
if rec.status == "accepted":
raise UserError("Cannot have more than one accepted offer.")
self.status = "accepted"
self.property_id.buyer_id = self.partner_id
self.property_id.selling_price = self.price
return True

def action_refuse_offer(self):
self.ensure_one()
old_status = self.status
self.status = "refused"
if old_status == "accepted":
self.property_id.buyer_id = ""
self.property_id.selling_price = 0
return True
2 changes: 2 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<field name="partner_id" string="Partner"/>
<field name="validity" string="Validity (days)"/>
<field name="date_deadline" string="Deadline"/>
<button name="action_accept_offer" type="object" icon="fa-check"/>
<button name="action_refuse_offer" type="object" icon="fa-close"/>
<field name="status" string="Status"/>
</list>
</field>
Expand Down
5 changes: 5 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="Property">
<header>
<button name="action_property_sold" string="Sold" type="object" class="oe_highlight"/>
<button name="action_property_cancelled" string="Cancel" type="object"/>
</header>
<sheet>
<h1>
<field name="name" string="Title"/>
Expand All @@ -35,6 +39,7 @@
<br/>
<group>
<group>
<field name="state" string="Status"/>
<field name="property_type_id" string="Property Type"/>
<field name="postcode" string="Postcode"/>
<field name="date_availability" string="Available From"/>
Expand Down

0 comments on commit f107512

Please sign in to comment.