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

18.0 gato tutorials #634

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ch.10 - all exercises
ch.10 - added constraints on expected_price, selling_price, offer_price, tag_name and type_name

ch.10 - Modified constraint on selling price: must be at least 90% of expected price to move to next stage
gato-odoo committed Mar 19, 2025
commit 4f495722646dfe7faffad1ad58b2a6c3f3f858dd
14 changes: 14 additions & 0 deletions realestatinator/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@ class EstatePropery(models.Model):
_name = 'estate_property'
Copy link

Choose a reason for hiding this comment

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

we use '.' for model naming instead of '_'

_description = 'real estate property'
_order = 'sequence'
_sql_constraints = [
('check_expected_price_positive', 'CHECK (0 < expected_price)', 'Check that the expected price is strictly positive'),

]


sequence = fields.Integer('Sequence', default=0)
name = fields.Char('Title', required=True)
@@ -86,3 +91,12 @@ def mark_sold(self):
raise exceptions.UserError('This property cannot be sold because it has already been cancelled.')

record.state = 'sold'

@api.constrains('selling_price')
def _check_selling_price(self):
print('\n\nconstraint\n\n')
for record in self:
if record.state not in ['offer_accepted', 'sold']:
return
if record.selling_price < 0.9 * record.expected_price:
raise exceptions.ValidationError('Selling price must be at least 90% of expected price.')
8 changes: 6 additions & 2 deletions realestatinator/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@
class EstatePropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = 'estate property offer'

_sql_constraints = [
('check_offer_price_positive', 'CHECK (0 < price)', 'Check that the offer price is strictly positive.'),
]
creation_date = fields.Date('Creation Date', default=fields.Date.today())
price = fields.Float('Price')
status = fields.Selection(string='Status', selection=[
@@ -28,14 +30,16 @@ def _inverse_deadline(self):
def refuse_offer(self):
for record in self:
if record.status == 'accepted':
record.property_id.selling_price = 0
record.property_id.state = 'offer_received'
record.property_id.selling_price = 0
record.property_id.buyer = None
record.status = 'refused'

def accept_offer(self):
for record in self:
if record.property_id.selling_price != 0:
raise exceptions.UserError('An offer as already been accepted for this property.')
record.property_id.state = 'offer_accepted'
record.status = 'accepted'
record.property_id.selling_price = record.price
record.property_id.buyer = record.partner_id
4 changes: 3 additions & 1 deletion realestatinator/models/estate_property_tags.py
Original file line number Diff line number Diff line change
@@ -3,5 +3,7 @@
class EstatePropertyTags(models.Model):
_name = 'estate.property.tags'
_description = 'estate property tag'

_sql_constraints = [
('name_unique', 'UNIQUE (name)', 'make sure tag name is unique.')
]
name = fields.Char('Name', required=True)
3 changes: 3 additions & 0 deletions realestatinator/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@
class EstatePropertyType(models.Model):
_name = 'estate.property.type'
_description = 'real estate property type'
_sql_constraints = [
('name_unique', 'UNIQUE (name)', 'make sure type name is unique.')
]
# _order = 'sequence'

name = fields.Char('Name', required=True)