Skip to content

Commit bc7078f

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 eec8651 commit bc7078f

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
"views/inherit_res_users_view.xml",
1313
"security/ir.model.access.csv",
1414
],
15+
"license": "AGPL-3",
1516
}

estate/models/estate_property.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class EstateProperty(models.Model):
4444
("sold", "Sold"),
4545
("cancelled", "Cancelled"),
4646
],
47-
string="Status",
47+
string="State",
4848
default="new",
4949
copy=False,
5050
)
@@ -94,16 +94,16 @@ class EstateProperty(models.Model):
9494
@api.depends("garden_area", "living_area")
9595
def _compute_total_property_area(self):
9696
for area in self:
97-
self.total_area = self.garden_area + self.living_area
97+
area.total_area = area.garden_area + area.living_area
9898

9999
@api.depends("offer_ids.price")
100100
def _best_property_offer(self):
101101
for record in self:
102102
offers_list = record.mapped("offer_ids.price")
103103
if offers_list:
104-
self.best_price = max(offers_list)
104+
record.best_price = max(offers_list)
105105
return
106-
self.best_price = 0
106+
record.best_price = 0
107107

108108
# on change of garden status , update gardern area and its orientation
109109

@@ -123,7 +123,6 @@ def action_sell_property(self):
123123
property_sell_status_dict = {"new": True, "sold": True, "cancelled": False}
124124

125125
for record in self:
126-
print("the object on sell action", record.read())
127126
if property_sell_status_dict[record.status]:
128127
record.status = "sold"
129128
record.state = "sold"
@@ -154,7 +153,7 @@ def _check_selling_price(self):
154153
if data.selling_price <= 0:
155154
return
156155

157-
price_float_ratio = data.selling_price / self.expected_price
156+
price_float_ratio = data.selling_price / data.expected_price
158157
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2)
159158
if ratio_diffrence == -1:
160159
data.selling_price = 0
@@ -168,7 +167,7 @@ def _check_selling_price(self):
168167
@api.ondelete(at_uninstall=False)
169168
def _unlink_if_state_new_or_cancelled(self):
170169
for data in self:
171-
if not bool(self.state == "new" or self.state == "cancelled"):
170+
if not bool(data.state == "new" or data.state == "cancelled"):
172171
raise UserError(
173172
"Can't delete property which is not in new or cancelled state!"
174173
)

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)