Skip to content

Commit cda8d01

Browse files
committed
[IMP] estate: chapter 9
1 parent af44200 commit cda8d01

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

estate/models/estate_property.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import api, fields, models
2+
from odoo.exceptions import UserError
23

34

45
class EstateProperty(models.Model):
@@ -37,15 +38,25 @@ class EstateProperty(models.Model):
3738
def _compute_total(self):
3839
for record in self:
3940
record.total_area = record.living_area + record.garden_area
40-
41+
4142
@api.depends("offer_ids")
4243
def _compute_highest_price(self):
4344
for record in self:
44-
record.best_price=max(record.offer_ids.mapped("price")) if record.offer_ids else 0
45-
45+
record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0
46+
4647
@api.onchange("garden")
4748
def _onchange_garden(self):
4849
self.garden_area = 10 if self.garden else 0
4950
self.garden_orientation = "North" if self.garden else None
50-
5151

52+
def action_mark_as_sold(self):
53+
if self.state == "Cancelled":
54+
raise UserError("Cette vente a été annulée")
55+
self.state = "Sold"
56+
return True
57+
58+
def action_mark_as_cancelled(self):
59+
if self.state == "Sold":
60+
raise UserError("Cette maison a déjà été vendue")
61+
self.state = "Cancelled"
62+
return True

estate/models/estate_property_offer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,15 @@ def _compute_deadline(self):
1818
record.date_deadline = fields.Date.add(record.create_date or fields.Date.today(), days=record.validity)
1919

2020
def _inverse_deadline(self):
21-
for record in self :
21+
for record in self:
2222
record.validity = (record.date_deadline - fields.Date.to_date(record.create_date)).days
23+
24+
def action_accept(self):
25+
self.status = "Accepted"
26+
self.property_id.buyer = self.partner_id
27+
self.property_id.selling_price = self.price
28+
return True
29+
30+
def action_refuse(self):
31+
self.status = "Refused"
32+
return True

estate/views/estate_property_views.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<field name="model">estate.property</field>
2929
<field name="arch" type="xml">
3030
<form string="Test">
31+
<header>
32+
<button name="action_mark_as_sold" type="object" string="Sold"/>
33+
<button name="action_mark_as_cancelled" type="object" string="Cancelled"/>
34+
</header>
3135
<sheet>
3236
<h1>
3337
<field name="name"/>
@@ -66,6 +70,8 @@
6670
<list string="Channel" >
6771
<field name="price"/>
6872
<field name="partner_id"/>
73+
<button name="action_accept" type="object" icon="fa-check"/>
74+
<button name="action_refuse" type="object" icon="oi-close"/>
6975
<field name="status"/>
7076
</list>
7177
</field>

0 commit comments

Comments
 (0)