Skip to content
Draft
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
467 changes: 467 additions & 0 deletions .eslintignore

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2022
},
"env": {
"browser": true,
"es2022": true,
"qunit": true
},
"rules": {
"prettier/prettier": ["error", {
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"printWidth": 100,
"endOfLine": "auto"
}],
"no-undef": "error",
"no-restricted-globals": ["error", "event", "self"],
"no-const-assign": ["error"],
"no-debugger": ["error"],
"no-dupe-class-members": ["error"],
"no-dupe-keys": ["error"],
"no-dupe-args": ["error"],
"no-dupe-else-if": ["error"],
"no-unsafe-negation": ["error"],
"no-duplicate-imports": ["error"],
"valid-typeof": ["error"],
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false, "caughtErrors": "all" }],
"curly": ["error", "all"],
"no-restricted-syntax": ["error", "PrivateIdentifier"],
"prefer-const": ["error", {
"destructuring": "all",
"ignoreReadBeforeAssign": true
}],
"arrow-body-style": ["error", "as-needed"]
},
"globals": {
"odoo": "readonly",
"$": "readonly",
"jQuery": "readonly",
"Chart": "readonly",
"fuzzy": "readonly",
"StackTrace": "readonly",
"QUnit": "readonly",
"luxon": "readonly",
"py": "readonly",
"FullCalendar": "readonly",
"globalThis": "readonly",
"ScrollSpy": "readonly",
"module": "readonly",
"chai": "readonly",
"describe": "readonly",
"it": "readonly",
"mocha": "readonly",
"DOMPurify": "readonly",
"Prism": "readonly",

"Alert": "readonly",
"Collapse": "readonly",
"Dropdown": "readonly",
"Modal": "readonly",
"Offcanvas": "readonly",
"Popover": "readonly",
"Tooltip": "readonly"
}
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg


*.sublime-project
*.sublime-workspace

node_modules/

MANIFEST

# PyInstaller
Expand Down
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
19 changes: 19 additions & 0 deletions Estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
'name': 'estate',
'depends': ['base'],
'application': True,
'installable': True,
'author': 'estate',
'category': 'Tutorials',
'license': 'AGPL-3',
'data': [
'security/ir.model.access.csv',
'data/date_cron.xml',
'views/estate_property_type_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_tags_views.xml',
'views/estate_property_views.xml',
'views/res_users_view.xml',
'views/estate_menus.xml',
],
}
10 changes: 10 additions & 0 deletions Estate/data/date_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<odoo>
<record id="ir_cron_move_sold" model="ir.cron">
<field name="name">Sold if validity exceeds</field>
<field name="model_id" ref="model_estate_property_offer"/>
<field name="state">code</field>
<field name="code">model._cron_move_sold</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
</record>
</odoo>
5 changes: 5 additions & 0 deletions Estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_offer
from . import estate_property_type
from . import estate_property_tag
from . import res_users
136 changes: 136 additions & 0 deletions Estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
from datetime import timedelta

from odoo import models, fields, api
from odoo.exceptions import ValidationError, UserError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property"
_order = "id desc "
name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
create_date = fields.Datetime()
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True)
bedrooms = fields.Integer()
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
]
)
active = fields.Boolean(default=True)
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("canceled", "Canceled"),
],
required=True,
copy=False,
default="new"
)
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
buyer_id = fields.Many2one("res.partner", string="Buyer")
salesperson_id = fields.Many2one("res.users", string="Salesperson")
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Float(compute="_compute_total_area", string="Total Area", store=True)
best_price = fields.Float(compute="_compute_best_price", string="Best Offer", store=True)
validity_days = fields.Integer(default=7)
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True)

_check_price = models.Constraint(
'CHECK(expected_price > 0 AND selling_price >= 0)',
'The Price of a property must be strictly positive.',
)

@api.depends("living_area", "garden_area")
def _compute_total_area(self):
for record in self:
record.total_area = (record.living_area or 0) + (record.garden_area or 0)

@api.depends("offer_ids.price", "state")
def _compute_best_price(self):
for record in self:
record.best_price = max(record.offer_ids.mapped("price")) if record.offer_ids else 0.0

@api.depends("create_date", "validity_days")
def _compute_date_deadline(self):
for record in self:
create_date = record.create_date or fields.Date.today()
if hasattr(create_date, "date"):
create_date = create_date.date()
record.date_deadline = create_date + timedelta(days=record.validity_days)

def _inverse_date_deadline(self):
for record in self:
create_date = record.create_date or fields.Date.today()
if hasattr(create_date, "date"):
create_date = create_date.date()
delta = (record.date_deadline - create_date).days if record.date_deadline else 0
record.validity_days = delta

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=2):
if float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) < 0:
raise ValidationError("The selling price cannot be lower than 90% of the expected price.")

@api.onchange("garden")
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = False

@api.model
def create(self, vals):
record = super().create(vals)
if record.offer_ids:
record.state = 'offer_received'
return record

def write(self, vals):
res = super().write(vals)
if 'offer_ids' in vals:
for record in self:
if record.offer_ids and record.state != 'offer_received':
record.state = 'offer_received'
return res

def action_set_sold(self):
for record in self:
if record.state != 'canceled':
record.state = 'sold'
else:
raise UserError("once sold cannot be canceled")

def action_set_canceled(self):
for record in self:
record.state = "canceled"

def action_back_to_new(self):
for record in self:
record.state = "new"

def _unlink(self):
for record in self:
if record.state in ["new"]:
raise ValidationError("You cannot delete a new or canceled property.")
return super().unlink()
78 changes: 78 additions & 0 deletions Estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from datetime import timedelta
from odoo import models, fields, api
from odoo.exceptions import UserError


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer"
_order = "price desc"

price = fields.Float(string="Price", required=True)
status = fields.Selection(
[('accepted', 'Accepted'), ('refused', 'Refused')],
string="Status",
copy=False
)
partner_id = fields.Many2one("res.partner", string="Buyer", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(default=7, string="Validity (Days)")
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline")

_check_price = models.Constraint(
'CHECK(price > 0)',
'The offer price must be strictly positive'
)

@api.depends("create_date", "validity")
def _compute_date_deadline(self):
for record in self:
base_date = record.create_date.date() if record.create_date else fields.Date.today()
record.date_deadline = base_date + timedelta(days=record.validity)

def _inverse_date_deadline(self):
for record in self:
base_date = record.create_date.date() if record.create_date else fields.Date.today()
if record.date_deadline:
record.validity = (record.date_deadline - base_date).days

def action_accept_offer(self):
for record in self:
if record.status == 'accepted':
continue

record.status = 'accepted'
record.property_id.write({
'selling_price': record.price,
'buyer_id': record.partner_id.id,
'state': 'offer_accepted'
})

record.property_id.offer_ids.filtered(lambda o: o.id != record.id).write({
'status': 'refused'
})
return True

def action_refuse_offer(self):
for record in self:
record.status = 'refused'
return True

@api.model
def create(self, vals):
if len(vals) > 0:
property = self.env['estate.property'].browse(vals[0]['property_id'])
for record in vals:
if property.state == 'new':
property.state = 'offer_received'
if record['price'] < property.best_price:
raise UserError("Offer must be higher or equal than %d" % property.best_price)
return super().create(vals)

@api.model
def _cron_move_sold(self):
expired_offers = self.search([
('status', '=', False),
('date_deadline', '<', fields.Date.today())
])
expired_offers.write({'status': 'refused'})
10 changes: 10 additions & 0 deletions Estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models, fields


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_order = "name desc "
color = fields.Integer(string='Color Index', default=3)

name = fields.Char(required=True)
25 changes: 25 additions & 0 deletions Estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from odoo import models, fields, api


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"
_order = "sequence , name"

name = fields.Char(required=True)
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
sequence = fields.Integer('Sequence', default=7)
offer_count = fields.Integer(string="Number of Offers", compute="_compute_offer_count")

_check_type_name_unique_ratio = models.Constraint(
'CHECK(name)',
'The property name must be unique.'
)

@api.depends('property_ids.offer_ids')
def _compute_offer_count(self):
for property_type in self:
offer_count = 0
for property in property_type.property_ids:
offer_count += len(property.offer_ids)
property_type.offer_count = offer_count
9 changes: 9 additions & 0 deletions Estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import models, fields


class ResUsers(models.Model):
_inherit = "res.users"

estate_property_ids = fields.One2many(
"estate.property", "salesperson_id", string="Properties as Salesperson"
)
6 changes: 6 additions & 0 deletions Estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
estate.access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
estate.access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
estate.access_res_users,access_res_users,model_res_users,base.group_user,1,1,1,1
Loading