Skip to content

Commit

Permalink
[IMP] estate: Use Actions To Cancel and set a property as sold
Browse files Browse the repository at this point in the history
  • Loading branch information
ataha1 committed Dec 19, 2024
1 parent 0973972 commit 75e607d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
17 changes: 17 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 @@ -71,3 +72,19 @@ def _onchange_garden(self):
else:
self.garden_area = 0
self.garden_orientation = False

def action_sold(self):
for record in self:
if record.state != "canceled":
record.state = "sold"
else:
raise UserError("Canceled properties can't be sold")
return True

def action_cancel(self):
for record in self:
if record.state != "sold":
record.state = "canceled"
else:
raise UserError("Sold properties can't be sold")
return True
12 changes: 10 additions & 2 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ def _compute_date_deadline(self):
record.date_deadline = fields.Datetime.add(
record.create_date, days=record.validity
)
print("Hi there")

def _inverse_date_deadline(self):
for record in self:
print((record.date_deadline - record.create_date.date()).days)
record.validity = (record.date_deadline - record.create_date.date()).days

def action_accept(self):
for record in self:
record.status = "accepted"
record.property_id.selling_price = record.price
record.property_id.buyer = record.partner_id

def action_refuse(self):
for record in self:
record.status = "refused"
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 @@ -10,6 +10,8 @@
<field name="partner_id" string="Partner"/>
<field name="validity" string="Validity"/>
<field name="date_deadline" string="Deadline"/>
<button name="action_accept" type="object" icon="fa-check"/>
<button name="action_refuse" type="object" icon="fa-times"/>
<field name="status" string="Status"/>
</list>
</field>
Expand Down
4 changes: 4 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="My new house">
<header>
<button name="action_sold" string="SOLD" type="object" />
<button name="action_cancel" string="CANCEL" type="object" />
</header>
<sheet>
<h1><field name="name" placeholder="e.g. My New House"/></h1>
<field name="tags_ids" widget="many2many_tags"/>
Expand Down

0 comments on commit 75e607d

Please sign in to comment.