-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
romc - Technical Training #208
base: 18.0
Are you sure you want to change the base?
Conversation
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.
LGTM :)
- Configure your IDE to get ride of EOF issues. "Insert Final Newline" in VScode.
- Remove all
# -*- coding: utf-8 -*-
, they are not required anymore (since version 16.0).
estate/models/__init__.py
Outdated
@@ -0,0 +1 @@ | |||
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer |
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.
We usually split imports, one by line. Does not change much but it is good to stay consistent with the standard codebase
estate/models/estate_property.py
Outdated
@api.depends("garden_area", "living_area") | ||
def _compute_total_area(self): | ||
for record in self: | ||
record.total_area = record.garden_area + record.living_area | ||
|
||
best_price = fields.Float(compute="_compute_best_price") |
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.
Methods after fields
@api.depends("garden_area", "living_area") | |
def _compute_total_area(self): | |
for record in self: | |
record.total_area = record.garden_area + record.living_area | |
best_price = fields.Float(compute="_compute_best_price") | |
best_price = fields.Float(compute="_compute_best_price") | |
@api.depends("garden_area", "living_area") | |
def _compute_total_area(self): | |
for record in self: | |
record.total_area = record.garden_area + record.living_area |
estate/models/estate_property.py
Outdated
def _compute_best_price(self): | ||
for record in self: | ||
prices = record.offer_ids.mapped("price") | ||
record.best_price = max(prices) if len(prices) else 0 |
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.
Nitpicking, max() default param syntax is better than a ternary
record.best_price = max(prices) if len(prices) else 0 | |
record.best_price = max(prices, default=0) |
@api.depends("create_date", "validity") | ||
def _compute_date_deadline(self): | ||
for record in self: | ||
create_date = record.create_date if record.create_date else date.today() |
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.
Nitpicking: shorter syntax
create_date = record.create_date if record.create_date else date.today() | |
create_date = record.create_date or date.today() |
ce3c108
to
f107512
Compare
f107512
to
66a5c8d
Compare
other_records = self.search( | ||
[("id", "!=", str(self.id)), ("property_id", "=", self.property_id.id)] | ||
) | ||
for rec in other_records: | ||
if rec.status == "accepted": | ||
raise UserError("Cannot have more than one accepted offer.") |
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.
other_records = self.search( | |
[("id", "!=", str(self.id)), ("property_id", "=", self.property_id.id)] | |
) | |
for rec in other_records: | |
if rec.status == "accepted": | |
raise UserError("Cannot have more than one accepted offer.") | |
accepted_offers = self.search( | |
[("id", "!=", str(self.id)), ("property_id", "=", self.property_id.id), ("status", "=" "accepted")] | |
) | |
if accepted_offers: | |
raise UserError("Cannot have more than one accepted offer.") |
def action_refuse_offer(self): | ||
self.ensure_one() | ||
old_status = self.status | ||
self.status = "refused" | ||
if old_status == "accepted": | ||
self.property_id.buyer_id = "" | ||
self.property_id.selling_price = 0 | ||
self.property_id.state = "offer_received" | ||
return True |
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.
def action_refuse_offer(self): | |
self.ensure_one() | |
old_status = self.status | |
self.status = "refused" | |
if old_status == "accepted": | |
self.property_id.buyer_id = "" | |
self.property_id.selling_price = 0 | |
self.property_id.state = "offer_received" | |
return True | |
def action_refuse_offer(self): | |
self.ensure_one() | |
if self.status == "accepted": | |
self.property_id.buyer_id = "" | |
self.property_id.selling_price = 0 | |
self.property_id.state = "offer_received" | |
self.status = "refused" | |
return True |
e236c0f
to
63f631c
Compare
estate/models/estate_property.py
Outdated
if any( | ||
record.state in ("offer_received", "offer_accepted", "sold") | ||
for record in self | ||
): |
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.
There is a builtin for that
if any( | |
record.state in ("offer_received", "offer_accepted", "sold") | |
for record in self | |
): | |
if self.filtered(lambda property: property.state in ("offer_received", "offer_accepted", "sold")): |
self.env["estate.property"].browse( | ||
vals["property_id"] | ||
).state = "offer_received" |
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.
browse()
is unreliable and should always be suffixed by exists()
The point of this method is to create a recordset with some ids inside but it does not verify their existence
self.env["estate.property"].browse( | |
vals["property_id"] | |
).state = "offer_received" | |
self.env["estate.property"].browse( | |
vals["property_id"] | |
).exists().state = "offer_received" |
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.
It could be mentioned in the tutorial ?
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.
"Yes indeed, I'll make sure to mention it in the new tutorial" -ANV
self.env["estate.property"].browse( | ||
vals["property_id"] | ||
).state = "offer_received" | ||
if any(record.price > vals["price"] for record in all_offers): |
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 should only check offers for a given property right ? Not all offers of all the properties in the db
if (this.props.onChange) { | ||
this.props.onChange(); |
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.
It is surprising that this props may not exists. The best approach would be to figure out why it is not provided sometime, fix the issue and remove this if check.
If it is inevitable, here is an alternative syntax that you may (or not) want to use
if (this.props.onChange) { | |
this.props.onChange(); | |
this.props.onChange?.(); |
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.
This is what is expected. The counter component can optionnally have a callback prop, but can also very well be a simple counter with no callback needed. I changed with the better '?' syntax.
) | ||
|
||
property_offers = offers_per_property[vals["property_id"]] | ||
property_model = self.env["estate.property"].browse(vals["property_id"]) |
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.
Naming conventions used ( not necessary to split in two lines )
property_model = self.env["estate.property"].browse(vals["property_id"]) | |
EstateProperty = self.env["estate.property"] | |
property = EstateProperty.browse(vals["property_id"]) |
estate/tests/test_estate.py
Outdated
@classmethod | ||
def setUpClass(cls): | ||
|
||
super(EstateTestCase, cls).setUpClass() |
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.
super(EstateTestCase, cls).setUpClass() | |
super().setUpClass() |
import { DashboardItem } from "./dashboard_item"; | ||
import { PieChart } from "../piechart/piechart"; | ||
import { DashboardDialog } from "./dashboard_dialog"; | ||
import { browser } from "@web/core/browser/browser"; |
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.
Import organization could be improved
No description provided.