Skip to content

Commit

Permalink
[ADD] estate: add sprinkles, colored tag/offers, add stat button
Browse files Browse the repository at this point in the history
- add status bar widget, model ordering on basis of their name, id and manual
     ordering
-Add conditional display of buttons(invisible, optional, readonly)
-Add a default filter. make the ‘Available’ filter selected by default in the
      estate.property action.
-add the stat button
- Covered chapter 11
  • Loading branch information
irah-odoo committed Aug 12, 2024
1 parent 8a44cae commit 11bab82
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 112 deletions.
3 changes: 1 addition & 2 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'name': 'estate',
'version': '0.1',
'license': 'LGPL-3',
'depends': ['base_setup'],
'depends': ['base_setup', 'mail'],
'description': "Technical Training",
'installable': True,
'application': True,
Expand All @@ -15,5 +15,4 @@
'view/estate_property_offer_views.xml',
'view/estate_menus.xml',
],

}
33 changes: 15 additions & 18 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@
class estate_property(models.Model):
_name = "estate_property"
_description = "Estate Property"
_order = "sequence, id desc"
_inherit = ['mail.thread', 'mail.activity.mixin']
name = fields.Char(required=True)
description = fields.Text()
sequence = fields.Integer('Sequence')
postcode = fields.Char()
date_availability = fields.Date(default=date.today() + relativedelta(month=3))
expected_price = fields.Float(readonly= True, required=True)
selling_price = fields.Float(readonly= True)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True)
bedrooms = fields.Integer(default=2)
livingArea = fields.Integer()
garage = fields.Integer()
facades = fields.Integer()
garden = fields.Boolean()
garden_area = fields.Integer()
active = fields.Boolean(default=True)
state = fields.Selection(default='new',
selection=[('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'), ('canceled', 'Canceled')])
state = fields.Selection(default='new', selection=[('new', 'New'), ('offer_received', 'Offer Received'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')], tracking=True)
garden_orientation = fields.Selection(selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')])
property_type = fields.Many2one("estate_property_type", string="Product Type")
property_type = fields.Many2one("estate_property_type", string="Property Type")
salesperson_id = fields.Many2one('res.users', string='Selesperson', default=lambda self: self.env.user)
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False, ondelete='cascade')
tag_ids = fields.Many2many("estate_property_tag", string="Tags")
offer_ids = fields.One2many('estate_property_offer', 'property_id')
total_area = fields.Float(compute="_compute_total")

best_offer = fields.Float(compute="_best_offer")
_sql_constraints = [
('check_Expected_price', 'CHECK(expected_price > 0)', 'Expected Price must be strictly positive'),
('check_selling_price', 'CHECK(selling_price >= 0)', 'Selling Price selling price must be positive'),
Expand All @@ -44,8 +43,6 @@ def _compute_total(self):
for record in self:
record.total_area = record.garden_area + record.livingArea

best_offer = fields.Float(compute="_best_offer")

@api.depends('offer_ids')
def _best_offer(self):
maximum_price = 0
Expand All @@ -62,7 +59,7 @@ def _onchange_garden(self):
else:
self.garden_area = 0
self.garden_orientation = ''

def button_action_sold(self):
if self.state == "canceled":
raise UserError("Can't be Sold")
Expand All @@ -74,12 +71,12 @@ def button_action_cancled(self):
raise UserError("Can't be Cancle, It is already Sold")
else:
self.state = "canceled"
@api.constrains('selling_price','expected_price')

@api.constrains('selling_price', 'expected_price')
def _price_constrains(self):
for record in self:
if record.selling_price > 0:
if record.selling_price < 0.9*record.expected_price:
raise ValidationError("Selling price cannot be lower than 90% of the expected price")
else:
pass
if record.selling_price < 0.9 * record.expected_price:
raise ValidationError("Selling price cannot be lower than 90% of the expected price")
else:
pass
14 changes: 9 additions & 5 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from odoo import models, fields, api
from datetime import date
from datetime import timedelta
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import UserError


class estate_property_offer(models.Model):
_name = "estate_property_offer"
_description = "Estate Property offer"
price = fields.Float()
_order = "sequence, price desc"
sequence = fields.Integer('Sequence')
_sql_constraints = [
('offer_price', 'CHECK(price > 0)', 'offer price must be strictly positive')
]
status = fields.Selection(copy=False, selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
partner_id = fields.Many2one("res.partner", required=True)
property_id = fields.Many2one("estate_property", required=True, ondelete='cascade')
property_id = fields.Many2one("estate_property", required=True)
validity = fields.Integer(default=7)
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_validity", string="Deadline")
property_type_id = fields.Many2one(related="property_id.property_type", store=True)

@api.depends('validity')
def _compute_deadline(self):
Expand All @@ -29,15 +32,14 @@ def _compute_deadline(self):
record.date_deadline = today + (record.validity - (record.date_deadline - today).days)
else:
record.date_deadline = timedelta(days=record.validity) + today

@api.ondelete(at_uninstall=False)
def _deletion_check(self):
for record in self:
if record.status == 'accepted':
record.property_id.buyer_id = None
record.property_id.selling_price = 0


def _inverse_validity(self):
for record in self:
today1 = fields.Date.from_string(record.create_date)
Expand All @@ -51,11 +53,13 @@ def action_confirm(self):
self.property_id.selling_price = self.price
self.property_id.buyer_id = self.partner_id
self.status = 'accepted'

self.property_id.state = 'offer_accepted'

def action_refused(self):
if self.status == 'accepted' and self.property_id.buyer_id == self.partner_id:
self.status = 'refused'
self.property_id.buyer_id = None
self.property_id.selling_price = 0
self.property_id.state = 'new'
else:
self.status = "refused"
5 changes: 4 additions & 1 deletion estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class estate_property_tag(models.Model):
_name = "estate_property_tag"
_description = "Estate Property Tag"
name = fields.Char(required=True)
_order = " sequence, name"
sequence = fields.Integer('Sequence')
color = fields.Integer()

_sql_constraints = [
('unique_tag','UNIQUE(name)','Property Tag name must be unique')
('unique_tag', 'UNIQUE(name)', 'Property Tag name must be unique')
]
12 changes: 11 additions & 1 deletion estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from odoo import models, fields
from odoo import api, models, fields


class estate_property_type(models.Model):
_name = "estate_property_type"
_description = "Estate Property Type"
name = fields.Char(required=True)
_order = "sequence, name"
sequence = fields.Integer('Sequence')
property_list_id = fields.One2many('estate_property', 'property_type')
offer_ids = fields.One2many("estate_property_offer", "property_type_id", string="offers")
offer_count = fields.Integer(string="Numbers of offer", compute='_compute_offer_count', store=True)

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
24 changes: 18 additions & 6 deletions estate/view/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
<field name="name">estate_property_offer_tree</field>
<field name="model">estate_property_offer</field>
<field name="arch" type="xml">
<tree sample="1">
<tree sample="1" editable="bottom" decoration-success="status in ('accepted')" decoration-danger="status in ('refused')" >

<field name = 'sequence' widget = 'handle'/>
<field name='price' />
<field name='partner_id' />
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_confirm" type="object" title="confirm" icon="fa-check"/>
<button name="action_refused" type="object" title="refused" icon="fa-times"/>
<button name="action_confirm" type="object" title="confirm" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
<button name="action_refused" type="object" title="refused" icon="fa-times" invisible="status in ('accepted', 'refused')"/>

<field name='status' />
<field name='status' invisible="status in ('accepted', 'refused')"/>
</tree>
</field>
</record>
Expand All @@ -21,9 +23,9 @@
<field name="name">estate_property_offer_form</field>
<field name="model">estate_property_offer</field>
<field name="arch" type="xml">
<form>
<form >
<sheet>
<group>
<group >
<field name='price' />
<field name='partner_id' />
<field name="validity"/>
Expand All @@ -36,5 +38,15 @@
</field>
</record>

<record id="estate_property_offer_check" model="ir.actions.act_window">
<field name="name">Estate Property Offers</field>
<field name="res_model">estate_property_offer</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>


</record>



</odoo>
15 changes: 15 additions & 0 deletions estate/view/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@
<field name="res_model">estate_property_tag</field>
<field name="view_mode">tree,form</field>
</record>


<record id = "estate_property_tag_list_action" model = "ir.ui.view">
<field name = "name">estate_property_tag_list</field>
<field name = "model">estate_property_tag</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name = "sequence" widget = "handle" />
<field name = "name"/>

</tree>

</field>

</record>
</odoo>
60 changes: 58 additions & 2 deletions estate/view/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
<odoo>

<record id="estate_property_type_action" model="ir.actions.act_window">
<field name="name">Property Type</field>
<field name="res_model">estate_property_type</field>
<field name="view_mode">tree,form</field>
</record>


<record id="estate_property_type_list_action" model="ir.ui.view">
<field name="name">estate_property_type_form</field>
<field name="model">estate_property_type</field>
<field name="arch" type="xml">
<tree>
<field name='sequence' widget='handle' />
<field name="name" />

</tree>
</field>

</record>

<record id="estate_property_list_action" model="ir.ui.view">
<field name="name">estate_property_type_form</field>
<field name="model">estate_property_type</field>
<field name="arch" type="xml">

<form>

<button type="action" name="%(estate_property_offer_check)d" string="offers" class="oe_stat_button"
icon="fa-ticket">

<div class="o_stat_info">
<field name="offer_count" widget="statinfo" string="" />
<span class="o_stat_text"> Offer</span>
</div>

</button>


<header>
<h1>
<field name="name" placeholder="e.g House">

</field>
</h1>
</header>
<notebook>
<page string="properties">
<field name="property_list_id">
<tree>
<field name="name" />
<field name="expected_price" />
<field name="state" />

</tree>

</field>

</page>
</notebook>
</form>
</field>
</record>

</odoo>
Loading

0 comments on commit 11bab82

Please sign in to comment.