Skip to content

Commit

Permalink
[IMP] estate: linking of business loigic with actions
Browse files Browse the repository at this point in the history
-linked logic with actions when property either sold or cancelled.
-ensured once any button changed it can't changed again
-applied same for accepting or refusing an offer.
-set selling price and buyer once offer is accepted.
-once offer is accepted other offers can not be marked as accept & vice-versa
  • Loading branch information
siha-odoo committed Feb 6, 2025
1 parent 7518a14 commit f22f496
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
22 changes: 19 additions & 3 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dateutil.relativedelta import relativedelta
from odoo import api,fields, models
from odoo import api,fields, models, exceptions

#Class of EstateProperty to define fields of database table
class EstateProperty(models.Model):
Expand Down Expand Up @@ -37,7 +37,7 @@ class EstateProperty(models.Model):
default='new')
total_area = fields.Float(string='Total Aream(sqm)',compute='_compute_total_area')
property_type_id = fields.Many2one('estate.property.type', string='Property Type')
user_id=fields.Many2one(res.users', string='Salesperson', default=lambda self: self.env.user)
user_id=fields.Many2one('res.users', string='Salesperson', default=lambda self: self.env.user)
partner_id = fields.Many2one('res.partner', string='Buyer',copy=False)
tag_ids = fields.Many2many('estate.property.tags',string='Tags')
offer_ids = fields.One2many('estate.property.offer','property_id',string='Offers') #One2Many field
Expand Down Expand Up @@ -66,4 +66,20 @@ def onchange_check_garden_status(self):
else:
self.garden_area =0
self.garden_orientation =''


#Function to perform action when property Sold
def action_to_sold_property(self):
for record in self:
if record.state == 'cancelled':
raise exceptions.UserError('A cancelled property can not be sold')
record.state = 'sold'
return True

#Function to perform action when property Canceled
def action_to_cancel_property(self):
for record in self:
if record.state == 'sold':
raise exceptions.UserError('A sold property can not be cancelled')
record.state = 'cancelled'
return True

34 changes: 29 additions & 5 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dateutil.relativedelta import relativedelta
from odoo import fields,models,api
from odoo import fields,models,api, exceptions

class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
Expand Down Expand Up @@ -27,9 +27,33 @@ def _compute_deadline(self):
date.date_deadline = fields.Date.today() + relativedelta(days=date.validate)

def _update_validity(self):
for days in self:
if days.date_deadline:
days.validate = (days.date_deadline - fields.Date.today()).days
for offer in self:
if offer.date_deadline:
offer.validate = (offer.date_deadline - fields.Date.today()).days
else:
days.validate = 7
offer.validate = 7

#Function to perform action when offer accpeted
def action_accept(self):
for record in self:
if record.property_id.selling_price and (record.status == 'accepted' or record.status == 'refused'):
raise exceptions.UserError("This property has already accepted offer!")

record.property_id.selling_price = record.price
record.property_id.partner_id = record.partner_id

record.status = 'accepted'

other_offers = self.search([
('property_id', '=', record.property_id.id),
('id', '!=', record.id),
('status', '=', '')
])

other_offers.write({'status':'refused'})

#Function to perform action when offer refused
def action_refuse(self):
for record in self:
record.status = 'refused'

7 changes: 7 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="Estate Property">
<header>
<button string="SOLD" name="action_to_sold_property" type="object" class="oe_highlight"/>
<button string="CANCEL" name="action_to_cancel_property" type="object" class="oe_highlight"/>
</header>
<sheet>
<group>
<h1 class="mb32">
Expand All @@ -37,6 +41,7 @@
<group>
<group>
<field name="tag_ids" widget="many2many_tags"/>
<field name="state"/>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="date_availability"/>
Expand Down Expand Up @@ -68,6 +73,8 @@
<field name="partner_id">Partner</field>
<field name="validate"/>
<field name="date_deadline"/>
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
<button name="action_refuse" string="Refuse" type="object" icon="fa-times"/>
<field name="status">Status</field>
</list>
</field>
Expand Down

0 comments on commit f22f496

Please sign in to comment.