-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[ADD] estate: init commit for estate module #1027
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
48b008c
793dd90
89f139a
6e16ab7
7de91aa
8a7f9f0
bad6fa4
a6e8cf1
331420f
566aad6
a5cf231
a8c1bd4
1b7200e
7758b15
4f64cde
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,22 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'description': 'Real Estate !', | ||
| 'version': '1.0', | ||
| 'summary': 'Track Real Estate', | ||
| 'website': 'https://www.odoo.com/app/realestate', | ||
| 'author': 'Odoo S.A.', | ||
| 'application': True, | ||
| 'license': 'LGPL-3', | ||
| 'depends': ['base'], | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_list.xml', | ||
| 'views/estate_view_form.xml', | ||
| 'views/estate_view_search.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| } | ||
| 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,97 @@ | ||||||||
| from datetime import date | ||||||||
| from dateutil.relativedelta import relativedelta | ||||||||
| from odoo.exceptions import UserError | ||||||||
| from odoo import api, fields, models | ||||||||
|
|
||||||||
|
|
||||||||
| class EstateProperty(models.Model): | ||||||||
| _name = "estate.property" | ||||||||
| _description = "Estate property" | ||||||||
| _order = "" | ||||||||
|
|
||||||||
| name = fields.Text('Title', required=True) | ||||||||
| description = fields.Text('Description') | ||||||||
| post_code = fields.Char('Postcode') | ||||||||
| date_availability = fields.Date( | ||||||||
| 'Available From', | ||||||||
| copy=False, | ||||||||
| default=lambda self: 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( | ||||||||
| selection=[ | ||||||||
| ('north', 'North'), | ||||||||
| ('south', 'South'), | ||||||||
| ('east', 'East'), | ||||||||
| ('west', 'West'), | ||||||||
| ], | ||||||||
| string='Garden Orientation', | ||||||||
| ) | ||||||||
| state = fields.Selection( | ||||||||
| selection=[ | ||||||||
| ('new', 'New'), | ||||||||
| ('offer', 'Offer'), | ||||||||
| ('received', 'Received'), | ||||||||
| ('offer_accepted', 'Offer Accepted'), | ||||||||
| ('sold', 'Sold'), | ||||||||
| ('cancelled', 'Cancelled'), | ||||||||
| ], | ||||||||
| string='State', | ||||||||
| default='new', | ||||||||
| required=True, | ||||||||
| copy=False, | ||||||||
| ) | ||||||||
| active = fields.Boolean('Active', default=True) | ||||||||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||||||||
| user_id = fields.Many2one( | ||||||||
| 'res.users', string='Salesman', default=lambda self: self.env.user | ||||||||
| ) | ||||||||
| buyer_id = fields.Many2one("res.partner", string="Buyer", readonly=True, copy=False) | ||||||||
| tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||||||||
| offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||||||||
| total_area = fields.Integer("Total Area (sqm)", compute="_compute_total_area") | ||||||||
| best_price = fields.Float( | ||||||||
| "Best Offer", compute="_compute_best_price", readonly=True | ||||||||
| ) | ||||||||
|
|
||||||||
| @api.depends('living_area', 'garden_area') | ||||||||
| def _compute_total_area(self): | ||||||||
| for rec in self: | ||||||||
| rec.total_area = (rec.living_area or 0) + (rec.garden_area or 0) | ||||||||
|
Comment on lines
+64
to
+67
Contributor
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. This compute is defined twice (see line 76). |
||||||||
|
|
||||||||
| @api.depends('offer_ids.price') | ||||||||
| def _compute_best_price(self): | ||||||||
| for rec in self: | ||||||||
| prices = rec.offer_ids.mapped('price') | ||||||||
| rec.best_price = max(prices) if prices else 0.0 | ||||||||
|
Contributor
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. That works, you can also do
Suggested change
|
||||||||
|
|
||||||||
| @api.depends("living_area", "garden_area") | ||||||||
| def _compute_total_area(self): | ||||||||
| for prop in self: | ||||||||
| prop.total_area = prop.living_area + prop.garden_area | ||||||||
|
|
||||||||
| @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_sold(self): | ||||||||
| if "cancelled" in self.mapped("state"): | ||||||||
|
Contributor
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 works but it's not super readable. I'd do:
Suggested change
|
||||||||
| raise UserError("Canceled property cannot be sold !") | ||||||||
| return self.write({"state": "sold"}) | ||||||||
|
Contributor
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
write doesn't return anything, and this notation also works, even if the recordset has many records. |
||||||||
|
|
||||||||
| def action_cancel(self): | ||||||||
| if "sold" in self.mapped("state"): | ||||||||
| raise UserError("Sold property cannot be canceled !") | ||||||||
| return self.write({"state": "cancelled"}) | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||
| from odoo import api, fields, models | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class EstatePropertyOffer(models.Model): | ||||||||||||||||||
| _name = "estate.property.offer" | ||||||||||||||||||
| _description = "Estate Property Offers" | ||||||||||||||||||
| _order = "price" | ||||||||||||||||||
|
|
||||||||||||||||||
| price = fields.Float("Price", required=True) | ||||||||||||||||||
| state = fields.Selection( | ||||||||||||||||||
| [('accepted', 'Accepted'), ('refused', 'Refused')], | ||||||||||||||||||
| string="Status", | ||||||||||||||||||
| default=False, | ||||||||||||||||||
| copy=False, | ||||||||||||||||||
| ) | ||||||||||||||||||
| partner_id = fields.Many2one("res.partner", string="Partner", required=True) | ||||||||||||||||||
| property_id = fields.Many2one("estate.property", string="Property", required=True) | ||||||||||||||||||
| validity = fields.Integer("Validity (days)", default=7) | ||||||||||||||||||
| date_deadline = fields.Date( | ||||||||||||||||||
| "Deadline", compute="_compute_date_deadline", store=True | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| @api.depends('validity') | ||||||||||||||||||
| def _compute_date_deadline(self): | ||||||||||||||||||
| for offer in self: | ||||||||||||||||||
| if offer._origin.validity: | ||||||||||||||||||
|
Contributor
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
validity will always be set, worst case to 0 so this if...else can be avoided. |
||||||||||||||||||
| offer.date_deadline = fields.Date.add( | ||||||||||||||||||
| offer.create_date.date(), days=offer.validity | ||||||||||||||||||
| ) | ||||||||||||||||||
| else: | ||||||||||||||||||
| offer.date_deadline = False | ||||||||||||||||||
|
|
||||||||||||||||||
| def action_accept(self): | ||||||||||||||||||
| for offer in self: | ||||||||||||||||||
| offer.state = 'accepted' | ||||||||||||||||||
| offer.property_id.selling_price = offer.price | ||||||||||||||||||
| offer.property_id.buyer_id = offer.partner_id.id | ||||||||||||||||||
| offer.property_id.state = 'offer_accepted' | ||||||||||||||||||
|
Comment on lines
+36
to
+38
Contributor
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
It's better to do those three "write" in one :) |
||||||||||||||||||
| other_offers = offer.property_id.offer_ids.filtered( | ||||||||||||||||||
| lambda o: o.id != offer.id and o.state != 'refused' | ||||||||||||||||||
| ) | ||||||||||||||||||
| other_offers.state = 'refused' | ||||||||||||||||||
| return True | ||||||||||||||||||
|
|
||||||||||||||||||
| def action_refuse(self): | ||||||||||||||||||
| for offer in self: | ||||||||||||||||||
| offer.state = 'refused' | ||||||||||||||||||
| return True | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char("Name", required=True) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char("Name", required=True) | ||
| sequence = fields.Integer("Sequence") | ||
| property_ids = fields.One2many( | ||
| "estate.property", "property_type_id", string="Properties" | ||
| ) | ||
| offer_count = fields.Integer(string="Offers count", compute="_compute_offer") |
|
Contributor
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. This should be in a folder named |
| 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 | ||
|
Contributor
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. EOL missing at the end of the file. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <odoo> | ||
| <record id="view_property_tree" model="ir.ui.view"> | ||
| <field name="name">Estate Property Tree</field> | ||
| <field name="model">estate.property</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Estate Properties"> | ||
| <field name="name"/> | ||
| <field name="tag_ids" widget="many2many_tags"/> | ||
| <field name="post_code"/> | ||
| <field name="bedrooms"/> | ||
| <field name="living_area"/> | ||
| <field name="expected_price"/> | ||
| <field name="selling_price"/> | ||
| <field name="date_availability"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> | ||
|
Contributor
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. EOL |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_menu_advertisements" name="Advertisements"> | ||
| <menuitem id="estate_property_menu_action" name="Properties" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_menu_settings" name="Settings"> | ||
| <menuitem id="estate_property_type_menu_action" name="Property Types" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tag_menu_action" name="Property Tags" action="estate_property_tag_action" /> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> | ||
|
Contributor
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. EOL |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <odoo> | ||
| <record id="view_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="Property Offer"> | ||
| <sheet> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="status"/> | ||
| </group> | ||
| <group> | ||
| <field name="partner_id"/> | ||
| <field name="property_id"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">tree,form</field> | ||
| </record> | ||
| </odoo> | ||
|
Contributor
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. EOL |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <odoo> | ||
| <record id="estate_property_offer_view_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="Property Offer"> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="state"/> | ||
| </group> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| <!-- Add the buttons ‘Accept’ and ‘Refuse’ to the estate.property.offer model. --> | ||
| <record id="estate_property_offer_view_tree" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.tree</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Offers"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="state"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept" type="object" icon="fa-check" title="Accept" | ||
| /> | ||
| <button name="action_refuse" type="object" icon="fa-times" title="Accept" | ||
| /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <odoo> | ||
| <record id="estate_property_tag_view_tree" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.tree</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Tags" editable="bottom"> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_action" 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> | ||
| </record> | ||
|
|
||
| </odoo> | ||
|
Contributor
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. EOL |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <odoo> | ||
| <record id="view_property_type_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.list</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <list> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="view_property_type_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.form</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <form> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_action" 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <odoo> | ||
| <record id="view_property_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.list</field> | ||
| <field name="model">estate.property</field> | ||
| <field name="arch" type="xml"> | ||
| <list> | ||
| <field name="name"/> | ||
| <field name="property_type_id"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_action" model="ir.actions.act_window"> | ||
| <field name="name">Properties</field> | ||
| <field name="res_model">estate.property</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.
You probably want to have application=True for this module. See the manifest reference.