Skip to content

Commit db44e2c

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 1ca46c5 commit db44e2c

File tree

7 files changed

+54
-9
lines changed

7 files changed

+54
-9
lines changed

estate/models/estate_property.py

Lines changed: 6 additions & 7 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,16 +98,16 @@ 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 _best_property_offer(self):
105105
for record in self:
106106
offers_list = record.mapped("offer_ids.price")
107107
if offers_list:
108-
self.best_price = max(offers_list)
108+
record.best_price = max(offers_list)
109109
return
110-
self.best_price = 0
110+
record.best_price = 0
111111

112112
# on change of garden status , update gardern area and its orientation
113113

@@ -127,7 +127,6 @@ def action_sell_property(self):
127127
property_sell_status_dict = {"new": True, "sold": True, "cancelled": False}
128128

129129
for record in self:
130-
print("the object on sell action", record.read())
131130
if property_sell_status_dict[record.status]:
132131
record.status = "sold"
133132
record.state = "sold"
@@ -158,7 +157,7 @@ def _check_selling_price(self):
158157
if data.selling_price <= 0:
159158
return
160159

161-
price_float_ratio = data.selling_price / self.expected_price
160+
price_float_ratio = data.selling_price / data.expected_price
162161
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2)
163162
if ratio_diffrence == -1:
164163
data.selling_price = 0
@@ -172,7 +171,7 @@ def _check_selling_price(self):
172171
@api.ondelete(at_uninstall=False)
173172
def _unlink_if_state_new_or_cancelled(self):
174173
for data in self:
175-
if not bool(self.state == "new" or self.state == "cancelled"):
174+
if not bool(data.state == "new" or data.state == "cancelled"):
176175
raise UserError(
177176
"Can't delete property which is not in new or cancelled state!"
178177
)

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
@@ -106,7 +106,6 @@
106106
>
107107
<field name="price"/>
108108
<field name="partner_id"/>
109-
<!-- <field name="status" invisible="True"/> -->
110109
<button name="action_offer_confirm" string="Accept" states="draft" type="object" icon="fa-check"
111110
invisible="status in ('accepted','refused')"
112111
/>

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)