From a9817541014b0f5d0814faedf402e5bb6257c116 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelaziz Date: Thu, 19 Dec 2024 15:13:04 +0100 Subject: [PATCH] [IMP] estate: Use Actions To Cancel and set a property as sold --- estate/models/estate_property.py | 17 +++++++++++++++++ estate/models/estate_property_offer.py | 12 ++++++++++-- estate/views/estate_property_offer_views.xml | 2 ++ estate/views/estate_property_views.xml | 4 ++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index a4ef0e87d7..1866a29d53 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): @@ -71,3 +72,19 @@ def _onchange_garden(self): else: self.garden_area = 0 self.garden_orientation = False + + def action_sold(self): + for record in self: + if record.state != "canceled": + record.state = "sold" + else: + raise UserError("Canceled properties can't be sold") + return True + + def action_cancel(self): + for record in self: + if record.state != "sold": + record.state = "canceled" + else: + raise UserError("Sold properties can't be sold") + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py index 2fe9509333..b65e99b359 100644 --- a/estate/models/estate_property_offer.py +++ b/estate/models/estate_property_offer.py @@ -26,9 +26,17 @@ def _compute_date_deadline(self): record.date_deadline = fields.Datetime.add( record.create_date, days=record.validity ) - print("Hi there") def _inverse_date_deadline(self): for record in self: - print((record.date_deadline - record.create_date.date()).days) record.validity = (record.date_deadline - record.create_date.date()).days + + def action_accept(self): + for record in self: + record.status = "accepted" + record.property_id.selling_price = record.price + record.property_id.buyer = record.partner_id + + def action_refuse(self): + for record in self: + record.status = "refused" diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml index 7dc32ae36e..bc773744cc 100644 --- a/estate/views/estate_property_offer_views.xml +++ b/estate/views/estate_property_offer_views.xml @@ -10,6 +10,8 @@ +