diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index b30704b0f8..45e6a5696f 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -1,4 +1,5 @@ from odoo import api, fields, models +from odoo.exceptions import UserError class EstateProperty(models.Model): @@ -73,3 +74,17 @@ def _onchange_garden(self): else: self.garden_area = 0 self.garden_orientation = "" + + def action_property_sold(self): + self.ensure_one() + if self.state == "cancelled": + raise UserError("Cancelled properties cannot be sold.") + self.state = "sold" + return True + + def action_property_cancelled(self): + self.ensure_one() + if self.state == "sold": + raise UserError("Sold properties cannot be cancelled.") + self.state = "cancelled" + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index ea3d3af8d6..319e6889c3 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -1,5 +1,6 @@ from odoo import api, fields, models from odoo.tools.date_utils import date +from odoo.exceptions import UserError class EstatePropertyOffer(models.Model): @@ -28,3 +29,23 @@ def _compute_date_deadline(self): def _inverse_date_deadline(self): for record in self: record.validity = (record.date_deadline - record.create_date.date()).days + + def action_accept_offer(self): + self.ensure_one() + other_records = self.search([("id", "!=", str(self.id))]) + for rec in other_records: + if rec.status == "accepted": + raise UserError("Cannot have more than one accepted offer.") + self.status = "accepted" + self.property_id.buyer_id = self.partner_id + self.property_id.selling_price = self.price + return True + + def action_refuse_offer(self): + self.ensure_one() + old_status = self.status + self.status = "refused" + if old_status == "accepted": + self.property_id.buyer_id = "" + self.property_id.selling_price = 0 + return True diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml index 4f13338da2..5e3533059d 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -9,6 +9,8 @@ +