Skip to content

Commit c169bc2

Browse files
committed
[ADD] estate_account: generate invoice for property sold through inheritance
Added logic to create a customer invoice when a property is marked as Sold Invoice includes 6% commission and ₹100 administrative fees Display property in user which buy by them only can delete property if it is in new or cancelled state [FIX] estate_account: fixed check style and tutorial changes fixed check style and tutorial changes in estate_account and estate_property
1 parent 05f2d4c commit c169bc2

13 files changed

+124
-21
lines changed

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'name': 'Estate Accounting',
3+
'version': '1.0',
4+
'depends': ['real_estate', 'account'],
5+
'category': 'Real Estate',
6+
'license': 'LGPL-3',
7+
'installable': True,
8+
'application': False,
9+
}

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from odoo import models, Command
2+
from odoo.exceptions import UserError
3+
4+
5+
class EstateProperty(models.Model):
6+
_inherit = 'estate.property'
7+
8+
def action_sold(self):
9+
res = super().action_sold()
10+
11+
journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1)
12+
if not journal:
13+
raise UserError("No sale journal found. Please configure at least one sale journal.")
14+
15+
for record in self:
16+
if not record.buyer_id:
17+
raise UserError("Please set a Buyer before generating an invoice.")
18+
if not record.selling_price:
19+
raise UserError("Please set a Selling Price before generating an invoice.")
20+
21+
invoice_vals = {
22+
"partner_id": record.buyer_id.id,
23+
"move_type": "out_invoice",
24+
"journal_id": journal.id,
25+
"invoice_line_ids": [
26+
Command.create({
27+
"name": "6% Commission",
28+
"quantity": 1,
29+
"price_unit": 0.06 * record.selling_price,
30+
}),
31+
Command.create({
32+
"name": "Administrative Fees",
33+
"quantity": 1,
34+
"price_unit": 100.0,
35+
}),
36+
]
37+
}
38+
39+
self.env["account.move"].create(invoice_vals)
40+
return res

real_estate/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
'data': [
1414
'security/ir.model.access.csv',
1515
'view/estate_property_views.xml',
16-
16+
'view/estate_property_offer_views.xml',
1717
'view/estate_property_type_views.xml',
1818
'view/estate_property_tag_views.xml',
19-
'view/estate_property_offer_views.xml',
2019
'view/estate_menus.xml',
20+
'view/estate_res_users_view.xml'
2121
],
2222
}

real_estate/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from . import estate_property_type
33
from . import estate_property_tag
44
from . import estate_property_offer
5+
from . import estate_res_users

real_estate/models/estate_property.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class EstateProperty(models.Model):
1919
('check_expected_price_positive', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'),
2020
('check_selling_price_positive', 'CHECK(selling_price >= 0)', 'The selling price must be positive.')
2121
]
22-
2322
bedrooms = fields.Integer(default=2)
2423
living_area = fields.Float(string="Living Area")
2524
facades = fields.Integer(string="Facades")
@@ -59,7 +58,8 @@ class EstateProperty(models.Model):
5958
@api.constrains('selling_price', 'expected_price')
6059
def _check_selling_price(self):
6160
for record in self:
62-
if float_is_zero(record.selling_price, precision_digits=2):
61+
if (float_is_zero(record.selling_price, precision_digits=2)
62+
or record.state not in ['offer_accepted', 'sold']):
6363
continue
6464
min_acceptable_price = 0.9 * record.expected_price
6565
if float_compare(record.selling_price, min_acceptable_price, precision_digits=2) < 0:
@@ -98,3 +98,9 @@ def action_sold(self):
9898
raise UserError("Cancelled properties cannot be sold.")
9999
record.state = 'sold'
100100
return True
101+
102+
@api.ondelete(at_uninstall=False)
103+
def _check_deletion(self):
104+
for record in self:
105+
if record.state not in ['new', 'cancelled']:
106+
raise UserError("You can only delete a property if its state is 'New' or 'Cancelled'.")

real_estate/models/estate_property_offer.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EstatePropertyOffer(models.Model):
1313
('new', 'New'),
1414
('accepted', 'Accepted'),
1515
('refused', 'Refused')
16-
], string="State",default='new', required=True)
16+
], string="State", default='new', required=True)
1717
_sql_constraints = [
1818
('check_price', 'CHECK(price > 0)', 'The offer price must be strictly positive.'),
1919
]
@@ -27,17 +27,19 @@ class EstatePropertyOffer(models.Model):
2727
)
2828
validity = fields.Integer(default=7)
2929
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True)
30+
3031
@api.depends('create_date', 'validity')
3132
def _compute_date_deadline(self):
3233
for record in self:
3334
create_date = record.create_date or fields.Datetime.now()
3435
record.date_deadline = create_date.date() + timedelta(days=record.validity)
36+
3537
def _inverse_date_deadline(self):
3638
for record in self:
3739
create_date = record.create_date or fields.Datetime.now()
3840
delta = record.date_deadline - create_date.date()
3941
record.validity = delta.days
40-
42+
4143
def action_accept(self):
4244
for offer in self:
4345
if offer.property_id.buyer_id:
@@ -49,7 +51,20 @@ def action_accept(self):
4951
'state': 'offer_accepted'
5052
})
5153
return True
54+
5255
def action_refuse(self):
5356
for offer in self:
5457
offer.state = 'refused'
5558
return True
59+
60+
@api.model_create_multi
61+
def create(self, vals_list):
62+
for vals in vals_list:
63+
price = vals.get('price')
64+
property_obj = self.env['estate.property'].browse(vals.get('property_id'))
65+
existing_offers = property_obj.offer_ids.filtered(lambda o: o.price >= price)
66+
if existing_offers:
67+
raise ValidationError("You cannot create an offer with a lower or equal price than existing offers.")
68+
property_obj.state = 'offer_received'
69+
70+
return super().create(vals_list)

real_estate/models/estate_property_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class EstatePropertyType(models.Model):
2121
string="Offers Count",
2222
compute="_compute_offer_count"
2323
)
24+
2425
@api.depends("offer_ids")
2526
def _compute_offer_count(self):
2627
for record in self:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from odoo import models, fields
2+
3+
4+
class ResUsers(models.Model):
5+
_inherit = 'res.users'
6+
7+
property_ids = fields.One2many(
8+
'estate.property',
9+
'salesperson_id',
10+
string="Properties",
11+
domain=[('state', '!=', 'cancelled')]
12+
)

0 commit comments

Comments
 (0)