Skip to content

Commit 259a7b3

Browse files
committed
[IMP] estate: chapter10
1 parent cda8d01 commit 259a7b3

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.analysis.extraPaths": [
3+
"/home/odoo/Documents/odoo"
4+
]
5+
}

estate/models/estate_property.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from odoo import api, fields, models
2-
from odoo.exceptions import UserError
2+
from odoo.exceptions import UserError, ValidationError
3+
from odoo.tools.float_utils import float_compare
34

45

56
class EstateProperty(models.Model):
67
_name = "estate.property"
78
_description = "Estate Property"
9+
_check_expected_price = models.Constraint("CHECK(expected_price>0)", "Le prix doit être strictement positif.")
10+
_check_selling_price = models.Constraint("CHECK(selling_price>=0)", "Le prix doit être positif.")
811

912
name = fields.Char(required=True)
1013
description = fields.Text()
@@ -38,7 +41,7 @@ class EstateProperty(models.Model):
3841
def _compute_total(self):
3942
for record in self:
4043
record.total_area = record.living_area + record.garden_area
41-
44+
4245
@api.depends("offer_ids")
4346
def _compute_highest_price(self):
4447
for record in self:
@@ -60,3 +63,9 @@ def action_mark_as_cancelled(self):
6063
raise UserError("Cette maison a déjà été vendue")
6164
self.state = "Cancelled"
6265
return True
66+
67+
@api.constrains("selling_price", "expected_price")
68+
def _check_selling_price_is_ok(self):
69+
for record in self:
70+
if float_compare(self.selling_price, 0.9 * self.expected_price, 2) == -1:
71+
raise ValidationError("Le prix de vente doit valoir au moins 90 pourcents du prix attendu.")

estate/models/estate_property_offer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class EstatePropertyOffer(models.Model):
55
_name = "estate.property.offer"
66
_description = "ici je mets une phrase 4"
7+
_check_price = models.Constraint("CHECK(price>0)", "Le prix doit être strictement positif.")
78

89
price = fields.Float()
910
status = fields.Selection(copy=False, selection=[('Accepted', 'Accepted'), ('Refused', 'Refused')])
@@ -26,7 +27,7 @@ def action_accept(self):
2627
self.property_id.buyer = self.partner_id
2728
self.property_id.selling_price = self.price
2829
return True
29-
30+
3031
def action_refuse(self):
3132
self.status = "Refused"
3233
return True

estate/models/estate_property_tag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "ici je mets une phrase 3"
7+
_name_unique = models.Constraint("unique (name)", "Ce tag existe déjà.")
78

89
name = fields.Char(required=True)

estate/models/estate_property_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "ici je mets une phrase 2"
7+
_name_unique = models.Constraint("unique (name)", "Ce type de propriété existe déjà.")
78

89
name = fields.Char(required=True)

estate/views/estate_property_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
<list string="Channel" >
7171
<field name="price"/>
7272
<field name="partner_id"/>
73-
<button name="action_accept" type="object" icon="fa-check"/>
74-
<button name="action_refuse" type="object" icon="oi-close"/>
73+
<button name="action_accept" type="object" icon="fa-check" string="accept"/>
74+
<button name="action_refuse" type="object" icon="oi-close" string="refuse"/>
7575
<field name="status"/>
7676
</list>
7777
</field>

0 commit comments

Comments
 (0)