Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Commit for Creating a PR #192

Open
wants to merge 23 commits into
base: 18.0
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
cgun-odoo marked this conversation as resolved.
Show resolved Hide resolved
from . import models
34 changes: 34 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
{
"name": "Estate",
"summary": """
Tutorial starting module
""",
"description": """
Tutorial starting module
""",
"author": "",
"category": "Real Estate/Brokerage",
"version": "0.1",
"depends": ["base"],
"application": True,
"demo": [
"demo/estate.property.type.csv",
"demo/estate_property_demo.xml",
"demo/estate_property_offer_demo.xml",
],
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"security/ir_rule.xml",
"views/estate_property_tag_views.xml",
"views/estate_property_offer_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_views.xml",
"views/estate_salesperson_views.xml",
"views/estate_menus.xml",
"report/estate_property_reports.xml",
"report/estate_property_templates.xml",
],
"license": "AGPL-3",
}
5 changes: 5 additions & 0 deletions estate/demo/estate.property.type.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"id","name","property_ids:id","sequence","offer_ids:id","offer_count"
property_type_1,"Residential",,"6",,"0"
property_type_2,"Commercial",,"1",,"0"
property_type_3,"Industrial",,"3",,"0"
property_type_4,"Land",,"16",,"0"
65 changes: 65 additions & 0 deletions estate/demo/estate_property_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<odoo>
<data>
<record id="estate_property_1" model="estate.property">
<field name="name">Big Villa</field>
<field name="property_type_id" ref="property_type_1"></field>
<field name="state">received</field>
<field name="description">A nice and big villa</field>
<field name="postcode">12345</field>
<field name="date_availability">1970-01-01</field>
<field name="expected_price">1600000</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
<field name="facades">4</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">100000</field>
<field name="garden_orientation">south</field>
<field name="salesperson_id"></field>
<field name="company_id" ref="base.main_company"></field>
</record>

<record id="estate_property_2" model="estate.property">
<field name="name">trailer home</field>
<field name="property_type_id" ref="property_type_1"></field>
<field name="state">received</field>
<field name="description">Home in a trailer park</field>
<field name="postcode">54321</field>
<field name="date_availability">1970-01-01</field>
<field name="expected_price">100000</field>
<field name="selling_price">120000</field>
<field name="bedrooms">1</field>
<field name="living_area">10</field>
<field name="facades">4</field>
<field name="garage">False</field>
<field name="salesperson_id"></field>
<field name="company_id" ref="base.main_company"></field>
</record>

<record id="estate_property_3" model="estate.property">
<field name="name">Fancy Apartment</field>
<field name="property_type_id" ref="property_type_1"></field>
<field name="state">new</field>
<field name="description">A nice and big apartment</field>
<field name="postcode">12345</field>
<field name="date_availability">1970-01-01</field>
<field name="expected_price">1600000</field>
<field name="bedrooms">6</field>
<field name="living_area">100</field>
<field name="facades">4</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">100000</field>
<field name="garden_orientation">south</field>
<field name="salesperson_id"></field>
<field name="offer_ids" eval="[
Command.create({
'price': 1500000,
'partner_id': ref('base.res_partner_12'),
'validity': 14
})
]"/>
<field name="company_id" ref="base.main_company"></field>
</record>
</data>
</odoo>
63 changes: 63 additions & 0 deletions estate/demo/estate_property_offer_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<odoo>
<data>
<record id="estate_property_offer_1" model="estate.property.offer">
<field name="price">10000</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_1"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>

<record id="estate_property_offer_2" model="estate.property.offer">
<field name="price">1500000</field>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_1"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>

<record id="estate_property_offer_3" model="estate.property.offer">
<field name="price">1500001</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_1"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>

<function model="estate.property.offer" name="action_refuse">
<value eval="[ref('estate_property_offer_1')]"/>
</function>

<function model="estate.property.offer" name="action_accept">
<value eval="[ref('estate_property_offer_2')]"/>
</function>

<function model="estate.property.offer" name="action_refuse">
<value eval="[ref('estate_property_offer_3')]"/>
</function>

<record id="estate_property_offer_4" model="estate.property.offer">
<field name="price">100000</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_2"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>

<record id="estate_property_offer_5" model="estate.property.offer">
<field name="price">120000</field>
<field name="partner_id" ref="base.res_partner_12"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_2"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>

<record id="estate_property_offer_6" model="estate.property.offer">
<field name="price">120001</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="validity">14</field>
<field name="property_id" ref="estate_property_2"/>
<field name="date_deadline" eval="datetime.now() + timedelta(days=14)"></field>
</record>
</data>
</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_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
161 changes: 161 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
from odoo import fields, models, api
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = 'estate.property'
_description = "Estate Property"
_order = 'id desc'
_sql_constraints = [
(
'check_expected_price_strictly_positive',
'CHECK(expected_price > 0)',
"The expected price should be strictly positive.",
),
(
'check_selling_price_positive',
'CHECK(selling_price >= 0)',
"The selling price should be positive.",
),
]

name = fields.Char("Title", required=True)

description = fields.Text("Description")

postcode = fields.Char("Postcode")

date_availability = fields.Date(
"Available From",
copy=False,
default=lambda self: fields.Date.today() + relativedelta(months=3),
)

expected_price = fields.Float("Expected Price", required=True)

selling_price = fields.Float("Selling Price", readonly=True, copy=False)

bedrooms = fields.Integer("Bedrooms", default=2)

living_area = fields.Integer("Living Area (sqm)")

facades = fields.Integer("Facades")

garage = fields.Boolean("Garage")

garden = fields.Boolean("Garden")

garden_area = fields.Integer("Garden Area (sqm)")

garden_orientation = fields.Selection(
string="Garden Orientation",
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
],
)

state = fields.Selection(
string="Status",
required=True,
copy=False,
default="new",
selection=[
('new', "New"),
('received', "Offer Received"),
('accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
)

active = fields.Boolean("Active", default=True)

property_type_id = fields.Many2one('estate.property.type', "Property Type")

buyer_id = fields.Many2one('res.partner', "Buyer", copy=False)

salesperson_id = fields.Many2one(
'res.users', "Salesperson", default=lambda self: self.env.user
)

tag_ids = fields.Many2many('estate.property.tag')

offer_ids = fields.One2many('estate.property.offer', 'property_id')

total_area = fields.Float(string="Total Area (sqm)", compute='_compute_total_area')

best_price = fields.Float(string="Best Price", compute='_compute_best_price')

company_id = fields.Many2one(
'res.company', "Agency", default=lambda self: self.env.company, required=True
)

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

@api.depends('offer_ids.price')
def _compute_best_price(self):
for record in self:
record.best_price = max(record.offer_ids.mapped("price"), default=0)

@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 = None

def action_sold(self):
for record in self:
if len(record.offer_ids) == 0:
raise UserError(self.env._("Properties without offers cannot be sold!"))
if record.state == 'cancelled':
raise UserError(self.env._("Cancelled properties cannot be sold!"))
else:
record.state = 'sold'
return True

def action_cancel(self):
for record in self:
if record.state == 'sold':
raise UserError(self.env._("Sold properties cannot be cancelled!"))
else:
record.state = 'cancelled'
return True

@api.constrains('selling_price')
def _check_compare_selling_price_to_expected_price(self):
for record in self:
if (
not float_is_zero(record.selling_price, precision_digits=5)
and float_compare(
record.selling_price,
record.expected_price * 0.9,
precision_digits=5,
)
< 0
):
raise ValidationError(
self.env._(
"Selling price of a property must not be less than 90 percent of the expected price."
)
)

@api.ondelete(at_uninstall=False)
def _unlink_if_correct_states(self):
for record in self:
if record.state not in ('new', 'cancelled'):
raise UserError(
self.env._(
"Only records with status New and Cancelled may be deleted."
)
)
Loading