-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] estate: add sprinkles, colored offers/tag, add stat/accepte/ref…
…use button - Add inline view and make editable - Add sequence and widget - Add conditional button on Offer and State - Add invisible, optional, editable filled - Add related fields in model property_type_id - Add Offer view from property_type - Covered chapter 11
- Loading branch information
Showing
9 changed files
with
205 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,119 @@ | ||
from odoo import models, fields, api | ||
from dateutil.relativedelta import relativedelta | ||
from datetime import date | ||
from odoo.exceptions import UserError | ||
from odoo.exceptions import UserError, ValidationError | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Real Estate Property Data" | ||
_inherit = ["mail.thread", "mail.activity.mixin"] | ||
name = fields.Char(required=True) | ||
description = fields.Char() | ||
postcode = fields.Char() | ||
date_availability = fields.Date(default=date.today() + relativedelta(months=3)) | ||
date_availability = fields.Date( | ||
copy=False, default=date.today() + relativedelta(months=3) | ||
) | ||
expected_price = fields.Float(required=True) | ||
selling_price = fields.Float() | ||
selling_price = fields.Float(copy=False, readonly=True) | ||
bedrooms = fields.Integer(default=2) | ||
living_area = fields.Integer() | ||
facades = fields.Integer() | ||
garage = fields.Boolean() | ||
garden = fields.Boolean() | ||
garden_area = fields.Integer() | ||
active = fields.Boolean(default=True) | ||
state = fields.Selection(default='new', selection=[('new', 'New'), ('offer_recived', 'Offer Recieved'), ('offer_accepted', 'Offer Accepted'), ('sold', 'Sold'), ('canceled', 'Canceled')]) | ||
garden_orientation = fields.Selection(selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')]) | ||
property_type_id = fields.Many2one("estate.property.type", string='Property Type') | ||
state = fields.Selection( | ||
required=True, | ||
copy=False, | ||
default="new", | ||
selection=[ | ||
("new", "New"), | ||
("offer_recived", "Offer Recieved"), | ||
("offer_accepted", "Offer Accepted"), | ||
("sold", "Sold"), | ||
("canceled", "Canceled"), | ||
], | ||
tracking=True, | ||
) | ||
garden_orientation = fields.Selection( | ||
selection=[ | ||
("north", "North"), | ||
("south", "South"), | ||
("east", "East"), | ||
("west", "West"), | ||
] | ||
) | ||
_order = "id desc" | ||
salesman_id = fields.Many2one( | ||
'res.users', # The model this field relates to | ||
string='Salesman', # Label for the field | ||
default=lambda self: self.env.user.partner_id # Set default to the current user's partner | ||
"res.users", # The model this field relates to | ||
string="Salesman", # Label for the field | ||
default=lambda self: self.env.user, # Set default to the current user's partner | ||
) | ||
buyer_id = fields.Many2one( | ||
'res.partner', # The model this field relates to | ||
string='Buyer', # Label for the field | ||
copy=False # Prevent the field value from being copied when duplicating the record | ||
"res.partner", # The model this field relates to | ||
string="Buyer", # Label for the field | ||
copy=False, # Prevent the field value from being copied when duplicating the record | ||
) | ||
|
||
tag_ids = fields.Many2many('estate.property.tag', string='Tags') | ||
offer_ids = fields.One2many('estate.property.offer', 'property_id') | ||
total = fields.Integer(compute='total_area') | ||
tag_ids = fields.Many2many("estate.property.tag", string="Tags", ondelete="cascade") | ||
offer_ids = fields.One2many("estate.property.offer", "property_id") | ||
total = fields.Integer(compute="total_area") | ||
best_offer = fields.Float(compute="best_offer_selete", store=True) | ||
property_type_id = fields.Many2one("estate.property.type") | ||
|
||
@api.depends('living_area', 'garden_area') | ||
sql_constraints = [ | ||
( | ||
"check_expected_price", | ||
"CHECK(expected_price > 0)", | ||
"The Expected Price of Property should be positive", | ||
), | ||
( | ||
"check_selling_price", | ||
"CHECK(selling_price >= 0 )", | ||
"The Selling Price of Property should be Positive", | ||
), | ||
("name_uniq", "unique (name)", "Property name already exists!"), | ||
] | ||
|
||
@api.depends("living_area", "garden_area") | ||
def total_area(self): | ||
for recorde in self: | ||
recorde.total = recorde.living_area + recorde.garden_area | ||
|
||
best_offer = fields.Float(compute='best_offer_selete', store=True) | ||
|
||
@api.depends('offer_ids') | ||
@api.depends("offer_ids") | ||
def best_offer_selete(self): | ||
temp = 0 | ||
for offer in self.offer_ids: | ||
if offer.price > temp: | ||
temp = offer.price | ||
self.best_offer = temp | ||
|
||
@api.onchange('garden') | ||
@api.onchange("garden") | ||
def garden_change(self): | ||
if self.garden: | ||
self.garden_area = 10 | ||
self.garden_orientation = 'north' | ||
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = '' | ||
self.garden_orientation = "" | ||
|
||
def status_action_sold_button(self): | ||
if self.state == 'canceled': | ||
if self.state == "canceled": | ||
raise UserError("Canceled property can't be sold") | ||
else: | ||
self.state = 'sold' | ||
self.state = "sold" | ||
|
||
def status_action_canceled_button(self): | ||
if self.state == 'sold': | ||
if self.state == "sold": | ||
raise UserError("Sold property can't be canceled") | ||
else: | ||
self.state = 'canceled' | ||
self.state = "canceled" | ||
|
||
_sql_constraints = [ | ||
('check_expected_price', 'CHECK(expected_price > 0)', | ||
'The Expected Price of Property should be positive'), | ||
('check_selling_price', 'CHECK(selling_price >= 0 )', | ||
'The Selling Price of Property should be Positive'), | ||
('name_uniq', 'unique (name)', "Property name already exists!"), | ||
] | ||
@api.constrains("selling_price", "expexted_price") | ||
def _check_date_end(self): | ||
for record in self: | ||
if record.selling_price > 0: | ||
price_percent = (record.selling_price / record.expected_price) * 100 | ||
if price_percent < 90: | ||
raise ValidationError("Selling Price must be at least 90%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
from odoo import fields, models | ||
from odoo import fields, models, api | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Real Estate Property Type" | ||
name = fields.Char(required=True) | ||
property_id = fields.One2many('estate.property', 'property_type_id') | ||
_order = 'sequence, name' | ||
sequence = fields.Integer('Sequence', help="Used to order stages. Lower is better.") | ||
offers_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
offer_count = fields.Integer(compute='_offers_count', help="Number of offers") | ||
|
||
@api.depends('offers_ids.property_type_id') | ||
def _offers_count(self): | ||
for record in self: | ||
if record.offers_ids: | ||
record.offer_count = len(record.offers_ids) | ||
else: | ||
record.offer_count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.