-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ADD] estate: create estate.property model and initial views #107
Changes from 5 commits
4f44de4
39a6abb
0db7313
9564242
cae8bfd
090fd5b
b189355
27fc6ce
50bb5db
6dd52ac
1e0cd9a
45c7b7d
58784c3
028d494
9b8798f
a688159
bb55acf
16712c7
ababe7f
0b1f226
f863581
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 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
'name': "estate", | ||
'version': '0.1', | ||
'depends': ['base', 'mail'], | ||
'description': "Technical practice", | ||
'installable': True, | ||
'application': True, | ||
|
||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/estate_property_views.xml', | ||
'views/estate_property_offer_view.xml', | ||
'views/estate_property_type.xml', | ||
'views/estate_property_tag_view.xml', | ||
'views/estate_menus.xml', | ||
], | ||
'license': 'LGPL-3', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import estate_property | ||
from . import estate_property_type | ||
from . import estate_property_tag | ||
from . import estate_property_offer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
from odoo import models, fields, api | ||
from dateutil.relativedelta import relativedelta | ||
from datetime import date | ||
from odoo.exceptions import UserError, ValidationError | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Real Estate Property Data" | ||
_inherit = ["mail.thread", "mail.activity.mixin"] | ||
name = fields.Char(required=True) | ||
description = fields.Char() | ||
postcode = fields.Char() | ||
date_availability = fields.Date( | ||
copy=False, default=date.today() + relativedelta(months=3) | ||
) | ||
expected_price = fields.Float(required=True) | ||
selling_price = fields.Float(copy=False, readonly=True) | ||
bedrooms = fields.Integer(default=2) | ||
living_area = fields.Integer() | ||
facades = fields.Integer() | ||
garage = fields.Boolean() | ||
garden = fields.Boolean() | ||
garden_area = fields.Integer() | ||
active = fields.Boolean(default=True) | ||
state = fields.Selection( | ||
required=True, | ||
copy=False, | ||
default="new", | ||
selection=[ | ||
("new", "New"), | ||
("offer_recived", "Offer Recieved"), | ||
("offer_accepted", "Offer Accepted"), | ||
("sold", "Sold"), | ||
("canceled", "Canceled"), | ||
], | ||
tracking=True, | ||
) | ||
garden_orientation = fields.Selection( | ||
selection=[ | ||
("north", "North"), | ||
("south", "South"), | ||
("east", "East"), | ||
("west", "West"), | ||
] | ||
) | ||
_order = "id desc" | ||
salesman_id = fields.Many2one( | ||
"res.users", # The model this field relates to | ||
string="Salesman", # Label for the field | ||
default=lambda self: self.env.user, # Set default to the current user's partner | ||
) | ||
buyer_id = fields.Many2one( | ||
"res.partner", # The model this field relates to | ||
string="Buyer", # Label for the field | ||
copy=False, # Prevent the field value from being copied when duplicating the record | ||
) | ||
|
||
tag_ids = fields.Many2many("estate.property.tag", string="Tags", ondelete="cascade") | ||
offer_ids = fields.One2many("estate.property.offer", "property_id") | ||
total = fields.Integer(compute="total_area") | ||
best_offer = fields.Float(compute="best_offer_selete", store=True) | ||
property_type_id = fields.Many2one("estate.property.type") | ||
|
||
sql_constraints = [ | ||
( | ||
"check_expected_price", | ||
"CHECK(expected_price > 0)", | ||
"The Expected Price of Property should be positive", | ||
), | ||
( | ||
"check_selling_price", | ||
"CHECK(selling_price >= 0 )", | ||
"The Selling Price of Property should be Positive", | ||
), | ||
("name_uniq", "unique (name)", "Property name already exists!"), | ||
] | ||
|
||
@api.depends("living_area", "garden_area") | ||
def total_area(self): | ||
for recorde in self: | ||
recorde.total = recorde.living_area + recorde.garden_area | ||
|
||
@api.depends("offer_ids") | ||
def best_offer_selete(self): | ||
temp = 0 | ||
for offer in self.offer_ids: | ||
if offer.price > temp: | ||
temp = offer.price | ||
self.best_offer = temp | ||
|
||
@api.onchange("garden") | ||
def garden_change(self): | ||
if self.garden: | ||
self.garden_area = 10 | ||
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = "" | ||
|
||
def status_action_sold_button(self): | ||
if self.state == "canceled": | ||
raise UserError("Canceled property can't be sold") | ||
else: | ||
self.state = "sold" | ||
|
||
def status_action_canceled_button(self): | ||
if self.state == "sold": | ||
raise UserError("Sold property can't be canceled") | ||
else: | ||
self.state = "canceled" | ||
|
||
@api.constrains("selling_price", "expexted_price") | ||
def _check_date_end(self): | ||
for record in self: | ||
if record.selling_price > 0: | ||
price_percent = (record.selling_price / record.expected_price) * 100 | ||
if price_percent < 90: | ||
raise ValidationError("Selling Price must be at least 90%") |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||
from odoo import models, fields, api | ||||||||||||||||||||||||||
from datetime import timedelta, date | ||||||||||||||||||||||||||
from odoo.exceptions import ValidationError | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
class EstatePropertyOffer(models.Model): | ||||||||||||||||||||||||||
_name = "estate.property.offer" | ||||||||||||||||||||||||||
_description = "Estate Property Offer" | ||||||||||||||||||||||||||
_order = "price desc" | ||||||||||||||||||||||||||
price = fields.Float() | ||||||||||||||||||||||||||
status = fields.Selection( | ||||||||||||||||||||||||||
copy=False, selection=[("accepted", "Accepted"), ("refused", "Refused")] | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
partner_id = fields.Many2one("res.partner", required=True) | ||||||||||||||||||||||||||
property_id = fields.Many2one("estate.property", required=True) | ||||||||||||||||||||||||||
validity = fields.Integer(default=7) | ||||||||||||||||||||||||||
deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline") | ||||||||||||||||||||||||||
property_type_id = fields.Many2one(related='property_id.property_type_id', store=True) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@api.ondelete(at_uninstall=False) | ||||||||||||||||||||||||||
def _check_offer(self): | ||||||||||||||||||||||||||
for record in self: | ||||||||||||||||||||||||||
if record.status == "accepted": | ||||||||||||||||||||||||||
# raise ValidationError("Accepted offer have benn deleted") | ||||||||||||||||||||||||||
record.property_id.selling_price = 0 | ||||||||||||||||||||||||||
record.property_id.buyer_id = None | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@api.depends("validity") | ||||||||||||||||||||||||||
def _compute_deadline(self): | ||||||||||||||||||||||||||
for record in self: | ||||||||||||||||||||||||||
today = record.create_date | ||||||||||||||||||||||||||
if today: | ||||||||||||||||||||||||||
today = record.create_date | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
today = date.today() | ||||||||||||||||||||||||||
if record.validity: | ||||||||||||||||||||||||||
record.deadline = today + timedelta(days=record.validity) | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
record.deadline = today | ||||||||||||||||||||||||||
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.
Suggested change
Can you give it a try but make sure to check all the cases |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def _inverse_deadline(self): | ||||||||||||||||||||||||||
for record in self: | ||||||||||||||||||||||||||
if record.deadline: | ||||||||||||||||||||||||||
# Convert create_date to a date object | ||||||||||||||||||||||||||
today = fields.Date.to_date(record.create_date) | ||||||||||||||||||||||||||
# Convert deadline to a date object | ||||||||||||||||||||||||||
deadline_date = fields.Date.from_string(record.deadline) | ||||||||||||||||||||||||||
record.validity = (deadline_date - today).days | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
record.validity = 7 # Default to 7 if deadline is not set | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def action_status_accept(self): | ||||||||||||||||||||||||||
self.status = "accepted" | ||||||||||||||||||||||||||
price_percent = 0 | ||||||||||||||||||||||||||
if self.property_id.expected_price != 0: | ||||||||||||||||||||||||||
price_percent = (self.price / self.property_id.expected_price) * 100 | ||||||||||||||||||||||||||
if price_percent > 90: | ||||||||||||||||||||||||||
self.property_id.selling_price = self.price | ||||||||||||||||||||||||||
self.property_id.buyer_id = self.partner_id | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
raise ValidationError("The selling price must be at least 90%") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def aciton_status_refused(self): | ||||||||||||||||||||||||||
if self.status == "accepted": | ||||||||||||||||||||||||||
self.property_id.selling_price = 0 | ||||||||||||||||||||||||||
self.property_id.buyer_id = None | ||||||||||||||||||||||||||
self.status = "refused" | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
self.status = "refused" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
_sql_constraints = [ | ||||||||||||||||||||||||||
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. Generally we define SQL constraints just after field definition |
||||||||||||||||||||||||||
("check_price", "CHECK(price >= 0)", "The Price of Offer should be positive"), | ||||||||||||||||||||||||||
] |
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 = 'Estate Property tag' | ||
name = fields.Char(required=True) | ||
_sql_constraints = [('name_uniq', 'unique (name)', "Tag name already exists!")] | ||
_order = 'name' | ||
color = fields.Integer() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from odoo import fields, models, api | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Real Estate Property Type" | ||
name = fields.Char(required=True) | ||
property_id = fields.One2many('estate.property', 'property_type_id') | ||
_order = 'sequence, name' | ||
sequence = fields.Integer('Sequence', help="Used to order stages. Lower is better.") | ||
offers_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
offer_count = fields.Integer(compute='_offers_count', help="Number of offers") | ||
|
||
@api.depends('offers_ids.property_type_id') | ||
def _offers_count(self): | ||
for record in self: | ||
if record.offers_ids: | ||
record.offer_count = len(record.offers_ids) | ||
else: | ||
record.offer_count = 0 |
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" | ||
access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 | ||
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 | ||
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 | ||
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<odoo> | ||
<menuitem id="estate_property_root" name="Real Estate"> | ||
|
||
<menuitem id="estate_property_first_level_menu" name="Advertisment"> | ||
<menuitem id="estate_property_model_menu_action" action="estate_property_action"/> | ||
</menuitem> | ||
|
||
<menuitem id="estate_property_type_level_menu" name="Setting"> | ||
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/> | ||
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action"/> | ||
</menuitem> | ||
|
||
</menuitem> | ||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<odoo> | ||
|
||
<record id='estate_property_offer_tree' model='ir.ui.view'> | ||
<field name="name">estate_property_offer</field> | ||
<field name="model">estate.property.offer</field> | ||
<field name="arch" type="xml"> | ||
<tree editable="bottom" sample="1" decoration-danger="status in ('refused', 'Refused')" decoration-success="status in ('accepted', 'Accepted')"> | ||
<field name='price'/> | ||
<field name='partner_id'/> | ||
|
||
<field name='validity' string='Validity (days)'/> | ||
<field name='deadline'/> | ||
<button name="action_status_accept" invisible="status in ('accepted', 'refused')" title="accept" type="object" icon="fa-check" /> | ||
<button name="aciton_status_refused" invisible="status in ('accepted', 'refused')" title="refused" type="object" icon="fa-times"/> | ||
<field name='status' column_invisible='1' /> | ||
</tree> | ||
</field> | ||
|
||
</record> | ||
|
||
|
||
<record id='estate_property_offer_form' model='ir.ui.view'> | ||
<field name="name">estate_property_offer_form</field> | ||
<field name="model">estate.property.offer</field> | ||
<field name="arch" type="xml"> | ||
<form > | ||
<sheet> | ||
<group > | ||
<field name='price'/> | ||
<field name='partner_id'/> | ||
<field name="validity"/> | ||
<field name="deadline"/> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
<record id="action_estate_property_offer" model="ir.actions.act_window"> | ||
<field name="name">Estate Property Offers</field> | ||
<field name="res_model">estate.property.offer</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="domain">[('property_type_id', '=', active_id)]</field> | ||
</record> | ||
<record id="action_estate_property_offer_y" model="ir.actions.act_window"> | ||
<field name="name">Estate Property Offers</field> | ||
<field name="res_model">estate.property.offer</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="domain">[('property_type_id', '=', active_id)]</field> | ||
</record> | ||
|
||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<odoo> | ||
<record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
<field name="name">Property Tag</field> | ||
<field name="res_model">estate.property.tag</field> | ||
<field name="view_mode">tree,form</field> | ||
|
||
<field name="help" type="html"> | ||
<p class="o_view_nocontent_smiling_face"> | ||
Create a new Property product | ||
</p> | ||
</field> | ||
</record> | ||
|
||
<record id='estate_property_tag_tree' model='ir.ui.view'> | ||
<field name="name">estate_property_tag</field> | ||
<field name="model">estate.property.tag</field> | ||
<field name="arch" type="xml"> | ||
<tree editable="bottom" sample="1"> | ||
<field name='name'/> | ||
</tree> | ||
</field> | ||
|
||
</record> | ||
</odoo> | ||
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. Need a blank line at the EOF |
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.
Generally, we first import external libraries and then we import from odoo. And also take care for the imports in alphabetical order.