Skip to content

Commit 0d37d1f

Browse files
committed
[FIX] real_estate: code correction according to coding guidelines and add access rights
In this tutorial, learn about coding guidelines about format of documentation and naming convention of models and files, also get information about how to organize models and files in Directories, get knowledge about xml format. next understand about javascript naming convention and formatting and gained knowledge about CSS and SCSS. Understand about access rule about which rights should give to user or not like create, edit, delete and update.
1 parent dfbe6bf commit 0d37d1f

17 files changed

+66
-82
lines changed

estate-gasa/models/inherited_model.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

estate_account/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
'name': "Account",
33
'version': '1.0',
4-
'depends': ['base','estate-gasa', 'account'],
4+
'depends': ['base', 'estate_gasa', 'account'],
55
'author': "Author Name",
66
'category': 'Category',
77
"license": "LGPL-3",
File renamed without changes.

estate-gasa/__manifest__.py renamed to estate_gasa/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
'data': [
1111
'security/ir.model.access.csv',
1212
'views/estate_property_views.xml',
13+
'views/estate_property_offer_views.xml',
1314
'views/estate_property_type_views.xml',
1415
'views/estate_tag_views.xml',
15-
'views/estate_property_offer_views.xml',
16-
'views/estate_menus.xml',
1716
'views/inherited_model.xml',
17+
'views/estate_menus.xml',
1818
],
1919
}
File renamed without changes.

estate-gasa/models/estate.py renamed to estate_gasa/models/estate.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class Estate(models.Model):
1616
expected_price = fields.Float()
1717
bedrooms = fields.Integer(default=2)
1818
last_seen = fields.Datetime("Last Seen", default=fields.Date.today)
19-
date_availability = fields.Date(
20-
default=lambda self: date.today() + timedelta(days=90),
21-
copy=False
22-
)
19+
date_availability = fields.Date(default=lambda self: date.today() + timedelta(days=90), copy=False)
2320
active = fields.Boolean(default=True)
2421
living_area = fields.Integer(string="Living Area")
2522
facades = fields.Integer(string="Facades")
@@ -106,20 +103,18 @@ def action_mark_cancelled(self):
106103
record.state = 'cancelled'
107104

108105
_sql_constraints = [
109-
('check_expected_price_positive', 'CHECK(expected_price > 0)',
110-
'The expected price must be strictly positive.'),
111-
('check_selling_price_positive', 'CHECK(selling_price >= 0)',
112-
'The selling price must be positive.'),
106+
('check_expected_price_positive', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'),
107+
('check_selling_price_positive', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'),
113108
]
114109

115110
@api.constrains('selling_price', 'expected_price')
116111
def _check_selling_price_threshold(self):
117112
for record in self:
118113
if float_is_zero(record.selling_price, precision_digits=2):
119114
continue
120-
115+
121116
minimum_allowed = record.expected_price * 0.9
122-
117+
123118
if float_compare(record.selling_price, minimum_allowed, precision_digits=2) < 0:
124119
raise ValidationError(
125120
("The selling price cannot be lower than 90%% of the expected price.\n"

estate-gasa/models/estate_property_offer.py renamed to estate_gasa/models/estate_property_offer.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from odoo import api, models, fields
2-
from odoo.exceptions import UserError,ValidationError
3-
from datetime import date, timedelta
2+
from odoo.exceptions import UserError, ValidationError
3+
from datetime import timedelta
44

55

66
class EstatePropertyOffer(models.Model):
@@ -64,21 +64,22 @@ def action_refuse(self):
6464
'The offer price must be strictly positive.'),
6565
]
6666

67-
@api.model
68-
def create(self, vals):
69-
property_id = vals.get('property_id')
70-
amount = vals.get('price')
71-
72-
if property_id and amount:
73-
existing_offers = self.search([
74-
('property_id', '=', property_id),
75-
('price', '>=', amount)
76-
])
77-
if existing_offers:
78-
raise ValidationError("An offer with a higher or equal price already exists.")
79-
80-
property = self.env['estate.property'].browse(property_id)
81-
if property.state == 'new':
82-
property.state = 'offer_received'
83-
84-
return super().create(vals)
67+
@api.model_create_multi
68+
def create(self, vals_list):
69+
for vals in vals_list:
70+
property_id = vals.get('property_id')
71+
amount = vals.get('price')
72+
73+
if property_id and amount:
74+
existing_offers = self.search([
75+
('property_id', '=', property_id),
76+
('price', '>=', amount)
77+
])
78+
if existing_offers:
79+
raise ValidationError("An offer with a higher or equal price already exists.")
80+
81+
property = self.env['estate.property'].browse(property_id)
82+
if property.state == 'new':
83+
property.state = 'offer_received'
84+
85+
return super().create(vals_list)

estate-gasa/models/estate_property_type.py renamed to estate_gasa/models/estate_property_type.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class EstatePropertyType(models.Model):
1313
_sql_constraints = [
1414
('unique_property_type_name', 'UNIQUE(name)',
1515
'Property type name must be unique.'),
16-
]
16+
]
1717
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string="Offers")
1818
offer_count = fields.Integer(compute='_compute_offer_count')
1919

2020
@api.depends('offer_ids')
2121
def _compute_offer_count(self):
22-
for rec in self:
23-
rec.offer_count = len(rec.offer_ids)
22+
for rec in self:
23+
rec.offer_count = len(rec.offer_ids)

estate_gasa/models/inherited_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from odoo import fields, models
2+
3+
4+
class InheritedModel(models.Model):
5+
_inherit = "res.users"
6+
7+
property_ids = fields.One2many(
8+
"estate.property",
9+
"seller",
10+
string="Properties",
11+
domain=[('state', '!=', 'cancelled')]
12+
)

0 commit comments

Comments
 (0)