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
10 changes: 10 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.Card";

static props = {
title: String,
content: String,
};
}
17 changes: 17 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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-esc="props.content"/>
</p>
</div>
</div>
</t>

</templates>
21 changes: 21 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.Counter";

static props = {
onChange: {
type: Function,
optional: true
},
};

setup() {
this.state = useState({ count: 1 });
}

increment() {
this.state.count++;
this.props.onChange();
}
}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.Counter">
<div class="border rounded p-3 d-flex align-items-center gap-3">
<span class="fw-semibold">
Counter: <t t-esc="state.count"/>
</span>

<button class="btn btn-primary" t-on-click="increment">
Increment
</button>
</div>
</t>

</templates>
15 changes: 14 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { Component } from "@odoo/owl";
import { Component, markup, useState } 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 };

setup() {
this.state = useState({ sum: 2 });
this.htmlContent = markup("<h1>Markup Text</h1>");
this.normalContent = "<h1>some content</h1>";
}
incrementSum() {
this.state.sum++;
}
}

25 changes: 22 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<?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 class="container">
<div class="p-3">
hello world
</div>
<div class="d-inline-flex flex-column gap-3">
<div class="d-inline-flex flex-column gap-3">
<div class="d-flex">
<Counter onChange.bind="incrementSum"/>
<Counter onChange.bind="incrementSum"/>
</div>
<div>
<p class="fw-bold mb-4">
The Sum is: <t t-esc="state.sum"/>
</p>
</div>
</div>
<div class="d-inline-flex border gap-3">
<Card title="'card 1'" content="htmlContent"/>
<Card title="'card 2'" content="normalContent"/>
</div>
</div>
</div>
</t>

Expand Down
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
21 changes: 21 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
'name': "Real Estate",
'description': """Real estate management tutorial module with properties, offers, types and tags.""",
'version': '1.0',
'license': 'LGPL-3',
'summary': 'Real Estate advertisement tutorial module',
'depends': ['base'],
'author': "Harsh Maniya",
'data': [
'security/ir.model.access.csv',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_views.xml',
'views/res_users_views.xml',
'views/estate_menus.xml'
],
'category': 'Sales/Real Estate',
'installable': True,
'auto_install': False,
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_offer
from . import estate_property_type
from . import estate_property_tag
from . import res_users
136 changes: 136 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
from dateutil.relativedelta import relativedelta
from datetime import date

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


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property"
_order = "id desc"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
default=lambda self: date.today() + relativedelta(months=3),
copy=False
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(
readonly=True,
copy=False
)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
selection=[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West'),
],
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled'),
],
required=True,
copy=False,
default='new',
)
property_type_id = fields.Many2one(
"estate.property.type",
)
salesperson_id = fields.Many2one(
"res.users",
default=lambda self: self.env.user,
)
buyer_id = fields.Many2one(
"res.partner",
copy=False,
)
tag_ids = fields.Many2many(
"estate.property.tag",
)
offer_ids = fields.One2many(
"estate.property.offer",
"property_id",
)
total_area = fields.Float(
compute="_compute_total_area"
)
best_price = fields.Float(
compute="_compute_best_price",
)
_expected_price = models.Constraint(
'CHECK(expected_price >= 0)',
'The expected price must be positive.',
)
_selling_price = models.Constraint(
'CHECK(selling_price >= 0)',
'The selling price must be positive.',
)

@api.depends('living_area', 'garden_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):
for record in self:
prices = record.offer_ids.mapped('price')
record.best_price = max(prices) if prices else 0.0

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

def action_cancel_property(self):
if self.filtered(lambda rec: rec.state == "sold"):
raise exceptions.UserError(_("Sold properties cannot be cancelled."))
self.write({"state": "cancelled"})
return True

def action_set_sold(self):
for rec in self:
if rec.state == "cancelled":
raise exceptions.UserError(_("Canceled properties cannot be sold."))
else:
rec.state = "sold"
return True

@api.constrains("selling_price", "expected_price")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be above one empty line.

def _check_selling_price(self):
for rec in self:
if rec.selling_price == 0:
return False
if float_compare(rec.selling_price, rec.expected_price * 0.9, precision_digits=2) < 0:
raise exceptions.ValidationError(_(
"The selling price must be at least 90% of the expected price!\n"
"You must reduce the expected price if you want to accept this offer."
))

@api.ondelete(at_uninstall=False)
def _check_property_deletion(self):
for rec in self:
if rec.state not in ("new", "cancelled"):
raise exceptions.UserError(_(
"You can only delete properties in New or Cancelled state."
))
81 changes: 81 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from dateutil.relativedelta import relativedelta

from odoo import models, fields, api, exceptions, _


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer"
_order = "price desc"

price = fields.Float(string="Price")
status = fields.Selection(
selection=[
("accepted", "Accepted"),
("refused", "Refused"),
],
copy=False,
)
partner_id = fields.Many2one(
"res.partner",
required=True,
)
property_id = fields.Many2one(
"estate.property",
required=True,
)
validity = fields.Integer(
default=7,
)
date_deadline = fields.Date(
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
store=True,
)
property_type_id = fields.Many2one(
related="property_id.property_type_id", store=True
)
_offer_price = models.Constraint(
'CHECK (price > 0)',
'Offer price must be greater than 0',
)

@api.depends("validity")
def _compute_date_deadline(self):
for rec in self:
create = rec.create_date or fields.Date.today()
rec.date_deadline = (create + relativedelta(days=rec.validity))

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

def action_accept(self):
for offer in self:
if offer.property_id.buyer_id:
raise exceptions.UserError(_('Only one offer can be accepted for a property.'))
offer.status = 'accepted'
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id
offer.property_id.state = 'offer_accepted'
return True

def action_refuse(self):
for offer in self:
offer.status = 'refused'
return True

@api.model
def create(self, vals):
for rec in vals:
property_id = rec.get('property_id')
price = rec.get('price', 0.0)
if property_id:
property_obj = self.env['estate.property'].browse(property_id)
best_offer = property_obj.best_price or 0.0
if price < best_offer:
raise exceptions.UserError(_(
'Offer price must be greater than or equal to the best offer price.'))
property_obj.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 models, fields


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_order = "name"

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

_unique_name = models.Constraint(
'unique(name)',
'The tag name must be unique.',
)
Loading