|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | from dateutil.relativedelta import relativedelta |
3 | | -from odoo.exceptions import ValidationError |
| 3 | +from odoo.exceptions import UserError, ValidationError |
4 | 4 |
|
5 | 5 | from odoo import api, models, fields, exceptions |
6 | 6 |
|
@@ -54,9 +54,7 @@ class EstateProperty(models.Model): |
54 | 54 | copy=False, |
55 | 55 | default="new", |
56 | 56 | ) |
57 | | - property_type_id = fields.Many2one( |
58 | | - "estate.property.type", string="Property Type" |
59 | | - ) |
| 57 | + property_type_id = fields.Many2one("estate.property.type", string="Property Type") |
60 | 58 | customer = fields.Many2one("res.partner", string="Customer", copy=False) |
61 | 59 | salesperson = fields.Many2one( |
62 | 60 | "res.users", string="Salesperson", default=lambda self: self.env.user |
@@ -107,8 +105,20 @@ def action_cancel_offer(self): |
107 | 105 | @api.constrains("selling_price", "expected_price") |
108 | 106 | def _check_selling_price_persentage(self): |
109 | 107 | for record in self: |
110 | | - selling_price_persentage = (record.selling_price / record.expected_price) * 100 |
111 | | - if selling_price_persentage >=90 or selling_price_persentage == 0: |
| 108 | + selling_price_persentage = ( |
| 109 | + record.selling_price / record.expected_price |
| 110 | + ) * 100 |
| 111 | + if selling_price_persentage >= 90 or selling_price_persentage == 0: |
112 | 112 | pass |
113 | 113 | else: |
114 | | - raise ValidationError("the selling price cannot be lower than 90% of the expected price.") |
| 114 | + raise ValidationError( |
| 115 | + "the selling price cannot be lower than 90% of the expected price." |
| 116 | + ) |
| 117 | + |
| 118 | + @api.ondelete(at_uninstall=False) |
| 119 | + def _unlink_prevent_property_on_state(self): |
| 120 | + for record in self: |
| 121 | + if record.state not in ("new", "cancelled"): |
| 122 | + raise UserError( |
| 123 | + "Can Delete property only on 'New' or 'Cancelled' state!" |
| 124 | + ) |
0 commit comments