rohar - Technical Training#1242
Conversation
bcfd4ea to
a6d47e1
Compare
Mathilde411
left a comment
There was a problem hiding this comment.
Pretty good so far !
Runbot is green so good job !
Also would you be able to squash your commits so that you only have one per chapter ?
| @@ -0,0 +1,2 @@ | |||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | |||
| estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 No newline at end of file | |||
There was a problem hiding this comment.
| estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 | |
| estate_property_access_user,estate.property.user,model_estate_property,base.group_user,1,1,1,1 |
Comments for each column:
1st column is the XMLid of the access right, it should be <model_name>_access_<concerned_group> (similarly to record rules in https://www.odoo.com/documentation/19.0/contributing/development/coding_guidelines.html#xml-ids-and-naming)
second column is the name
2nd column is the name of the rule, the one that will be displayed in the ui, should say the model name and the targeted group (there is not really a fixed way, but a common one is with dots, like suggested)
3rd one is the xmlid of the model targeted, you don't need to add the module name in front if the xmlid is from the same module as you, same for 4th column that represents the targetted group
9687c2b to
31493f7
Compare
Mathilde411
left a comment
There was a problem hiding this comment.
Good job here !
Here are a few things that I'd have done another way :)
0af77d9 to
9013cee
Compare
9013cee to
7745737
Compare
Mathilde411
left a comment
There was a problem hiding this comment.
Oops forgot to submit it !
Pretty good overall !
Fix the last few points and you'll be good to go !
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", | ||
| "A property expected price must be stricly positive", | ||
| ) | ||
|
|
||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", | ||
| "A property selling price must be positive", | ||
| ) | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def check_selling_price(self): | ||
| for record in self: | ||
| if float_is_zero(record.selling_price, precision_digits=2): | ||
| return | ||
| if float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) == -1: | ||
| raise ValidationError("The selling price cannot be lower than 90% of the expected price.") | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| if any(not record.state in ("new", "cancelled") for record in self): | ||
| raise UserError("Can only delete an new or cancelled property.") |
There was a problem hiding this comment.
Be careful about attribute ordering
| ) | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def check_selling_price(self): |
There was a problem hiding this comment.
should be named '_check_selling_price'
| if float_is_zero(record.selling_price, precision_digits=2): | ||
| return |
| @api.model | ||
| def create(self, vals_list): | ||
| property = self.env["estate.property"].browse(vals_list[0]["property_id"]) | ||
| if max(property.offer_ids.mapped("price"), default=0.0) > vals_list[0]["price"]: | ||
| raise UserError("New offer must be higher than existing ones.") | ||
|
|
||
| property.state = "offer_received" | ||
|
|
||
| return super().create(vals_list) |
There was a problem hiding this comment.
What if I create multiple records ? (multiple values in vals_list) then only the first one would be checked
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| days = record.date_deadline - record.create_date.date() | ||
| record.validity = days.days | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| property_id = record.property_id | ||
| if property_id.state in ("sold", "accepted"): | ||
| raise UserError("A sold or cancelled property can't be sold.") | ||
|
|
||
| if (property_id.has_garden and property_id.garden_orientation == "south" and float_compare(record.price, property_id.expected_price, precision_digits=2) == -1): | ||
| raise ValidationError("The selling price cannot be lower than 90% of the expected price.") | ||
|
|
||
| record.status = "accepted" | ||
| property_id.state = "sold" | ||
| property_id.buyer_id = record.partner_id | ||
| property_id.selling_price = record.price | ||
|
|
||
| def action_refuse(self): | ||
| self.status = "refused" |
| estate_property_access_user,estate.property.user,model_estate_property,base.group_user,1,1,1,1 | ||
| estate_property_type_access_user,estate.property.type.user,model_estate_property_type,base.group_user,1,1,1,1 | ||
| estate_property_tag_access_user,estate.property.tag.user,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| estate_property_offer_acces_user,estate.property.offer.user,model_estate_property_offer,base.group_user,1,1,1,1 No newline at end of file |
| <field name="validity" optional="true"/> | ||
| <field name="date_deadline" optional="true"/> | ||
| <field name="property_type_id" optional="true"/> |
| from odoo import models | ||
|
|
||
|
|
||
| class EstateAccount(models.Model): | ||
| _name = "estate.account" | ||
| _description = "Real estate accounting" |
There was a problem hiding this comment.
You don't need a model here ? Why did you add it ?
| _name = "estate.property" | ||
| _inherit = ["estate.property"] |
There was a problem hiding this comment.
Can just be:
| _name = "estate.property" | |
| _inherit = ["estate.property"] | |
| _inherit = "estate.property" |
| "security/ir.model.access.csv", | ||
| ], | ||
| "license": "LGPL-3", | ||
| "auto_install": True, |
There was a problem hiding this comment.
This makes sense here ! Do you know why ?

No description provided.