Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
'name': "Real Estate",

'summary': """
Server framework 101: A New Application"
""",

'description': """
Starting module for "Server framework 101: A New Application"
""",

'author': "Odoo",
'website': "https://www.odoo.com/",
'category': 'Tutorials',
'version': '0.1',
'application': True,
'installable': True,
'depends': ['base'],

'data': [
"data/estate.tag.csv",
"data/estate.property.csv",
"security/ir.model.access.csv"
],
'assets': {
},
'license': 'LGPL-3'
}
3 changes: 3 additions & 0 deletions estate/data/estate.property.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","expecting_price","area","property_type"
estate_tag_1,"Odoo Farm 2",300000,2000,"house"
estate_tag_2,"Odoo LLN",1000000,40000,"apartment"
3 changes: 3 additions & 0 deletions estate/data/estate.tag.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","color"
estate_property_1,"Leased",5
estate_property_2,"Empty",8
2 changes: 2 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import estate_tag
from . import estate_property
41 changes: 41 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class Property(models.Model):
_name = "estate.property"
_description = "Real Estate Property"
_order = "expecting_price, selling_price, sequence, id"

name = fields.Char("Name", required=True, translate=True)

property_type = fields.Selection(
[
("house", "House"),
("apartment", "Apartment"),
("land", "Land")
],
required=True
)

currency_id = fields.Many2one('res.currency', 'Currency', readonly=True)
expecting_price = fields.Monetary("Expecting Price", required=True)
selling_price = fields.Monetary("Selling Price", default=0)

bedroom_number = fields.Integer("Bedrooms", default=0)
area = fields.Integer("Living Area (sqm)", required=True)

sequence = fields.Integer(default=10)

tag_ids = fields.Many2many("estate.tag", string="Tags")

_check_bedroom_number = models.Constraint(
'CHECK(bedroom_number >= 0)',
'The number of bedrooms can\'t be negative.',
)

_check_area = models.Constraint(
'CHECK(area >= 0)',
'The area can\'t be negative.',
)
40 changes: 40 additions & 0 deletions estate/models/estate_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models

from random import randint


class EstateTagCategory(models.Model):
_name = "estate.tag.category"
_description = "Estate Tag Category"
_order = "sequence"

def _default_sequence(self):
"""
Here we use a _default method instead of ordering on 'sequence, id' to
prevent adding a new related stored field in the 'event.tag' model that
would hold the category id.
"""
return (self.search([], order="sequence desc", limit=1).sequence or 0) + 1

name = fields.Char("Name", required=True, translate=True)
sequence = fields.Integer('Sequence', default=_default_sequence)
tag_ids = fields.Many2many("estate.tag", "category_id", string="Tags")


class EstateTag(models.Model):
_name = "estate.tag"
_description = "Estate Tag"
_order = "category_sequence, sequence, id"

def _default_color(self):
return randint(1, 11)

name = fields.Char("Name", required=True, translate=True)
sequence = fields.Integer("Sequence", default=0)
category_id = fields.Many2one("estate.tag.category", string="Category", index=True, ondelete='cascade')
category_sequence = fields.Integer(related="category_id.sequence", string='Category Sequence', store=True)
color = fields.Integer(
string='Color Index', default=lambda self: self._default_color(),
help='Tag color. No color means no display in kanban or front-end, to distinguish internal tags from public categorization tags.')
4 changes: 4 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
access_estate_tag,access_estate_tag,model_estate_tag,base.group_user,1,1,1,1
access_estate_tag_category,access_estate_tag_category,model_estate_tag_category,base.group_user,1,1,1,1