Skip to content

Commit b6acb37

Browse files
committed
[IMP] estate: Implemented Interact with other modules
-Enhance property management with offer handling and invoice creation
1 parent 9d14654 commit b6acb37

File tree

8 files changed

+62
-12
lines changed

8 files changed

+62
-12
lines changed

Estate/models/estate_property.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ class EstateProperty(models.Model):
5050
best_price = fields.Float(compute="_compute_best_price", string="Best Offer", store=True)
5151
validity_days = fields.Integer(default=7)
5252
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True)
53-
53+
5454
_check_price = models.Constraint(
5555
'CHECK(expected_price > 0 AND selling_price >= 0)',
5656
'The Price of a property must be strictly positive.',
5757
)
58-
58+
5959
@api.depends("living_area", "garden_area")
6060
def _compute_total_area(self):
6161
for record in self:
6262
record.total_area = (record.living_area or 0) + (record.garden_area or 0)
6363

64-
@api.depends("offer_ids.price" , "state")
64+
@api.depends("offer_ids.price", "state")
6565
def _compute_best_price(self):
6666
for record in self:
6767
record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0.0
@@ -91,16 +91,22 @@ def _onchange_garden(self):
9191
else:
9292
record.garden_area = 0
9393
record.garden_orientation = False
94-
94+
95+
@api.model
96+
def create(self, vals):
97+
record = super().create(vals)
98+
if record.offer_ids:
99+
record.state = 'offer_received'
100+
return record
101+
95102
def write(self, vals):
103+
res = super().write(vals)
96104
if 'offer_ids' in vals:
97-
result = super().write(vals)
98105
for record in self:
99-
if record.offer_ids and record.state == 'new':
106+
if record.offer_ids and record.state != 'offer_received':
100107
record.state = 'offer_received'
101-
return result
102-
return super().write(vals)
103-
108+
return res
109+
104110
def action_set_sold(self):
105111
for record in self:
106112
record.state = "sold"

Estate/models/estate_property_offer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EstatePropertyOffer(models.Model):
2020
def action_accept_offer(self):
2121
for record in self:
2222
record.status = 'accepted'
23-
23+
2424
def action_refuse_offer(self):
2525
for record in self:
2626
record.status = 'refused'

Estate/models/estate_property_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class EstatePropertyType(models.Model):
66
_name = "estate.property.type"
77
_description = "Real Estate Property Type"
8-
_order="name desc "
8+
_order = "name desc"
99

1010
name = fields.Char(required=True)
1111
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
@@ -24,7 +24,7 @@ def _compute_offer_count(self):
2424
for property in property_type.property_ids:
2525
offer_count += len(property.offer_ids)
2626
property_type.offer_count = offer_count
27-
27+
2828
@api.constrains('name')
2929
def _check_type_name_unique(self):
3030
for record in self:

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
'name': 'Estate_account',
3+
'depends': ['base', 'Estate', 'account'],
4+
'application': True,
5+
'installable': True,
6+
'author': 'Estate_account',
7+
'category': 'Tutorials',
8+
'license': 'AGPL-3',
9+
'data': [
10+
'security/ir.model.access.csv',
11+
],
12+
}

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from odoo import models, Command
2+
3+
4+
class EstateProperty(models.Model):
5+
_inherit = "estate.property"
6+
7+
def action_set_sold(self):
8+
for property in self:
9+
invoice_vals = {
10+
"partner_id": property.buyer_id.id,
11+
"move_type": "out_invoice",
12+
"invoice_line_ids": [
13+
Command.create({
14+
"name": "Commission (6%)",
15+
"quantity": 1,
16+
"price_unit": property.selling_price * 0.06,
17+
}),
18+
19+
Command.create({
20+
"name": "Administrative Fee",
21+
"quantity": 1,
22+
"price_unit": 100,
23+
}),
24+
],
25+
}
26+
self.env["account.move"].create(invoice_vals)
27+
28+
return super().action_set_sold()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
2+
access_estate_property,Estate Property,model_estate_property,base.group_user,1,1,1,1

0 commit comments

Comments
 (0)