Skip to content
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

Open
wants to merge 25 commits into
base: 18.0
Choose a base branch
from

Conversation

romaincarlier4
Copy link

No description provided.

@robodoo
Copy link

robodoo commented Dec 16, 2024

Pull request status dashboard

Copy link

@kfr-odoo kfr-odoo left a 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).

@@ -0,0 +1 @@
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer

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

Comment on lines 55 to 61
@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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods after fields

Suggested change
@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

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

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

Suggested change
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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: shorter syntax

Suggested change
create_date = record.create_date if record.create_date else date.today()
create_date = record.create_date or date.today()

Comment on lines 48 to 53
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.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.")

Comment on lines 60 to 68
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 103 to 106
if any(
record.state in ("offer_received", "offer_accepted", "sold")
for record in self
):

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

Suggested change
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")):

Comment on lines 46 to 48
self.env["estate.property"].browse(
vals["property_id"]
).state = "offer_received"

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

Suggested change
self.env["estate.property"].browse(
vals["property_id"]
).state = "offer_received"
self.env["estate.property"].browse(
vals["property_id"]
).exists().state = "offer_received"

Copy link
Author

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 ?

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):

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

Comment on lines 19 to 20
if (this.props.onChange) {
this.props.onChange();

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

Suggested change
if (this.props.onChange) {
this.props.onChange();
this.props.onChange?.();

Copy link
Author

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"])

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 )

Suggested change
property_model = self.env["estate.property"].browse(vals["property_id"])
EstateProperty = self.env["estate.property"]
property = EstateProperty.browse(vals["property_id"])

@classmethod
def setUpClass(cls):

super(EstateTestCase, cls).setUpClass()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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";

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants