-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ADD] estate: create initial module structure and manifest #1416
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
55b2599
3e53ed6
8e7aed2
9f2dbc6
32a2e25
af5fe3c
74647bf
8a0878c
c292f36
94e7959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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,16 @@ | ||
| # __manifest__.py | ||
| { # noqa: B018 | ||
| "author": "Odoo S.A.", | ||
| "name": "estate", | ||
| "depends": ["base"], | ||
| "application": True, | ||
| "license": "LGPL-3", | ||
| "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" | ||
| ], | ||
| } |
| 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,102 @@ | ||||||||||||||||||||||||||||
| from odoo.tools.date_utils import add | ||||||||||||||||||||||||||||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||||||||||||||||||||||||||||
| from odoo.exceptions import UserError, ValidationError | ||||||||||||||||||||||||||||
| from odoo import api, fields, models | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class EstateProperty(models.Model): | ||||||||||||||||||||||||||||
| _name = "estate.property" | ||||||||||||||||||||||||||||
| _description = "Estate property model" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| active = fields.Boolean('Active', default=True) | ||||||||||||||||||||||||||||
| state = fields.Selection([ | ||||||||||||||||||||||||||||
| ('new', 'New'), | ||||||||||||||||||||||||||||
| ('offer_received', 'Offer Received'), | ||||||||||||||||||||||||||||
| ('offer_accepted', 'Offer Accepted'), | ||||||||||||||||||||||||||||
| ('sold', 'Sold'), | ||||||||||||||||||||||||||||
| ('cancelled', 'Cancelled') | ||||||||||||||||||||||||||||
| ], string='Status', default='new', required=True, copy=False) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| name = fields.Char(required=True) | ||||||||||||||||||||||||||||
| description = fields.Text() | ||||||||||||||||||||||||||||
| postcode = fields.Char() | ||||||||||||||||||||||||||||
| date_availability = fields.Date(copy=False, default=lambda self: add(fields.Date.today(), months=3), string="Available From") | ||||||||||||||||||||||||||||
| expected_price = fields.Float(required=True) | ||||||||||||||||||||||||||||
| selling_price = fields.Float(readonly=True, copy=False) | ||||||||||||||||||||||||||||
| bedrooms = fields.Integer(default=2) | ||||||||||||||||||||||||||||
| living_area = fields.Integer(string="Living Area (sqm)") | ||||||||||||||||||||||||||||
| facades = fields.Integer() | ||||||||||||||||||||||||||||
| has_garage = fields.Boolean() | ||||||||||||||||||||||||||||
| has_garden = fields.Boolean() | ||||||||||||||||||||||||||||
| garden_area = fields.Integer(string="Garden Area (sqm)") | ||||||||||||||||||||||||||||
| garden_orientation = fields.Selection( | ||||||||||||||||||||||||||||
| string='Type', | ||||||||||||||||||||||||||||
| selection=[ | ||||||||||||||||||||||||||||
| ('north', 'North'), | ||||||||||||||||||||||||||||
| ('south', 'South'), | ||||||||||||||||||||||||||||
| ('east', 'East'), | ||||||||||||||||||||||||||||
| ('west', 'West') | ||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+40
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. Having the selection list in one line is okay but when we have such multiple values we style it like this.
Suggested change
|
||||||||||||||||||||||||||||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||||||||||||||||||||||||||||
|
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. stick to double quotes or single quotes :) |
||||||||||||||||||||||||||||
| buyer = fields.Many2one('res.partner', copy=False) | ||||||||||||||||||||||||||||
| salesperson = fields.Many2one('res.users', default=lambda self: self.env.user, string="Salesman") | ||||||||||||||||||||||||||||
| tag_ids = fields.Many2many('estate.property.tag') | ||||||||||||||||||||||||||||
| offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") | ||||||||||||||||||||||||||||
| total_area = fields.Integer(compute="_compute_total_area", string="Total Area (sqm)") | ||||||||||||||||||||||||||||
| best_price = fields.Float(compute="_compute_best_offer", string="Best Offer") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @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_offer(self): | ||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||
| prices = record.offer_ids.mapped("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. There will be an issue in case some properties don't have |
||||||||||||||||||||||||||||
| record.best_price = max(prices) if prices else 0.0 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @api.onchange("has_garden") | ||||||||||||||||||||||||||||
| def _onchange_has_garden(self): | ||||||||||||||||||||||||||||
| if self.has_garden: | ||||||||||||||||||||||||||||
| self.garden_area = 10 | ||||||||||||||||||||||||||||
| self.garden_orientation = "north" | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| self.garden_area = 0 | ||||||||||||||||||||||||||||
| self.garden_orientation = None | ||||||||||||||||||||||||||||
|
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. okay, we conventionally use |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def mark_order_as_sold(self): | ||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||
| if record.state == "cancelled": | ||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+71
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. When we can write logic on the whole recordset instead of looping over each record, we do that. It's better for reading and writing through the database. For example here you can check if any of |
||||||||||||||||||||||||||||
| raise UserError("Cancelled properties cannot be sold") | ||||||||||||||||||||||||||||
|
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. add this
Suggested change
|
||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| record.state = "sold" | ||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def mark_order_as_cancelled(self): | ||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||
| if record.state == "sold": | ||||||||||||||||||||||||||||
| raise UserError("Sold properties cannot be cancelled") | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| record.state = "cancelled" | ||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+83
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 comments apply here for recordset handling (instead of per record) and the translation thing :) |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @api.constrains("selling_price", "expected_price") | ||||||||||||||||||||||||||||
| def _check_selling_price(self): | ||||||||||||||||||||||||||||
| for record in self: | ||||||||||||||||||||||||||||
| if float_is_zero(record.selling_price, precision_digits=2): | ||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) < 0: | ||||||||||||||||||||||||||||
| raise ValidationError("The selling price must be at leat 90% of the expected price ! You must reduce the expected price if you want to accept this order !") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| _expected_price_strictly_positive_constraint = models.Constraint( | ||||||||||||||||||||||||||||
| "CHECK(expected_price > 0)", | ||||||||||||||||||||||||||||
| "The expected price should be strictly greater than 0!" | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| _selling_price_positive_constraint = models.Constraint( | ||||||||||||||||||||||||||||
| "CHECK(selling_price >= 0)", | ||||||||||||||||||||||||||||
| "The selling price should be greater or equal to 0!" | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||
| from odoo.tools.date_utils import add | ||||||||||||||||
| from odoo.exceptions import UserError | ||||||||||||||||
| from odoo import api, fields, models | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class EstatePropertyOffer(models.Model): | ||||||||||||||||
| _name = "estate.property.offer" | ||||||||||||||||
| _description = "Estate property offer model" | ||||||||||||||||
|
|
||||||||||||||||
| price = fields.Float() | ||||||||||||||||
| status = fields.Selection([ | ||||||||||||||||
| ('accepted', 'Accepted'), | ||||||||||||||||
| ('refused', 'Refused') | ||||||||||||||||
| ], copy=False) | ||||||||||||||||
| partner_id = fields.Many2one("res.partner", required=True, string="Partner") | ||||||||||||||||
| property_id = fields.Many2one("estate.property", required=True) | ||||||||||||||||
| validity = fields.Integer(default=7, string="Validity (days)") | ||||||||||||||||
| date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline") | ||||||||||||||||
|
|
||||||||||||||||
| @api.depends("create_date", "validity") | ||||||||||||||||
| def _compute_date_deadline(self): | ||||||||||||||||
| for record in self: | ||||||||||||||||
| base_date = record.create_date.date() if record.create_date else fields.Date.today() | ||||||||||||||||
| record.date_deadline = add(base_date, days=record.validity) | ||||||||||||||||
|
|
||||||||||||||||
| def _inverse_date_deadline(self): | ||||||||||||||||
| for record in self: | ||||||||||||||||
| base_date = record.create_date.date() if record.create_date else fields.Date.today() | ||||||||||||||||
| if record.date_deadline and base_date: | ||||||||||||||||
| record.validity = (record.date_deadline - base_date).days | ||||||||||||||||
|
|
||||||||||||||||
| def accept_offer(self): | ||||||||||||||||
| for record in self: | ||||||||||||||||
|
|
||||||||||||||||
| if record.status == "accepted": | ||||||||||||||||
| continue | ||||||||||||||||
|
|
||||||||||||||||
| accepted_offer = record.property_id.offer_ids.filtered(lambda offer: offer.status == "accepted") | ||||||||||||||||
| if accepted_offer: | ||||||||||||||||
| raise UserError("Only one offer can be accepted for a giver property !") | ||||||||||||||||
| else: | ||||||||||||||||
| record.status = "accepted" | ||||||||||||||||
| record.property_id.buyer = record.partner_id | ||||||||||||||||
| record.property_id.selling_price = record.price | ||||||||||||||||
|
Comment on lines
+41
to
+44
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. you can remove the else, the error raised if the condition is true will prevent the rest of the code from running
Suggested change
|
||||||||||||||||
| return True | ||||||||||||||||
|
|
||||||||||||||||
| def refuse_offer(self): | ||||||||||||||||
| for record in self: | ||||||||||||||||
| record.status = "refused" | ||||||||||||||||
|
Comment on lines
+48
to
+49
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. you can do |
||||||||||||||||
| return True | ||||||||||||||||
|
|
||||||||||||||||
| _offer_price_strictly_positive_constraint = models.Constraint( | ||||||||||||||||
| "CHECK(price > 0)", | ||||||||||||||||
| "The price of an offer should be strictly greater than 0!" | ||||||||||||||||
| ) | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate property tag model" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _property_tag_unique_constraint = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "Property tag should have an unique name!" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate property type model" | ||
|
|
||
| name = fields.Char(required=True) |
| 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,estate_property,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type,estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_advertisements_menu" name="Advertisements"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_settings_menu_type_action" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_settings_menu_tag_action" action="estate_property_tag_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
|
|
||
| </odoo> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?xml version="1.0"?> | ||
| <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"> | ||
| <header> | ||
| <button name="accept_offer" type="object" string="Accept"/> | ||
| <button name="refuse_offer" type="object" string="Refuse"/> | ||
| </header> | ||
| <sheet> | ||
| <h1> | ||
| <field name="property_id"/> | ||
| </h1> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <field name="status"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_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="Properties"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="accept_offer" type="object" title="Accept" icon="fa-check"/> | ||
| <button name="refuse_offer" type="object" title="Refuse" icon="fa-times"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </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.