diff --git a/estate/__manifest__.py b/estate/__manifest__.py
index 695124bc19..a6ce1f3d17 100644
--- a/estate/__manifest__.py
+++ b/estate/__manifest__.py
@@ -16,5 +16,6 @@
"views/estate_property_type_view.xml",
"views/estate_property_tag_view.xml",
"views/estate_menu.xml",
+ "views/res_users.xml",
],
}
diff --git a/estate/models/__init__.py b/estate/models/__init__.py
index 001ba04f23..dd577ecb4e 100644
--- a/estate/models/__init__.py
+++ b/estate/models/__init__.py
@@ -3,3 +3,4 @@
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
+from . import res_users
\ No newline at end of file
diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py
index 7deeb2c7b5..4e323adadc 100644
--- a/estate/models/estate_property.py
+++ b/estate/models/estate_property.py
@@ -35,6 +35,7 @@ class EstateProperty(models.Model):
("canceled", "Canceled"),
],
default="new",
+ readonly=True,
)
active = fields.Boolean(default=True)
saler_id = fields.Many2one(
@@ -74,8 +75,8 @@ def _compute_area(self):
def _compute_bestprice(self):
for record in self:
if record.offer_ids:
+ max1 = 0
for i in record.offer_ids:
- max1 = 0
if i.price > max1:
max1 = i.price
record.best_price = max1
@@ -102,6 +103,12 @@ def _check_selling_price(self):
raise ValidationError(
"the selling price cannot be lower than 90'%' of the expected price."
)
+ #creating a delection check function that will check if the property is sold or not
+ @api.ondelete(at_uninstall=False)
+ def _check_property(self):
+ if any(user.state not in ("new", "canceled") for user in self):
+ raise UserError("You can't delete a property that is in process.")
+
# created the action for the sold button that will chage the state field of the property to sold
def action_sold(self):
diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py
index a867505cf4..5264b192ea 100644
--- a/estate/models/estate_property_offer.py
+++ b/estate/models/estate_property_offer.py
@@ -1,7 +1,7 @@
from odoo import api, models, fields
from dateutil.relativedelta import relativedelta
from datetime import date
-from odoo.exceptions import UserError
+from odoo.exceptions import UserError, ValidationError
class EstateProperty(models.Model):
@@ -39,11 +39,6 @@ def _compute_deadline(self):
record.create_date = date.today()
record.deadline = record.create_date + relativedelta(days=record.Validity)
- @api.onchange("name")
- def _onchange_offer(self):
- if self.name:
- self.property_id.state = "offer_recieved"
-
# created the inverse function that will compute the validity when we manually update the deadline i.e deadline - creation date
def _inverse_deadline(self):
for record in self:
@@ -51,6 +46,16 @@ def _inverse_deadline(self):
record.deadline.toordinal() - record.create_date.toordinal()
)
+ # create a create model that will make status as offer recieved when we create the offer
+ @api.model
+ def create(self, vals):
+ record = super().create(vals)
+ if record.price < record.property_id.best_price:
+ raise ValidationError("One of the offer is present which is best than your offer.")
+ record.property_id.state = "offer_recieved"
+ return record
+
+
# created the action for the accept button that will accept the offer from the offers for a property.
def action_accept(self):
# checks weather any other offer is alredy accepted. if offer is alredy accepted then it will raise an error
diff --git a/estate/models/res_users.py b/estate/models/res_users.py
new file mode 100644
index 0000000000..d8039f3d33
--- /dev/null
+++ b/estate/models/res_users.py
@@ -0,0 +1,7 @@
+from odoo import fields, models
+
+
+class resuserinherit(models.Model):
+ _inherit = "res.users"
+
+ property_ids = fields.One2many("estate.property", "saler_id")
diff --git a/estate/views/estate_property_type_view.xml b/estate/views/estate_property_type_view.xml
index 859e6db485..f56f9b4c10 100644
--- a/estate/views/estate_property_type_view.xml
+++ b/estate/views/estate_property_type_view.xml
@@ -23,13 +23,16 @@
estate.property.type