Skip to content

[ADD] estate_gasa,*: Implemented Real Estate with Accounting using Account Module #843

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

Draft
wants to merge 9 commits into
base: 18.0
Choose a base branch
from
Draft
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Ignore VS Code settings
.vscode/
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"esbenp.prettier-vscode"
]
}
2 changes: 2 additions & 0 deletions estate_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3
from . import models
10 changes: 10 additions & 0 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
'name': "Account",
'version': '1.0',
'depends': ['base', 'estate_gasa', 'account'],
'author': "gasa",
'category': 'Category',
"license": "LGPL-3",
"application": True,
"sequence": 1
}
1 change: 1 addition & 0 deletions estate_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate
43 changes: 43 additions & 0 deletions estate_account/models/estate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odoo import models, Command
from odoo.exceptions import UserError


class Estate(models.Model):
_inherit = 'estate.property'

def action_mark_sold(self):
self.check_access_rights('write')
self.check_access_rule('write')
res = super().action_mark_sold()

journal = self.env['account.journal'].sudo().search([('type', '=', 'sale')], limit=1)
if not journal:
raise UserError("No sale journal found. Please configure at least one sale journal.")

for record in self:
if not record.buyer:
raise UserError("Please set a Buyer before generating an invoice.")
if not record.selling_price:
raise UserError("Please set a Selling Price before generating an invoice.")

invoice_vals = {
"partner_id": record.buyer.id,
"move_type": "out_invoice",
"journal_id": journal.id,
"invoice_line_ids": [
Command.create({
"name": "6% Commission",
"quantity": 1,
"price_unit": 0.06 * record.selling_price,
}),
Command.create({
"name": "Administrative Fees",
"quantity": 1,
"price_unit": 100.0,
}),
]
}

self.env["account.move"].sudo().create(invoice_vals)

return res
2 changes: 2 additions & 0 deletions estate_gasa/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3
from . import models
25 changes: 25 additions & 0 deletions estate_gasa/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
'name': "estate",
'version': '1.0',
'depends': ['base'],
'author': "gasa",
'category': 'Real Estate/Brokerage',
"license": "LGPL-3",
"application": True,
"sequence": 1,
'data': [
'security/security.xml',
'security/ir.model.access.csv',
'security/estate_property_rules.xml',
'data/estate.property.type.csv',
'views/estate_property_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_tag_views.xml',
'views/inherited_model.xml',
'views/estate_menus.xml'
],
"demo": [
'demo/estate_property_demo_data.xml',
],
}
5 changes: 5 additions & 0 deletions estate_gasa/data/estate.property.type.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name
estate_property_type_residential,Residential
estate_property_type_commercial,Commercial
estate_property_type_industrial,Industrial
estate_property_type_land,Land
98 changes: 98 additions & 0 deletions estate_gasa/demo/estate_property_demo_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="demo_property_big_villa" model="estate.property">
<field name="name">Big Villa</field>
<field name="state">new</field>
<field name="description">A nice and big villa</field>
<field name="postcode">12345</field>
<field name="date_availability">2025-07-10</field>
<field name="expected_price">97000</field>
<field name="selling_price">97000</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">100</field>
<field name="garden_orientation">south</field>
<field name="property_type" ref="estate_property_type_residential" />
</record>

<record id="demo_property_trailer_home" model="estate.property">
<field name="name">Trailer home</field>
<field name="state">cancelled</field>
<field name="description">Home in a trailer park</field>
<field name="postcode">54321</field>
<field name="date_availability">2025-07-10</field>
<field name="expected_price">1000</field>
<field name="selling_price">1000</field>
<field name="bedrooms">2</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_orientation">south</field>
<field name="property_type" ref="estate_property_type_residential" />
</record>

<record id="property_offer_1" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_2" />
<field name="property_id" ref="demo_property_big_villa" />
<field name="price">90000</field>
<field name="validity">14</field>
<field name="date_deadline" eval="(datetime.now() + timedelta(days=14)).date().isoformat()" />
</record>

<record id="property_offer_2" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_2" />
<field name="property_id" ref="demo_property_big_villa" />
<field name="price">1500000</field>
<field name="validity">14</field>
<field name="date_deadline" eval="(datetime.now() + timedelta(days=14)).date().isoformat()" />
</record>

<record id="property_offer_3" model="estate.property.offer">
<field name="partner_id" ref="base.res_partner_3" />
<field name="property_id" ref="demo_property_big_villa" />
<field name="price">1500001</field>
<field name="validity">14</field>
<field name="date_deadline" eval="(datetime.now() + timedelta(days=14)).date().isoformat()" />
</record>
<function model="estate.property.offer" name="action_accept">
<value eval="[ref('property_offer_1')]" />
</function>

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

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

<record id="demo_property_with_inline_offers" model="estate.property">
<field name="name">Estate with Inline Offers</field>
<field name="state">new</field>
<field name="postcode">44444</field>
<field name="expected_price">120000</field>
<field name="date_availability">2025-07-15</field>
<field name="garden">True</field>
<field name="garage">True</field>
<field name="bedrooms">3</field>
<field name="living_area">95</field>
<field name="property_type" ref="estate_property_type_residential" />
<field name="offer_ids"
eval="[
Command.create({
'partner_id': ref('base.res_partner_2'),
'price': 100000,
'validity': 10,
}),
Command.create({
'partner_id': ref('base.res_partner_3'),
'price': 115000,
'validity': 14,
})
]" />
</record>
</odoo>
6 changes: 6 additions & 0 deletions estate_gasa/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# License LGPL-3
from . import estate
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import inherited_model
137 changes: 137 additions & 0 deletions estate_gasa/models/estate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from odoo import api, fields, models
from datetime import date, timedelta
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class Estate(models.Model):
_name = "estate.property"
_description = "Estate Property"
_order = "id desc"

name = fields.Char(required=True, default="Unknown")
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
expected_price = fields.Float()
bedrooms = fields.Integer(default=2)
last_seen = fields.Datetime("Last Seen", default=fields.Date.today)
date_availability = fields.Date(default=lambda self: date.today() + timedelta(days=90), copy=False)
active = fields.Boolean(default=True)
living_area = fields.Integer(string="Living Area")
facades = fields.Integer(string="Facades")
garage = fields.Boolean(string="Garage")
garden = fields.Boolean(string="Garden")
garden_area = fields.Integer(string="Garden Area")
garden_orientation = fields.Selection(
[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West')
],
string="Garden Orientation"
)
state = fields.Selection(
selection=[
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled')
],
default='new',
required=True,
copy=False
)
property_type = fields.Many2one("estate.property.type", string="Property Type")
buyer = fields.Many2one(
"res.partner",
string="Buyer",
copy=False
)
seller = fields.Many2one(
"res.users",
string="Salesperson",
default=lambda self: self.env.user
)
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many(
"estate.property.offer", "property_id", string="Offers"
)
total_area = fields.Integer(
string="Total Area",
compute="_compute_total_area",
store=True
)

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

selling_price = fields.Float(copy=False)
company_id = fields.Many2one(
'res.company',
string='Company',
required=True,
default=lambda self: self.env.company
)

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

@api.depends("offer_ids.price")
def _compute_best_price(self):
for record in self:
prices = record.offer_ids.mapped("price")
record.best_price = max(prices) if prices else 0.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 = False

def action_mark_sold(self):
for record in self:
if record.state == 'cancelled':
raise UserError("Canceled properties cannot be sold.")
record.state = 'sold'

def action_mark_cancelled(self):
for record in self:
if record.state == 'sold':
raise UserError("Sold properties cannot be canceled.")
record.state = 'cancelled'

@api.constrains('selling_price', 'expected_price')
def _check_selling_price_threshold(self):
for record in self:
if float_is_zero(record.selling_price, precision_digits=2):
continue

minimum_allowed = record.expected_price * 0.9

if float_compare(record.selling_price, minimum_allowed, precision_digits=2) < 0:
raise ValidationError(
("The selling price cannot be lower than 90%% of the expected price.\n"
"Expected Price: %.2f, Selling Price: %.2f (Minimum allowed: %.2f)") %
(record.expected_price, record.selling_price, minimum_allowed)
)

@api.ondelete(at_uninstall=False)
def _check_property_state_before_delete(self):
for record in self:
if record.state not in ['new', 'cancelled']:
raise UserError("You can only delete properties that are in 'New' or 'Cancelled' state.")

_sql_constraints = [
('check_expected_price_positive', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'),
('check_selling_price_positive', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'),
]
Loading