-
Notifications
You must be signed in to change notification settings - Fork 3.1k
sever - Technical Training #1235
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
SebVrc
wants to merge
4
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-sever
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
4 commits
Select commit
Hold shift + click to select a range
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,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.card"; | ||
| static props = { | ||
| title: String, | ||
| content: String, | ||
| } | ||
| } |
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,14 @@ | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_owl.card"> | ||
| <div class="card d-inline-block m-2" style="width: 18rem;"> | ||
| <div class="card-body"> | ||
| <h5 class="card-title"> | ||
| <t t-out="props.title"/> | ||
| </h5> | ||
| <p class="card-text"> | ||
| <t t-out="props.content"/> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </t> | ||
| </templates> |
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 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
| export class Counter extends Component { | ||
| static template = "awesome_owl.counter"; | ||
|
|
||
| setup() { | ||
| this.state = useState({ value: 0}); | ||
| } | ||
|
|
||
| increment() { | ||
| this.state.value++; | ||
| } | ||
| } |
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,8 @@ | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="awesome_owl.counter"> | ||
| Component Counter: <t t-esc="state.value"/> | ||
| <button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
| </t> | ||
|
|
||
| </templates> |
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 |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { Component, markup, useState } from "@odoo/owl"; | ||
| import { Counter } from "./counter/counter"; | ||
| import { Card } from "./card/card" | ||
|
|
||
| export class Playground extends Component { | ||
| static template = "awesome_owl.playground"; | ||
| static components = { Counter, Card }; | ||
|
|
||
| setup() { | ||
| this.state = useState({ value: 0}); | ||
| this.str1 = "<div class='text-primary'>some content</div>"; | ||
| this.str2 = markup("<div class='text-primary'>some content</div>"); | ||
| } | ||
|
|
||
| increment() { | ||
| this.state.value++; | ||
| } | ||
| } |
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
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,18 @@ | ||
| { | ||
| "name": "Estate", | ||
| "author": "sever", | ||
| "depends": [ | ||
| "base", | ||
| ], | ||
| "application": True, | ||
| "license": "LGPL-3", | ||
| "data": [ | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_users_view.xml", | ||
| "views/estate_menus.xml", | ||
| "security/ir.model.access.csv", | ||
| ], | ||
| } |
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 # noqa: I001 | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import user_property |
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,110 @@ | ||
| 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 Module" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| default=fields.Date.add(fields.Date.today(), months=3), | ||
| copy=False, | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True, copy=False) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_areas = fields.Integer() | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection( | ||
| [("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| [ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| required=True, | ||
| copy=False, | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type") | ||
| buyer_id = fields.Many2one("res.partner", copy=False) | ||
| seller_id = fields.Many2one("res.users", default=lambda self: self.env.user) | ||
| property_tag_ids = fields.Many2many("estate.property.tag") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id") | ||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Float(compute="_compute_best_price") | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "The expected price must be strictly positive.", | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "The selling price must be positive", | ||
| ) | ||
|
|
||
| @api.depends("living_areas", "garden_area") | ||
| def _compute_total_area(self): | ||
| for property in self: | ||
| property.total_area = property.garden_area + property.living_areas | ||
|
|
||
| @api.depends("offer_ids.price") | ||
| def _compute_best_price(self): | ||
| for property in self: | ||
| property.best_price = ( | ||
| max(property.offer_ids.mapped("price")) if len(property.offer_ids) > 0 else 0 | ||
| ) | ||
|
|
||
| @api.constrains("expected_price", "selling_price") | ||
| def _check_selling_price(self): | ||
| for property in self: | ||
| too_low = float_compare(property.selling_price, 0.9 * property.expected_price, 3) == -1 | ||
| if not float_is_zero(property.selling_price, 3) and too_low: | ||
| msg = "The selling price cannot be lower than 90 percents of the expected price." | ||
| raise ValidationError(msg) | ||
|
|
||
| @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 | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled_property(self): | ||
| for property in self: | ||
| if property.state != "new" and property.state != "cancelled": | ||
| msg = "Only new or cancelled properties can be deleted" | ||
| raise UserError(msg) | ||
| return super().unlink() | ||
|
|
||
| def action_sold_property(self): | ||
| for property in self: | ||
| if property.state == "cancelled": | ||
| msg = "Sold properties cannot be cancelled" | ||
| raise UserError(msg) | ||
| property.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel_property(self): | ||
| for property in self: | ||
| if property.state == "sold": | ||
| msg = "Cancelled properties cannot be sold" | ||
| raise UserError(msg) | ||
| property.state = "cancelled" | ||
| 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,79 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Estate Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| 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", | ||
| ) | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", | ||
| "The offer price must be strictly positive", | ||
| ) | ||
|
|
||
| @api.depends("validity") | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| if offer.create_date: | ||
| offer.date_deadline = fields.Date.add( | ||
| offer.create_date, | ||
| days=offer.validity, | ||
| ) | ||
| else: | ||
| offer.date_deadline = fields.Date.add( | ||
| fields.Date.today(), | ||
| days=offer.validity, | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for offer in self: | ||
| if offer.create_date: | ||
| offer.validity = int((offer.date_deadline - offer.create_date.date()).days) | ||
| else: | ||
| offer.validity = int((offer.date_deadline - fields.Date.today()).days) | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals): | ||
| for offer in vals: | ||
| linked_property = self.env["estate.property"].browse(offer["property_id"]) | ||
|
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. Avoid making search and browse calls on each iteration of the loop (this is quite important as it could cause performance issues). Batching the search and filtering inside the loop for the relevant results could be a better approach for that. |
||
| if float_compare(offer["price"], linked_property.best_price, 3) == -1: | ||
| msg = "Offer price cannot be lower than an existing offer" | ||
| raise ValidationError(msg) | ||
| linked_property.state = "offer_received" | ||
| return super().create(vals) | ||
|
|
||
| @api.constrains("status", "property_id") | ||
| def _check_south_facing_garden_accept_offer(self): | ||
| for offer in self: | ||
| price_below_expected = float_compare(offer.price, offer.property_id.expected_price, 3) == -1 | ||
| if offer.status == "accepted" and offer.property_id.garden_orientation == "south" and price_below_expected: | ||
| msg = "Offers for properties with south facing garden can only be accepted if the price of the offer is above the expected price of the property" | ||
| raise ValidationError(msg) | ||
|
|
||
| def action_accept_offer(self): | ||
| for offer in self: | ||
| offer.status = "accepted" | ||
| offer.property_id.selling_price = offer.price | ||
| offer.property_id.buyer_id = offer.partner_id | ||
| offer.property_id.state = "offer_accepted" | ||
| return True | ||
|
|
||
| def action_refuse_offer(self): | ||
| for offer in self: | ||
| offer.status = "refused" | ||
| 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,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() | ||
|
|
||
| _check_name_unique = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "The tag name must 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,16 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many("estate.property", "property_type_id") | ||
| sequence = fields.Integer("Sequence", default=1) | ||
|
|
||
| _check_name_unique = models.Constraint( | ||
| "UNIQUE(name)", | ||
| "The type name must 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,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class UserProperties(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| property_ids = fields.One2many( | ||
| "estate.property", "seller_id", domain=[('state', '=', '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,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 |
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 test_estate_property |
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.
You don't need the
super().unlink()with theondeletedecorator