dalio - Technical Training#1233
Conversation
6d29bbd to
d9454fb
Compare
Mathilde411
left a comment
There was a problem hiding this comment.
Very solid PR.
Also be careful of usage of ' vs ". You should use a convention and stick to it.
Most R&D teams use ' :)
Mathilde411
left a comment
There was a problem hiding this comment.
Very good, I don't have a lot to say :D
2409a9d to
1338c5c
Compare
Mathilde411
left a comment
There was a problem hiding this comment.
Good job !
Fix those last few things and you'll be good to go !
| expected_price = fields.Monetary(currency_field="currency_id", required=True) | ||
| selling_price = fields.Monetary(currency_field="currency_id", readonly=True, copy=False) |
There was a problem hiding this comment.
Default currency_field should already be currency_id here, so no need to add it
| @api.ondelete(at_uninstall=False) | ||
| def _check_state_before_deletion(self): | ||
| for record in self: | ||
| if record.state not in ["new", "canceled"]: |
There was a problem hiding this comment.
Thre is a typo on "cancelled" here, won't work
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == "cancelled": | ||
| raise UserError("Canceled properties cannot be sold.") | ||
| record.state = "sold" | ||
| return True |
There was a problem hiding this comment.
| def action_sold(self): | |
| for record in self: | |
| if record.state == "cancelled": | |
| raise UserError("Canceled properties cannot be sold.") | |
| record.state = "sold" | |
| return True | |
| def action_sold(self): | |
| for record in self: | |
| if record.state == "cancelled": | |
| raise UserError("Canceled properties cannot be sold.") | |
| self.state = "sold" | |
| return True |
Only one assignation for the whole recordset
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == "sold": | ||
| raise UserError("Sold properties cannot be canceled.") | ||
| record.state = "cancelled" | ||
| return True |
|
|
||
| price = fields.Monetary(currency_field="currency_id") | ||
| status = fields.Selection( | ||
| string="Status", |
| @api.model | ||
| def create(self, vals_list): | ||
|
|
||
| for vals in vals_list: | ||
| prop = self.env["estate.property"].browse(vals.get("property_id")) | ||
| existing_prices = prop.offer_ids.mapped("price") | ||
|
|
||
| if existing_prices and vals.get("price") < max(existing_prices): | ||
| raise UserError(f"The offer must be higher than {max(existing_prices):.2f}") | ||
|
|
||
| prop.state = "offer_received" | ||
|
|
||
| return super().create(vals_list) |
There was a problem hiding this comment.
Browse in a loop is a performance killer it should never happen. Basically if you have a recordset of all the properties and you fetch a field for one of them, the ORM is going to fetch it for all and cache them so that next iteration of the loop, you have them ready. But there since you have a different recordset for every iteration of the loop, the ORM can't do this optimization and you'll end up with one request per iteration which is very not good.
| @api.model | |
| def create(self, vals_list): | |
| for vals in vals_list: | |
| prop = self.env["estate.property"].browse(vals.get("property_id")) | |
| existing_prices = prop.offer_ids.mapped("price") | |
| if existing_prices and vals.get("price") < max(existing_prices): | |
| raise UserError(f"The offer must be higher than {max(existing_prices):.2f}") | |
| prop.state = "offer_received" | |
| return super().create(vals_list) | |
| @api.model | |
| def create(self, vals_list): | |
| #do a search/browse here | |
| for vals in vals_list: # <- etract it by **zip**ing the vals_list with the recordset :) | |
| existing_prices = prop.offer_ids.mapped("price") | |
| if existing_prices and vals.get("price") < max(existing_prices): | |
| raise UserError(f"The offer must be higher than {max(existing_prices):.2f}") | |
| prop.state = "offer_received" | |
| return super().create(vals_list) |
|
|
||
| _name = "estate.property.type" | ||
| _description = "Property Type" | ||
| _order = "name" |
There was a problem hiding this comment.
You added a sequence to order the stages but the order here was not updated
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") |
| property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") | ||
|
|
||
| offer_count = fields.Integer(compute="_compute_offer_count", string="Offer Count") |
| "account", | ||
| ], | ||
| "data": [], | ||
| "application": False, |
There was a problem hiding this comment.
Application's default is False, you don't need it.
My first squash commit
This commit is here to introduce the testing framework of Odoo. Try running the tests using `--test-tags :TestEstateProperty`. Doc: https://www.odoo.com/documentation/18.0/developer/reference/backend/testing.html?highlight=tests#invocation The tests were made such that the first one should work but the second one should fail. Your job is to ensure both tests pass in the end. You should update the behaviour of the appropriate models. If you want, you can also add a small test of your own to get a feel for it.
5b2c1b2 to
e5ac3b6
Compare

No description provided.