Skip to content

Commit 7758b15

Browse files
author
youness benbraitit (yoben)
committed
[IMP] estate: added accept/refuse offer
added requirement of chapter 9
1 parent 1b7200e commit 7758b15

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

estate/models/estate_property.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date
22
from dateutil.relativedelta import relativedelta
3+
from odoo.exceptions import UserError, ValidationError
34
from odoo import api, fields, models
45

56

@@ -57,8 +58,7 @@ class EstateProperty(models.Model):
5758
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
5859
total_area = fields.Integer("Total Area (sqm)", compute="_compute_total_area")
5960
best_price = fields.Float(
60-
"Best Offer",
61-
compute="_compute_best_price", readonly=True
61+
"Best Offer", compute="_compute_best_price", readonly=True
6262
)
6363

6464
@api.depends('living_area', 'garden_area')
@@ -85,3 +85,13 @@ def _onchange_garden(self):
8585
else:
8686
self.garden_area = 0
8787
self.garden_orientation = False
88+
89+
def action_sold(self):
90+
if "cancelled" in self.mapped("state"):
91+
raise UserError("Canceled property cannot be sold !")
92+
return self.write({"state": "sold"})
93+
94+
def action_cancel(self):
95+
if "sold" in self.mapped("state"):
96+
raise UserError("Sold property cannot be canceled !")
97+
return self.write({"state": "cancelled"})

estate/models/estate_property_offer.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class EstatePropertyOffer(models.Model):
1515
)
1616
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
1717
property_id = fields.Many2one("estate.property", string="Property", required=True)
18-
validity = fields.Integer(
19-
"Validity (days)", default=7
20-
)
18+
validity = fields.Integer("Validity (days)", default=7)
2119
date_deadline = fields.Date(
2220
"Deadline", compute="_compute_date_deadline", store=True
2321
)
@@ -31,3 +29,20 @@ def _compute_date_deadline(self):
3129
)
3230
else:
3331
offer.date_deadline = False
32+
33+
def action_accept(self):
34+
for offer in self:
35+
offer.state = 'accepted'
36+
offer.property_id.selling_price = offer.price
37+
offer.property_id.buyer_id = offer.partner_id.id
38+
offer.property_id.state = 'offer_accepted'
39+
other_offers = offer.property_id.offer_ids.filtered(
40+
lambda o: o.id != offer.id and o.state != 'refused'
41+
)
42+
other_offers.state = 'refused'
43+
return True
44+
45+
def action_refuse(self):
46+
for offer in self:
47+
offer.state = 'refused'
48+
return True

estate/views/estate_property_offer_views.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</form>
1313
</field>
1414
</record>
15-
15+
<!-- Add the buttons ‘Accept’ and ‘Refuse’ to the estate.property.offer model. -->
1616
<record id="estate_property_offer_view_tree" model="ir.ui.view">
1717
<field name="name">estate.property.offer.tree</field>
1818
<field name="model">estate.property.offer</field>
@@ -23,6 +23,10 @@
2323
<field name="state"/>
2424
<field name="validity"/>
2525
<field name="date_deadline"/>
26+
<button name="action_accept" type="object" icon="fa-check" help="Accept"
27+
/>
28+
<button name="action_refuse" type="object" icon="fa-times" help="Refuse"
29+
/>
2630
</list>
2731
</field>
2832
</record>

estate/views/estate_view_form.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<form string="Property">
77
<header>
88
<field name="state" widget="statusbar"/>
9+
<button name="action_sold" string="SOLD" type="object"
10+
invisible="state in ['action_solde']"
11+
class="oe_highlight"/>
12+
<button name="action_cancel" string="CANCEL" type="object"
13+
invisible="state in ['action_cancel']"
14+
class="oe_highlight"/>
915
</header>
1016
<sheet>
1117
<div class="oe_title">

0 commit comments

Comments
 (0)