-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ADD] estate: Created Estate Module #1049
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: 19.0
Are you sure you want to change the base?
Changes from all commits
0ce5e44
742a492
e197d7f
22d2d17
c260137
a6feab6
b048a7d
f21c9e7
dfc0ad5
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,20 @@ | ||
| { | ||
| 'name': "Real Estate", | ||
| 'version': '1.0', | ||
| 'license': 'LGPL-3', | ||
| 'summary': 'Real Estate advertisement tutorial module', | ||
| 'depends': ['base'], | ||
| 'author': "Harsh Maniya", | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| 'category': 'Sales/Real Estate', | ||
| 'installable': True, | ||
| 'auto_install': False, | ||
| 'description': """Real estate management tutorial module with properties, offers, types and tags.""", | ||
| } | ||
| 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,128 @@ | ||||||||||||||||||||||||
| from dateutil.relativedelta import relativedelta | ||||||||||||||||||||||||
| from datetime import date | ||||||||||||||||||||||||
| from odoo import models, fields, api | ||||||||||||||||||||||||
| from odoo.exceptions import UserError,ValidationError | ||||||||||||||||||||||||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||||||||||||||||||||||||
|
Comment on lines
+1
to
+5
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
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| class EstateProperty(models.Model): | ||||||||||||||||||||||||
| _name = "estate.property" | ||||||||||||||||||||||||
| _description = "Real Estate Property" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| name = fields.Char(required=True) | ||||||||||||||||||||||||
| description = fields.Text() | ||||||||||||||||||||||||
| postcode = fields.Char() | ||||||||||||||||||||||||
| date_availability = fields.Date( | ||||||||||||||||||||||||
| default=lambda sself: date.today() + relativedelta(months=3), | ||||||||||||||||||||||||
| copy=False | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| expected_price = fields.Float(string="Expected Price", required=True) | ||||||||||||||||||||||||
|
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. Please follow this -> #1049 (comment) |
||||||||||||||||||||||||
| selling_price = fields.Float( | ||||||||||||||||||||||||
| readonly=True, | ||||||||||||||||||||||||
| copy=False | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| bedrooms = fields.Integer(default=2) | ||||||||||||||||||||||||
| living_area = fields.Integer() | ||||||||||||||||||||||||
| facades = fields.Integer() | ||||||||||||||||||||||||
| garage = fields.Boolean() | ||||||||||||||||||||||||
| garden = fields.Boolean() | ||||||||||||||||||||||||
| garden_area = fields.Integer() | ||||||||||||||||||||||||
| garden_orientation = fields.Selection( | ||||||||||||||||||||||||
| selection=[ | ||||||||||||||||||||||||
| ('north', 'North'), | ||||||||||||||||||||||||
| ('south', 'South'), | ||||||||||||||||||||||||
| ('east', 'East'), | ||||||||||||||||||||||||
| ('west', 'West'), | ||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| active = fields.Boolean(default=True) | ||||||||||||||||||||||||
| state = fields.Selection( | ||||||||||||||||||||||||
| selection=[ | ||||||||||||||||||||||||
| ('new', 'New'), | ||||||||||||||||||||||||
| ('offer_received', 'Offer Received'), | ||||||||||||||||||||||||
| ('offer_accepted', 'Offer Accepted'), | ||||||||||||||||||||||||
| ('sold', 'Sold'), | ||||||||||||||||||||||||
| ('cancelled', 'Cancelled'), | ||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||
| copy=False, | ||||||||||||||||||||||||
| default='new', | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| property_type_id = fields.Many2one( | ||||||||||||||||||||||||
| "estate.property.type", | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| salesperson_id = fields.Many2one( | ||||||||||||||||||||||||
| "res.users", | ||||||||||||||||||||||||
| default=lambda self: self.env.user, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| buyer_id = fields.Many2one( | ||||||||||||||||||||||||
| "res.partner", | ||||||||||||||||||||||||
| copy=False, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| tag_ids = fields.Many2many( | ||||||||||||||||||||||||
| "estate.property.tag", | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| offer_ids = fields.One2many( | ||||||||||||||||||||||||
| "estate.property.offer", | ||||||||||||||||||||||||
| "property_id", | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| total_area = fields.Float( | ||||||||||||||||||||||||
| compute="_compute_total_area" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| best_price = fields.Float( | ||||||||||||||||||||||||
| compute="_compute_best_price", | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| _expected_price = models.Constraint( | ||||||||||||||||||||||||
| 'CHECK(expected_price >= 0)', | ||||||||||||||||||||||||
| 'The expected price must be positive.', | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| _selling_price = models.Constraint( | ||||||||||||||||||||||||
| 'CHECK(selling_price >= 0)', | ||||||||||||||||||||||||
| 'The selling price must be positive.', | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @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 = None | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def action_cancel(self): | ||||||||||||||||||||||||
| for rec in self: | ||||||||||||||||||||||||
| if rec.state == "sold": | ||||||||||||||||||||||||
| raise UserError("Sold properties cannot be cancelled.") | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| rec.state = "cancelled" | ||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||
|
Comment on lines
+104
to
+110
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. I think It's good to make the error message translatable. We can use filtered() here.
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def action_set_sold(self): | ||||||||||||||||||||||||
| for rec in self: | ||||||||||||||||||||||||
| if rec.state == "cancelled": | ||||||||||||||||||||||||
| raise UserError("Canceled properties cannot be sold.") | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| rec.state = "sold" | ||||||||||||||||||||||||
|
Comment on lines
+112
to
+117
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. Same here. |
||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||
| @api.constrains("selling_price", "expected_price") | ||||||||||||||||||||||||
|
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. Should be above one empty line. |
||||||||||||||||||||||||
| def _check_selling_price(self): | ||||||||||||||||||||||||
| for rec in self: | ||||||||||||||||||||||||
| if rec.selling_price == 0: | ||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||
| if float_compare(rec.selling_price, rec.expected_price * 0.9, precision_digits=2) < 0: | ||||||||||||||||||||||||
| raise ValidationError( | ||||||||||||||||||||||||
|
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. Same here, it should be translatable. |
||||||||||||||||||||||||
| "The selling price must be at least 90% of the expected price!\n" | ||||||||||||||||||||||||
| "You must reduce the expected price if you want to accept this offer." | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||
| from dateutil.relativedelta import relativedelta | ||||||||||||||||
| from odoo import models, fields, api | ||||||||||||||||
| from odoo.exceptions import UserError | ||||||||||||||||
|
Comment on lines
+1
to
+3
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
|
||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class EstatePropertyOffer(models.Model): | ||||||||||||||||
| _name = "estate.property.offer" | ||||||||||||||||
| _description = "Real Estate Property Offer" | ||||||||||||||||
|
|
||||||||||||||||
| price = fields.Float(string="Price") | ||||||||||||||||
| status = fields.Selection( | ||||||||||||||||
| [ | ||||||||||||||||
| ("accepted", "Accepted"), | ||||||||||||||||
| ("refused", "Refused"), | ||||||||||||||||
| ], | ||||||||||||||||
| copy=False, | ||||||||||||||||
| ) | ||||||||||||||||
| partner_id = fields.Many2one( | ||||||||||||||||
| "res.partner", | ||||||||||||||||
| required=True, | ||||||||||||||||
| ) | ||||||||||||||||
| property_id = fields.Many2one( | ||||||||||||||||
| "estate.property", | ||||||||||||||||
| required=True, | ||||||||||||||||
| ) | ||||||||||||||||
| validity = fields.Integer( | ||||||||||||||||
| default=7, | ||||||||||||||||
| ) | ||||||||||||||||
| date_deadline = fields.Date( | ||||||||||||||||
| compute="_compute_date_deadline", | ||||||||||||||||
| inverse="_inverse_date_deadline", | ||||||||||||||||
| store=True, | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| @api.depends("validity") | ||||||||||||||||
| def _compute_date_deadline(self): | ||||||||||||||||
| for rec in self: | ||||||||||||||||
| create = rec.create_date or fields.Date.today() | ||||||||||||||||
| rec.date_deadline = (create + relativedelta(days=rec.validity)) | ||||||||||||||||
|
|
||||||||||||||||
| def _inverse_date_deadline(self): | ||||||||||||||||
| for rec in self: | ||||||||||||||||
| create = rec.create_date or fields.Date.today() | ||||||||||||||||
| rec.validity = (rec.date_deadline - fields.Date.today(create)).days | ||||||||||||||||
|
|
||||||||||||||||
| def action_accept(self): | ||||||||||||||||
| for offer in self: | ||||||||||||||||
| if offer.property_id.buyer_id: | ||||||||||||||||
| raise UserError('Only one offer can be accepted for a property.') | ||||||||||||||||
| offer.status = 'accepted' | ||||||||||||||||
| offer.property_id.selling_price = offer.price | ||||||||||||||||
| offer.property_id.buyer_id = offer.partner_id | ||||||||||||||||
| return True | ||||||||||||||||
|
|
||||||||||||||||
| def action_refuse(self): | ||||||||||||||||
| for offer in self: | ||||||||||||||||
| offer.status = 'refused' | ||||||||||||||||
| return True | ||||||||||||||||
|
|
||||||||||||||||
| _offer_price = models.Constraint( | ||||||||||||||||
|
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. It is good to declare constraint after the immediate declaration of all fields. |
||||||||||||||||
| 'CHECK (price > 0)', | ||||||||||||||||
| 'Offer price must be greater than 0', | ||||||||||||||||
| ) | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Real Estate Property Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| 'unique(name)', | ||
| 'The tag name must be unique.', | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Real Estate Property Type" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| 'unique(name)', | ||
| 'The property type name must be unique.', | ||
| ) |
| 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_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type_user,access_estate_property_type_user,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag_user,access_estate_property_tag_user,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer_user,access_estate_property_offer_user,model_estate_property_offer,base.group_user,1,1,1,1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <odoo> | ||
| <menuitem id="menu_estate_root" name="Real Estate"/> | ||
| <menuitem id="menu_estate_advertisements" name="Advertisements" parent="menu_estate_root" sequence="10"/> | ||
| <menuitem id="menu_estate_properties" name="Properties" parent="menu_estate_advertisements" action="action_estate_property" sequence="10"/> | ||
|
|
||
| <menuitem id="menu_estate_settings" name="Settings" parent="menu_estate_root" sequence="20"/> | ||
|
|
||
| <menuitem id="menu_estate_property_types" name="Property Types" | ||
| parent="menu_estate_settings" | ||
| action="action_estate_property_type" | ||
| sequence="10"/> | ||
|
|
||
| <menuitem id="menu_estate_property_tags" name="Property Tags" | ||
| parent="menu_estate_settings" | ||
| action="action_estate_property_tag"/> | ||
|
Comment on lines
+2
to
+15
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 issue and empty line before . if you want to leave an empty line, then you should follow the same for others too. |
||
| </odoo> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <odoo> | ||
| <record id="view_estate_property_offer_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.list</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Offers"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept" string="Accept" type="object" icon="fa-check"/> | ||
| <button name="action_refuse" string="Refuse" type="object" icon="fa-close" /> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="view_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 string="Offer"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <field name="status"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <odoo> | ||
| <record id="action_estate_property_tag" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| <field name="help" type="html"> | ||
| <p>Create and manage tags for your properties.</p> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <odoo> | ||
| <record id="action_estate_property_type" model="ir.actions.act_window"> | ||
| <field name="name">Property Types</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| </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 adapt this -> #1049 (comment)