-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] real_estate: create two module real estate and account #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
base: 18.0
Are you sure you want to change the base?
Changes from all commits
7aaf839
8b76f10
26fc1ca
d48f4ad
1a7732c
567b121
d337c6c
baf7908
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"esbenp.prettier-vscode" | ||
] | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Licensing statement |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
'name': "Account", | ||
'version': '1.0', | ||
'depends': ['base', 'estate_gasa', 'account'], | ||
'author': "Author Name", | ||
'category': 'Category', | ||
"license": "LGPL-3", | ||
"application": True, | ||
"sequence": 1, | ||
# 'data': [ | ||
# 'views/estate_property_views.xml', | ||
# ], | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this if not required |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import estate |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from odoo import models, Command | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class Estate(models.Model): | ||
_inherit = 'estate.property' | ||
|
||
def action_mark_sold(self): | ||
res = super().action_mark_sold() | ||
|
||
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.") | ||
|
||
journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1) | ||
if not journal: | ||
raise UserError("No sale journal found. Please configure at least one sale journal.") | ||
|
||
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"].create(invoice_vals) | ||
|
||
return res | ||
Comment on lines
+9
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this search query in the for loop ? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
'name': "estate", | ||
'version': '1.0', | ||
'depends': ['base'], | ||
'author': "Author Name", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure you put a real author name |
||
'category': 'Category', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a valid category |
||
"license": "LGPL-3", | ||
"application": True, | ||
"sequence": 1, | ||
'data': [ | ||
'security/ir.model.access.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', | ||
Comment on lines
+10
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation is not right |
||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import estate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing licensing |
||
from . import estate_property_type | ||
from . import estate_property_tag | ||
from . import estate_property_offer | ||
from . import inherited_model |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
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") | ||
garden = fields.Boolean(string="Garage") | ||
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 | ||
) | ||
|
||
@api.depends('living_area', 'garden_area') | ||
def _compute_total_area(self): | ||
for record in self: | ||
record.total_area = record.living_area + record.garden_area | ||
|
||
best_price = fields.Float( | ||
string="Best Offer", | ||
compute="_compute_best_price" | ||
) | ||
selling_price = fields.Float(copy=False) | ||
Comment on lines
+67
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field definition should be before the compute function definitions |
||
|
||
@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' | ||
|
||
_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.'), | ||
] | ||
|
||
@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.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from odoo import api, models, fields | ||
from odoo.exceptions import UserError, ValidationError | ||
from datetime import timedelta | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = "estate.property.offer" | ||
_description = "Property Offer" | ||
_order = "price desc" | ||
|
||
price = fields.Float() | ||
status = fields.Selection([ | ||
('accepted', 'Accepted'), | ||
('refused', 'Refused') | ||
], | ||
copy=False | ||
) | ||
|
||
partner_id = fields.Many2one("res.partner", string="Customer", required=True) | ||
property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
|
||
property_type_id = fields.Many2one( | ||
related='property_id.property_type', | ||
string="Property Type", | ||
store=True | ||
) | ||
|
||
validity = fields.Integer(default=7) | ||
date_deadline = fields.Date( | ||
compute="_compute_date_deadline", | ||
inverse="_inverse_date_deadline", | ||
store=True | ||
) | ||
|
||
@api.depends("validity", "create_date") | ||
def _compute_date_deadline(self): | ||
for record in self: | ||
create_date = record.create_date or fields.Datetime.now() | ||
record.date_deadline = create_date.date() + timedelta(days=record.validity) | ||
|
||
def _inverse_date_deadline(self): | ||
for record in self: | ||
create_date = record.create_date or fields.Datetime.now() | ||
record.validity = (record.date_deadline - create_date.date()).days | ||
|
||
def action_accept(self): | ||
for offer in self: | ||
if offer.property_id.state == 'sold': | ||
raise UserError("Cannot accept an offer for a sold property.") | ||
other_offers = offer.property_id.offer_ids.filtered(lambda o: o.id != offer.id) | ||
other_offers.write({'status': 'refused'}) | ||
|
||
offer.status = 'accepted' | ||
offer.property_id.selling_price = offer.price | ||
offer.property_id.buyer = offer.partner_id | ||
offer.property_id.state = 'offer_accepted' | ||
|
||
def action_refuse(self): | ||
for offer in self: | ||
offer.status = 'refused' | ||
|
||
_sql_constraints = [ | ||
('check_offer_price_positive', 'CHECK(price > 0)', | ||
'The offer price must be strictly positive.'), | ||
] | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for vals in vals_list: | ||
property_id = vals.get('property_id') | ||
amount = vals.get('price') | ||
|
||
if property_id and amount: | ||
existing_offers = self.search([ | ||
('property_id', '=', property_id), | ||
('price', '>=', amount) | ||
]) | ||
if existing_offers: | ||
raise ValidationError("An offer with a higher or equal price already exists.") | ||
|
||
property = self.env['estate.property'].browse(property_id) | ||
if property.state == 'new': | ||
property.state = 'offer_received' | ||
|
||
return super().create(vals_list) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from odoo import models, fields | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "Real Estate Property Tag" | ||
_order = "name" | ||
|
||
name = fields.Char(required=True) | ||
color = fields.Integer(string="Color") | ||
sequence = fields.Integer(string="Sequence", default=10) | ||
|
||
_sql_constraints = [ | ||
('unique_tag_name', 'UNIQUE(name)', | ||
'Tag name must be unique.'), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from odoo import api, models, fields | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Property Type" | ||
_order = "sequence, name" | ||
|
||
name = fields.Char(required=True) | ||
sequence = fields.Integer(string="Sequence", default=10) | ||
property_ids = fields.One2many("estate.property", "property_type", string="Properties") | ||
|
||
_sql_constraints = [ | ||
('unique_property_type_name', 'UNIQUE(name)', | ||
'Property type name must be unique.'), | ||
] | ||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not the right place to define the sqlconstraints |
||
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string="Offers") | ||
offer_count = fields.Integer(compute='_compute_offer_count') | ||
|
||
@api.depends('offer_ids') | ||
def _compute_offer_count(self): | ||
for rec in self: | ||
rec.offer_count = len(rec.offer_ids) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class InheritedModel(models.Model): | ||
_inherit = "res.users" | ||
|
||
property_ids = fields.One2many( | ||
"estate.property", | ||
"seller", | ||
string="Properties", | ||
domain=[('state', '!=', 'cancelled')] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
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_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End of file line is missing |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<menuitem id="estate_menu_root" name="Estate" /> | ||
|
||
<!-- Submenu: Advertisements--> | ||
<menuitem id="estate_menu_properties" name="Application" parent="estate_menu_root" /> | ||
<menuitem id="estate_menu_property_action" name="Properties" action="estate_property_action" | ||
parent="estate_menu_properties" /> | ||
|
||
<!-- Submenu: Settings --> | ||
<menuitem id="estate_menu_settings" name="Settings" parent="estate_menu_root" /> | ||
<menuitem id="estate_menu_property_type" name="Property Types" | ||
action="estate_property_type_action" parent="estate_menu_settings" /> | ||
<menuitem id="estate_menu_property_tag" name="Property Tags" | ||
parent="estate_menu_settings" action="estate_property_tag_action" /> | ||
</odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this.
This is not need here