Skip to content

Commit 5775c43

Browse files
[ADD] real_estate: Add required fields for property details
- Introduce essential fields to the estate_property model for comprehensive property detail storage. - Set name and expected_price fields as always required to ensure data integrity. - Implement an API constraint to validate that expected_price is always greater than zero. Chapter 3
1 parent 8de6abe commit 5775c43

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

estate/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'description': """
88
A module so that customers can bid on real estates
99
""",
10+
'license': 'LGPL-3', # Default License
1011
'application': True,
1112
'installable': True,
1213
# data files always loaded at installation

estate/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

estate/models/estate_property.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from odoo import fields, models, api
2+
from odoo.exceptions import ValidationError
3+
4+
5+
class estate_property(models.Model):
6+
7+
_name = "estate.property"
8+
_description = "A real estate model with many fields"
9+
name = fields.Char(required=True)
10+
description = fields.Text()
11+
postcode = fields.Integer()
12+
date_availability = fields.Datetime()
13+
expected_price = fields.Float(required=True)
14+
selling_price = fields.Float()
15+
bedrooms = fields.Integer()
16+
living_area = fields.Integer()
17+
facades = fields.Integer()
18+
garage = fields.Boolean()
19+
garden = fields.Boolean()
20+
garden_area = fields.Integer()
21+
garden_orientation = fields.Selection(
22+
string='Type',
23+
selection=[('north', 'North'), ('south', 'South'),
24+
('east', 'East'), ('west', 'West')],
25+
help="Type is used to specify the garden orientation")
26+
27+
@api.constrains('expected_price')
28+
def _check_price(self):
29+
for rec in self:
30+
if rec.expected_price <= 0:
31+
raise ValidationError("Price must be positive")

0 commit comments

Comments
 (0)