-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ADD] estate: add estate module for tutoriel #1370
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
Open
jeanbfly
wants to merge
20
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutoriel-estate-jebou
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
23ccdb7
[ADD] estate: add estate module for tutoriel
7f39dc3
[ADD] estate: add access rights for estate model
6549326
[ADD] estate: add views and menus to estate model. Also change access…
44306a4
[ADD] estate: add basics views (form, search) to estate
dedcc8f
[ADD] estate: add property_tag, property_offer, property_type and the…
02cae9a
[LINT] estate: try to correct self_in_self rule
30e80c0
[LINT] estate: add author and license
5c17957
[IMP] estate: add sold, cancelled, accept, refuse buttons
fa7fdaa
[IMP] estate: add sql and python constrains to model
69c0938
[IMP] estate: add the sprinkles
98aecf6
[IMP] estate: correct error translations
a106d5c
[IMP] estate: add create handler
6e5e363
[IMP] estate: faster search with sql query
11dc21d
[IMP] estate: remove edge cases
da71d77
[IMP] estate: correct review comments
38c6cff
[IMP] estate: add inherited module from res.users
7b71900
[ADD] estate_account: add the estate_account module
33cf547
[IMP] estate: add kanban view for properties
4c5a4f2
[IMP] estate: check code guidelines
20dedd3
[IMP] estate: patch import issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "author": "Odoo S.A.", | ||
| "license": "LGPL-3", | ||
| "application": True, | ||
| "depends": ["base"], | ||
| "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_property_tag_views.xml", | ||
| "views/res_users_views.xml", | ||
| "views/estate_property_menus.xml", | ||
| ], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from . import ( | ||
| estate_property, | ||
| estate_property_offer, | ||
| estate_property_tag, | ||
| estate_property_type, | ||
| res_users, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Table for property test tutoriel" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char("Title", required=True, default="Unknown") | ||
| 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", | ||
| ) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| "Available From", | ||
| copy=False, | ||
| default=fields.Date.add(fields.Date.today(), months=3), | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price >= 0)", | ||
| "The price should be strictly positive", | ||
| ) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "The price should be strictly positive", | ||
| ) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer("Living Area (sqm)") | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer("Garden Area (sqm)") | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now) | ||
|
jeanbfly marked this conversation as resolved.
|
||
| 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, readonly=True) | ||
| tags_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", readonly=True) | ||
| best_price = fields.Float( | ||
| compute="_compute_best_price", | ||
| readonly=True, | ||
| string="Best Offer", | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _ondelete(self): | ||
| for record in self: | ||
| if record.state in ("new", "cancelled"): | ||
| raise UserError( | ||
| self.env._( | ||
| "You cannot delete a entry with a 'New' or 'Canceled' status.", | ||
| ), | ||
| ) | ||
|
|
||
| @api.onchange("garden") | ||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = "north" | ||
| return | ||
| self.garden_orientation = False | ||
| self.garden_area = 0 | ||
|
|
||
| @api.depends("offer_ids.price") | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| record.best_price = max(record.offer_ids.mapped("price"), default=0) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def _constrain_selling_price(self): | ||
| for record in self: | ||
| if ( | ||
| not float_is_zero(record.selling_price, 3) | ||
| and float_compare( | ||
| record.expected_price * 0.90, | ||
| record.selling_price, | ||
| 3, | ||
| ) | ||
| > 0 | ||
| ): | ||
| raise ValidationError( | ||
| self.env._( | ||
| "selling price should be at least 90 percent of the expected price", | ||
| ), | ||
| ) | ||
|
|
||
| def action_cancel(self): | ||
| if self.state == "sold": | ||
| raise UserError(self.env._("A sold property cannot be cancelled")) | ||
| self.state = "cancelled" | ||
|
|
||
| def action_sold(self): | ||
| if self.state == "cancelled": | ||
| raise UserError(self.env._("A cancelled property cannot be sold")) | ||
| self.state = "sold" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Table for offers of a property" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float("Price") | ||
| _check_price = models.Constraint( | ||
| "CHECK(price >= 0)", | ||
| "Le prix doit être strictement positif", | ||
| ) | ||
| status = fields.Selection( | ||
| string="Status", | ||
| copy=False, | ||
| selection=[("accepted", "Accepted"), ("refused", "Refused")], | ||
| ) | ||
| 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.Datetime( | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
| property_type_id = fields.Many2one(related="property_id.property_type_id") | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| property_id = vals.get("property_id") | ||
| price = vals.get("price", 0) | ||
|
|
||
| if not property_id: | ||
| continue | ||
|
|
||
| if self.env["estate.property.offer"].search_count( | ||
| [ | ||
| ("property_id", "=", property_id), | ||
| ( | ||
| "price", | ||
| ">", | ||
| price, | ||
| ), | ||
| ], | ||
| ): | ||
| raise UserError( | ||
| self.env._( | ||
| "You cannot create a offer with a lower price than a existing one for this property", | ||
| ), | ||
| ) | ||
|
|
||
| self.env["estate.property"].browse(property_id).state = "offer received" | ||
| return super().create(vals_list) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = fields.Datetime.add( | ||
| record.create_date.date() or fields.Datetime.now().date(), | ||
|
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. what if the |
||
| days=record.validity, | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date).days | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| record.property_id.offer_ids.status = "refused" | ||
| record.status = "accepted" | ||
| record.property_id.state = "offer accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| record.status = "refused" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Table for tags of a property" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| _check_name = models.Constraint("UNIQUE(name)", "Le nom du tag doit être unique") | ||
|
|
||
| color = fields.Integer("Color") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Table for type of property" | ||
| _order = "sequence" | ||
|
|
||
| name = fields.Char(required=True) | ||
| _check_name = models.Constraint("UNIQUE(name)", "Le nom du type doit être unique") | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "property_type_id", | ||
| string="Properties", | ||
| ) | ||
|
|
||
| sequence = fields.Integer( | ||
| "Sequence", | ||
| default=1, | ||
| help="Used to order stages. Lower is better.", | ||
| ) | ||
|
|
||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id") | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| domain="[('state', 'in', ['new', 'offer received'])]", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,estate.model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type,access.estate.property.type,estate.model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,access.estate.property.tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,access.estate.property.offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 | ||
| access_res_users,access.res.users,estate.model_res_users,base.group_user,1,1,1,1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <odoo> | ||
| <menuitem id="estate_property_menu" name="Real Estate"> | ||
| <menuitem id="estate_property_menu_advertisements" name="Advertisements"> | ||
| <menuitem id="estate_property_menu_action" action="estate_property_action_view" /> | ||
| </menuitem> | ||
| <menuitem id="estate_property_menu_settings" name="Settings"> | ||
| <menuitem id="estate_property_menu_property_types" | ||
| action="estate_property_type_action_view" /> | ||
| <menuitem id="estate_property_menu_property_tags" | ||
| action="estate_property_tag_action_view" /> | ||
| </menuitem> | ||
| </menuitem> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <odoo> | ||
| <record id="estate_property_offer_action_view" model="ir.actions.act_window"> | ||
| <field name="name">estate.property.offer.action.view</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.view.list</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <list editable="top" decoration-danger="status=='refused'" | ||
| decoration-success="status=='accepted'"> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <button name="action_accept" string="Accept" type="object" | ||
| icon="fa-check" invisible="status in ('accepted', 'refused')" /> | ||
| <button name="action_refuse" string="Refuse" type="object" | ||
| icon="fa-close" invisible="status in ('accepted', 'refused')" /> | ||
| <field name="status" /> | ||
| <field name="property_type_id" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <odoo> | ||
| <record id="estate_property_tag_action_view" model="ir.actions.act_window"> | ||
| <field name="name">estate.property.tag.main.action</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_list_view" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.list.view</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list editable="top"> | ||
| <field name="name" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| </odoo> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nitpick(feel free to ignore it for now): we usually do the imports as
from . import <model>