Skip to content

Commit 4cd0123

Browse files
committed
[IMP] estate: interact with external modules and code cleanup
Implemented cross-module field access and method calls to demonstrate interaction with other modules., Cleaned codebase to fix linter errors and improve readability.
1 parent 65537da commit 4cd0123

File tree

9 files changed

+57
-15
lines changed

9 files changed

+57
-15
lines changed

estate/models/estate_property.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class EstateProperty(models.Model):
4646
("sold", "Sold"),
4747
("cancelled", "Cancelled"),
4848
],
49-
string="Status",
49+
string="State",
5050
default="new",
5151
copy=False,
5252
)
@@ -98,7 +98,7 @@ class EstateProperty(models.Model):
9898
@api.depends("garden_area", "living_area")
9999
def _compute_total_property_area(self):
100100
for area in self:
101-
self.total_area = self.garden_area + self.living_area
101+
area.total_area = area.garden_area + area.living_area
102102

103103
@api.depends("offer_ids.price")
104104
def _compute_best_price(self):
@@ -156,7 +156,7 @@ def _check_selling_price(self):
156156
if data.selling_price <= 0:
157157
return
158158

159-
price_float_ratio = data.selling_price / self.expected_price
159+
price_float_ratio = data.selling_price / data.expected_price
160160
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2)
161161
if ratio_diffrence == -1:
162162
data.selling_price = 0
@@ -169,7 +169,7 @@ def _check_selling_price(self):
169169
@api.ondelete(at_uninstall=False)
170170
def _unlink_if_state_new_or_cancelled(self):
171171
for data in self:
172-
if not bool(self.state == "new" or self.state == "cancelled"):
172+
if not bool(data.state == "new" or data.state == "cancelled"):
173173
raise UserError(
174174
"Can't delete property which is not in new or cancelled state!"
175175
)

estate/models/estate_property_offer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ def _compute_offer_deadline(self):
5353
offer.date_deadline = datetime.now() + relativedelta(
5454
days=(offer.validity or 0)
5555
)
56-
return
57-
58-
offer.date_deadline = offer.create_date + relativedelta(
59-
days=(offer.validity or 0)
60-
)
56+
else:
57+
offer.date_deadline = offer.create_date + relativedelta(
58+
days=(offer.validity or 0)
59+
)
6160

6261
# deadline date can also be changed and once this is saved validity will be updated
6362
def _deadline_update(self):
@@ -85,7 +84,7 @@ def action_offer_refuse(self):
8584
for record in self:
8685
if record.status == "accepted":
8786
record.property_id.selling_price = 0
88-
record.property_id.partner_id = ""
87+
record.property_id.partner_id = False
8988
record.status = "refused"
9089

9190
# now in case of offer creation CRUD

estate/models/estate_property_tag.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# the tag model will be here
2-
3-
41
from odoo import fields, models
52

63

estate/views/estate_property_tag_views.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
<field name="view_mode">list,form</field>
99
</record>
1010

11-
1211
</odoo>

estate/views/estate_property_views.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
>
112112
<field name="price"/>
113113
<field name="partner_id"/>
114-
<!-- <field name="status" invisible="True"/> -->
115114
<button name="action_offer_confirm" string="Accept" states="draft" type="object" icon="fa-check"
116115
invisible="status in ('accepted','refused')"
117116
/>

estate_account/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

estate_account/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
"installable": True,
66
"depends": ["base", "account", "estate"],
77
"data": [],
8+
"license": "AGPL-3",
89
}

estate_account/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import estate_property
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from odoo import models, Command
2+
3+
4+
class EstateProperty(models.Model):
5+
_inherit = "estate.property"
6+
7+
def action_sell_property(self):
8+
for record in self:
9+
partner_id = record.partner_id
10+
if partner_id:
11+
comission = record.selling_price * 0.06
12+
adminstration_fees = 100
13+
14+
# creating an account move for invoicing
15+
self.env["account.move"].create(
16+
{
17+
"partner_id": partner_id.id,
18+
"move_type": "out_invoice",
19+
"line_ids": [
20+
Command.create(
21+
{
22+
"name": record.name,
23+
"quantity": 1,
24+
"price_unit": record.selling_price,
25+
}
26+
),
27+
Command.create(
28+
{
29+
"name": "Commision",
30+
"quantity": 1,
31+
"price_unit": comission,
32+
}
33+
),
34+
Command.create(
35+
{
36+
"name": "Admin Fees",
37+
"quantity": 1,
38+
"price_unit": adminstration_fees,
39+
}
40+
),
41+
],
42+
}
43+
)
44+
45+
return super().action_sell_property()

0 commit comments

Comments
 (0)