Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions awesome_owl/static/src/Card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.card";
static props = {
title: String,
content: String,
};
}
15 changes: 15 additions & 0 deletions awesome_owl/static/src/Card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_owl.card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">
<t t-esc="props.title"/>
</h5>
<p class="card-text">
<t t-out="props.content"/>
</p>
</div>
</div>
</t>
</templates>
13 changes: 13 additions & 0 deletions awesome_owl/static/src/Counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.counter";
static props = {};
setup() {
this.state = useState({ value: 0 });
}

increment() {
this.state.value++;
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/Counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_owl.counter">
<div class="p-3">
hello world
<p>Counter: <t t-esc="state.value"/>
</p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>
</templates>
6 changes: 5 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Component } from "@odoo/owl";
import { Component, markup } from "@odoo/owl";
import { Counter } from "./Counter/counter";
import { Card } from "./Card/card";

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = {Counter, Card}
value1 = markup("<div class='text-danger'>This is the first card content</div>");
}
11 changes: 5 additions & 6 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
</div>
<Counter/>
<Card title="'First Card'" content="value1"/>
<Card title="'Second Card'" content="'This is the second card content'"/>
<Card title="'Third Card'" content="'Reusable components are powerful!'"/>
</t>

</templates>
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
'name': "estate",
'author': "pkhu",
'license': "LGPL-3",
'depends': ['base', 'mail'],
'application': True,
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_maintenance_view.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/res_users_views.xml',
'views/estate_investor_views.xml',
'views/estate_menus.xml',
],
}
7 changes: 7 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import estate_property
from . import estate_property_offer
from . import estate_property_tag
from . import etsate_property_type
from . import estate_property_maintenance
from . import res_users
from . import estate_investor
9 changes: 9 additions & 0 deletions estate/models/estate_investor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class EstateInvestor(models.Model):
_name = "estate.investor"
_description = "investor details"
_rec_name = 'id'

name = fields.Many2one('res.partner')
130 changes: 130 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from datetime import timedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = 'estate.property'
_description = 'estate property details'
_order = 'id desc'
_inherit = 'mail.thread'

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
copy=False, default=lambda self: fields.Date.today() + timedelta(days=90)
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer(string="Living Area(sqm)")
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
selection=[
('north', "North"),
('west', "West"),
('east', "East"),
('south', "South"),
]
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
default='new',
copy=False,
required=True,
)
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)
partner_id = fields.Many2one('res.partner', string="Buyer", readonly=True)
tag_ids = fields.Many2many('estate.property.tag', string="Tags")
offer_ids = fields.One2many(
'estate.property.offer', 'property_id')
total_area = fields.Integer(
compute='_compute_total_area', string="Total Area(sqm)")
best_price = fields.Float(compute='_compute_best_price', store=True)
property_maintainance_ids = fields.One2many(
'estate.property.maintenance', 'property_id')
total_maintenance_cost = fields.Float(
compute='_compute_total_maintenance_cost')
investor = fields.Many2one('estate.investor')
_check_expected_price = models.Constraint(
'CHECK(expected_price > 0)',
"The Expected price cannot be negative or zero."
)
_check_selling_price = models.Constraint(
'CHECK(selling_price > 0)',
"The Selling price cannot be negative."
)

@api.depends('garden_area', 'living_area')
def _compute_total_area(self):
for record in self:
record.total_area = record.living_area + record.garden_area

@api.depends('offer_ids.price')
def _compute_best_price(self):
best_price = dict(self.env['estate.property.offer']._read_group(domain=[
('property_id', 'in', self.ids)], aggregates=['price:max'], groupby=['property_id']))
for record in self:
record.best_price = best_price.get(record, 0.0)

@api.onchange('garden')
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = 'north'
else:
self.garden_area = None
self.garden_orientation = None

@api.constrains('selling_price', 'expected_price')
def _constraint_selling_price(self):
if float_is_zero(self.selling_price, precision_rounding=0.01):
return
elif float_compare(self.selling_price, self.expected_price * 0.9, precision_rounding=0.01) < 0:
raise ValidationError(_(
"Selling price cannot be lower than 90% of the expected price."))

def action_property_sold(self):
if self.state != 'offer_accepted':
raise UserError(_("Atleast one offer should be accepted."))
for record in self.property_maintainance_ids:
if record.status != 'done':
raise UserError(_("Maintenance Request are still pending."))
self.state = 'sold'

def action_property_cancel(self):
self.state = 'cancelled'

def action_accept_best_offer(self):
data = self.env['estate.property.offer'].search(
domain=[('property_id', 'in', self.ids), ('price', '=', self.best_price)], limit=1)
data.action_accepted()

@api.depends('property_maintainance_ids.cost')
def _compute_total_maintenance_cost(self):
maintenace_cost = dict(self.env['estate.property.maintenance']._read_group(domain=[(
'property_id', 'in', self.ids)], aggregates=['cost:sum'], groupby=['property_id']))
for record in self:
record.total_maintenance_cost = maintenace_cost.get(record, 0.0)

@api.ondelete(at_uninstall=False)
def _unlink_property(self):
if self.state not in ['new', 'cancelled']:
raise UserError(
_("Only new and cancelled property can be deleted."))
20 changes: 20 additions & 0 deletions estate/models/estate_property_maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_is_zero


class PropertyMantainance(models.Model):
_name = 'estate.property.maintenance'
_description = 'show propety maintenance request'

name = fields.Char(string="Title", required=True)
cost = fields.Float()
status = fields.Selection(selection=[(
'new', "New"), ('approved', "Approved"), ('done', "Done")], default='new')
property_id = fields.Many2one('estate.property')

@api.onchange('status')
def _onchange_status(self):
for record in self:
if record.status == 'approved' and float_is_zero(record.cost, precision_rounding=0.01):
raise UserError(_("Cost must be greater than zero."))
88 changes: 88 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from datetime import timedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare


class PropertyOffer(models.Model):
_name = 'estate.property.offer'
_description = 'Property offer for each property.'
_order = 'price desc'

price = fields.Float()
status = fields.Selection(
selection=[('accepted', "Accepted"), ('refused', "Refused")], copy=False
)
partner_id = fields.Many2one(
'res.partner', string="Partner", required=True)
property_id = fields.Many2one(
'estate.property', string="Property", required=True)
validity = fields.Integer(default=7)
date_deadline = fields.Date(
compute='_compute_date_deadline', inverse='_inverse_date_deadline'
)
property_type_id = fields.Many2one(
'estate.property.type',
related='property_id.property_type_id',
store=True
)

_check_price = models.Constraint(
'CHECK(price >= 0)',
"The Offer price cannot be negative."
)

@api.depends('validity')
def _compute_date_deadline(self):
for record in self:
record.date_deadline = (record.create_date or fields.Date.today()) + \
timedelta(days=record.validity)

def _inverse_date_deadline(self):
for record in self:
record.validity = (
record.date_deadline -
(record.create_date.date() or fields.Date.today())
).days

def action_accepted(self):
offers = self.property_id.offer_ids.filtered(
lambda a: a.id != self.id)
for offer in offers:
offer.status = 'refused'
self.status = 'accepted'
self.property_id.partner_id = self.partner_id
self.property_id.selling_price = self.price
self.property_id.state = 'offer_accepted'

def action_refused(self):
if self.status == 'accepted':
self.property_id.partner_id = None
self.property_id.selling_price = None
self.property_id.state = 'offer_received'
self.status = 'refused'

@api.ondelete(at_uninstall=False)
def _ondelete_offer(self):
for records in self:
if records.status == 'accepted':
raise ValidationError(_("Accepted offer cannot be deleted."))

@api.model
def create(self, vals):
for val in vals:
price = val.get('price')
property_id = val.get('property_id')
property = self.env['estate.property'].browse(property_id)
if property.state == 'new':
property.best_price = price
elif float_compare(price, property.best_price, precision_rounding=0.01) < 0:
raise UserError(
_("Price should be greater than %s", property.best_price))
else:
property.best_price = price
if property and property.state == 'new':
property.state = 'offer_received'

return super().create(vals)
15 changes: 15 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class PropertyTag(models.Model):
_name = 'estate.property.tag'
_description = 'Property Tags to describe property such new, renovated...'
_order = 'name'

name = fields.Char(required=True)
color = fields.Integer()

_unique_name = models.Constraint(
'UNIQUE(name)',
"Property Tag must be unique."
)
23 changes: 23 additions & 0 deletions estate/models/etsate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from odoo import api, fields, models


class PropertyType(models.Model):
_name = 'estate.property.type'
_description = 'Define Type of property (House, Apartment, Penthouse, Castle…)'
_order = 'sequence, name desc'

name = fields.Char(required=True)
property_ids = fields.One2many('estate.property', 'property_type_id')
sequence = fields.Integer(default=10)
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
offer_count = fields.Integer(compute='_compute_offer_count')

_unique_name = models.Constraint(
'UNIQUE(name)',
"Property Type must be unique."
)

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
Loading