-
Notifications
You must be signed in to change notification settings - Fork 3.2k
chean - Technical Onboarding #1341
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
anchevalier
wants to merge
1
commit into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-onboarding-chean
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
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,15 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "depends": ["base"], | ||
| "application": True, | ||
| "installable": True, | ||
| "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/estate_menus.xml", | ||
| "views/res_users_views.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,5 @@ | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_property_type | ||
| from . import estate_property | ||
| from . import res_user |
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,164 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| 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 = "Estate Property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(string="Title", required=True) | ||
| active = fields.Boolean(default=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char(string="Postcode") | ||
| date_availability = fields.Date( | ||
| string="Available From", | ||
| copy=False, | ||
| default=lambda self: fields.Date.today() + relativedelta(months=3), | ||
| ) | ||
| expected_price = fields.Float(string="Expected Price", required=True) | ||
| selling_price = fields.Float( | ||
| string="Selling Price", | ||
| readonly=True, | ||
| copy=False, | ||
| ) | ||
| bedrooms = fields.Integer(string="Bedrooms", default=2) | ||
| living_area = fields.Integer(string="Living Area (sqm)") | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection( | ||
| string="Garden Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| state = fields.Selection( | ||
| string="State", | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("canceled", "Canceled"), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default="new", | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| comodel_name="estate.property.type", | ||
| string="Property Type", | ||
| ) | ||
| salesman_id = fields.Many2one( | ||
| comodel_name="res.users", | ||
| string="Salesman", | ||
| default=lambda self: self.env.user, | ||
| ) | ||
| buyer_id = fields.Many2one( | ||
| comodel_name="res.partner", | ||
| string="Buyer", | ||
| readonly=True, | ||
| copy=False, | ||
| ) | ||
| tag_ids = fields.Many2many( | ||
| comodel_name="estate.property.tag", | ||
| string="Tags", | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| comodel_name="estate.property.offer", | ||
| inverse_name="property_id", | ||
| string="Offers", | ||
| ) | ||
| total_area = fields.Integer( | ||
| string="Total Area (sqm)", | ||
| compute="_compute_total_area", | ||
| ) | ||
| best_price = fields.Float( | ||
| string="Best Offer", | ||
| compute="_compute_best_price", | ||
| ) | ||
|
|
||
| _check_expected_price_positive = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "A property expected price should be strictly positive.", | ||
| ) | ||
| _check_selling_price_positive = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "A property selling price should be positive.", | ||
| ) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for property_ in self: | ||
| property_.total_area = property_.living_area + property_.garden_area | ||
|
|
||
| @api.depends("offer_ids.price") | ||
| def _compute_best_price(self): | ||
| for property_ in self: | ||
| property_.best_price = max(property_.offer_ids.mapped("price"), default=0.0) | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def _check_selling_price(self): | ||
| for property_ in self: | ||
| if float_is_zero(property_.selling_price, precision_digits=2): | ||
| continue | ||
|
|
||
| minimum_price = property_.expected_price * 0.9 | ||
| if ( | ||
| float_compare( | ||
| property_.selling_price, | ||
| minimum_price, | ||
| precision_digits=2, | ||
| ) | ||
| < 0 | ||
| ): | ||
| raise ValidationError( | ||
| self.env._( | ||
| "The selling price must be at least 90%% of the expected " | ||
| "price. You must reduce the expected price if you want to " | ||
| "accept this offer." | ||
| ) | ||
| ) | ||
|
|
||
| @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 | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _prevent_unlink_not_new_or_canceled(self): | ||
| for property_ in self: | ||
| if property_.state not in ("new", "canceled"): | ||
| raise UserError( | ||
| self.env._("Only new or canceled properties can be deleted.") | ||
| ) | ||
|
|
||
| def action_sold(self): | ||
|
anchevalier marked this conversation as resolved.
|
||
| self.ensure_one() | ||
|
|
||
| if self.state == "canceled": | ||
| raise UserError(self.env._("Canceled properties cannot be sold.")) | ||
|
|
||
| self.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| self.ensure_one() | ||
|
|
||
| if self.state == "sold": | ||
| raise UserError(self.env._("Sold properties cannot be canceled.")) | ||
|
|
||
| self.state = "canceled" | ||
| return True | ||
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,113 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Estate Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float(string="Price") | ||
| validity = fields.Integer(string="Validity", default=7) | ||
| date_deadline = fields.Date( | ||
| string="Deadline Date", | ||
| compute="_compute_date_deadline", | ||
| inverse="_inverse_date_deadline", | ||
| ) | ||
| status = fields.Selection( | ||
| string="Status", | ||
| selection=[ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused"), | ||
| ], | ||
| copy=False, | ||
| ) | ||
| partner_id = fields.Many2one( | ||
| comodel_name="res.partner", | ||
| string="Partner", | ||
| required=True, | ||
| ) | ||
| property_id = fields.Many2one( | ||
| comodel_name="estate.property", | ||
| string="Property", | ||
| required=True, | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| string="Property Type", | ||
| related="property_id.property_type_id", | ||
| store=True, | ||
| ) | ||
|
|
||
| _check_price_positive = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "An offer price should be strictly positive.", | ||
| ) | ||
|
|
||
| @api.depends("create_date", "validity") | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| create_date = offer.create_date or fields.Datetime.now() | ||
| offer.date_deadline = create_date.date() + timedelta(days=offer.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for offer in self: | ||
| create_date = offer.create_date or fields.Datetime.now() | ||
| offer.validity = (offer.date_deadline - create_date.date()).days | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| properties = self.env["estate.property"].browse( | ||
| [vals["property_id"] for vals in vals_list] | ||
| ) | ||
|
|
||
| for vals in vals_list: | ||
| property = properties.browse(vals["property_id"]) | ||
|
|
||
| if property.state == "sold": | ||
| raise UserError( | ||
| self.env._("You can't create an offer for a sold property.") | ||
| ) | ||
|
|
||
| if vals["price"] < property.best_price: | ||
| raise UserError( | ||
| self.env._( | ||
| "You can't create an offer with a lower amount than an " | ||
| "existing offer." | ||
| ) | ||
| ) | ||
|
|
||
| property.state = "offer_received" | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| def action_accept_offer(self): | ||
| self.ensure_one() | ||
|
|
||
| if self.status == "accepted": | ||
| raise UserError(self.env._("You already accepted the offer.")) | ||
|
|
||
| if self.property_id.buyer_id: | ||
| raise UserError(self.env._("Only one offer can be accepted.")) | ||
|
|
||
| self.status = "accepted" | ||
| self.property_id.selling_price = self.price | ||
| self.property_id.buyer_id = self.partner_id | ||
| self.property_id.state = "offer_accepted" | ||
| self.property_id.offer_ids.filtered(lambda offer: offer != self).status = ( | ||
| "refused" | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
| def action_refuse_offer(self): | ||
| self.ensure_one() | ||
|
|
||
| if self.status == "accepted": | ||
| raise UserError( | ||
| self.env._("You cannot refuse an offer once it has been accepted.") | ||
| ) | ||
|
|
||
| self.status = "refused" | ||
| return True | ||
|
anchevalier marked this conversation as resolved.
|
||
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,15 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer(string="Color") | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "A property tag name should be unique.", | ||
| ) |
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,31 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer() | ||
| property_ids = fields.One2many( | ||
| comodel_name="estate.property", | ||
| inverse_name="property_type_id", | ||
| string="Properties", | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| comodel_name="estate.property.offer", | ||
| inverse_name="property_type_id", | ||
| string="Offers", | ||
| ) | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "A property type name should be unique.", | ||
| ) | ||
|
|
||
| @api.depends("offer_ids") | ||
| def _compute_offer_count(self): | ||
| for property_type in self: | ||
| property_type.offer_count = len(property_type.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,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| comodel_name="estate.property", | ||
| inverse_name="salesman_id", | ||
| domain=[("state", "in", ["new", "offer_received"])], | ||
| string="Real Estate Properties", | ||
| ) |
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,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 | ||
|
anchevalier marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.