@@ -35,7 +35,7 @@ class EstateProperty(models.Model):
3535 selection = [('new' , 'New' ), ('received' , 'Offer Received' ), ('accepted' , 'Offer Accepted' ), ('sold' , 'Sold' ), ('cancelled' , 'Cancelled' )],
3636 default = 'new' , copy = False , required = True )
3737 seller_id = fields .Many2one ('res.users' , default = lambda self : self .env .user )
38- buyer_id = fields .Many2one ('res.partner' )
38+ buyer_id = fields .Many2one ('res.partner' , readonly = True )
3939 tag_ids = fields .Many2many ('estate.property.tag' , string = "Tags" )
4040 type_id = fields .Many2one ('estate.property.type' , string = "Type" )
4141 offer_ids = fields .One2many ('estate.property.offer' , 'property_id' )
@@ -82,5 +82,10 @@ def action_set_cancelled(self):
8282 @api .constrains ('selling_price' , 'expected_price' )
8383 def _check_selling_price (self ):
8484 self .ensure_one ()
85- if len ( self .offer_ids ) > 0 and float_compare (self .expected_price , 0.9 * self .selling_price , 0 ) > 0 :
85+ if self .buyer_id and float_compare (self .expected_price , 0.9 * self .selling_price , 0 ) > 0 :
8686 raise ValidationError ("The selling price cannot be lower than 90% of the expected price." )
87+
88+ @api .ondelete (at_uninstall = False )
89+ def _unlink_if_not_new_or_cancelled (self ):
90+ if any (record .state in ['new' , 'cancelled' ] for record in self ):
91+ raise UserError ("Can't delete a property which has a state of new or cancelled!" )
0 commit comments