-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] estate: first tutorial for a real estate #868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mohf-odoo
wants to merge
12
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorials-mohf
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6420332
[ADD] estate: first tutoiral for a real estate
mohf-odoo f6cad70
[IMP] estate: added the one2many relationship between the estate and …
mohf-odoo 84aecea
[IMP] estate: added the one2many relationship between the estate and …
mohf-odoo 061f947
[IMP] estate: added smart fields (computed and onchanges), actions, a…
mohf-odoo b2ce65e
[FIX] estate: resolve multiple warnings in views and manifests
mohf-odoo 2f8fc34
[ADD] estate: enhanced UI I
mohf-odoo e9933bc
[ADD] estate: enhanced UI II
mohf-odoo 3f2658f
[ADD] estate: inheritance, interacting with other modules and kanban
mohf-odoo a798ede
[ADD] estate: adding the estate_account
mohf-odoo bceae2f
[ADD] estate: chatter and UI enhancements
mohf-odoo 1c1599d
[FIX] estate: clean codeded
mohf-odoo d327098
[ADD] awesome_owl: Web framework Counter Example
mohf-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Card extends Component { | ||
static template = "awesome_owl.Card"; | ||
static props = { | ||
heading: { type: String }, | ||
content: { type: String }, | ||
slots: { | ||
type: Object, | ||
shape: { | ||
default: true | ||
}, | ||
}, | ||
}; | ||
|
||
setup() { | ||
this.state = useState({ isOpen: true }); | ||
} | ||
|
||
toggleContent(){ | ||
this.state.isOpen = !this.state.isOpen; | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -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-out="props.heading"/> | ||
<button class="btn" t-on-click="toggleContent">Toggle</button> | ||
</h5> | ||
<p class="card-text" t-if="state.isOpen"> | ||
<t t-out="props.content"/> | ||
<t t-slot="default"/> | ||
</p> | ||
</div> | ||
</div> | ||
</t> | ||
</templates> |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @odoo-module **/ | ||
|
||
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({ value: 0 }); | ||
} | ||
|
||
increment() { | ||
this.state.value++; | ||
if (this.props.onChange) { | ||
this.props.onChange(); | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
<t t-name="awesome_owl.Counter"> | ||
<div class="m-2 p-2 border d-inline-block"> | ||
<span class="me-2">Counter: <t t-esc="state.value"/></span> | ||
<button t-on-click="increment"> | ||
Click Me! [<t t-esc="state.value"/>] | ||
</button> | ||
</div> | ||
</t> | ||
</templates> |
This file contains hidden or 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,22 @@ | ||
/** @odoo-module **/ | ||
import { Card } from "./card/card"; | ||
import { Component, markup, useState } from "@odoo/owl"; | ||
import { Counter } from "./counter/counter"; | ||
|
||
import { Component } from "@odoo/owl"; | ||
|
||
export class Playground extends Component { | ||
static template = "awesome_owl.playground"; | ||
static template = "awesome_owl.Playground"; | ||
static components = { Card, Counter }; | ||
static props = { | ||
heading: { type: String, optional: true } | ||
}; | ||
|
||
setup() { | ||
this.str1 = "<div class='text-primary'>some content</div>"; | ||
this.str2 = markup("<div class='text-primary'>HTML content using markup</div>"); | ||
this.sum = useState({ value: 0 }); | ||
} | ||
|
||
incrementSum() { | ||
this.sum.value++; | ||
} | ||
} |
This file contains hidden or 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,10 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
<t t-name="awesome_owl.Playground"> | ||
<div class="p-5"> | ||
<div class="text-center"> | ||
<h2 class="flex"> | ||
Hello dear, | ||
<img src="./awesome_owl/static/src/Owl.png" alt="Owl Picture" style="width: 50px; height: 80px;"/> | ||
</h2> | ||
<p class="italic"> | ||
"Wisdom doesn’t always hoot the loudest, but it listens the best." | ||
</p> | ||
</div> | ||
<div class="flex-column"> | ||
<div class="mb-2"> | ||
<Counter onChange.bind="incrementSum"/> | ||
<Counter onChange.bind="incrementSum" /> | ||
</div> | ||
|
||
<t t-name="awesome_owl.playground"> | ||
<div class="p-3"> | ||
hello world | ||
<div class="mb-40"> | ||
<p>Total Sum: <t t-esc="sum.value" /></p> | ||
</div> | ||
</div> | ||
<div> | ||
<Card heading="'Wisdom 1'" content="'Knowledge flies on quiet wings — not loud ones.'"> | ||
<t t-out="this.str2" /> | ||
</Card> | ||
<Card heading="'Wisdom 2'" content="'True wisdom doesn’t flutter — it soars slowly and surely.'"> | ||
<Counter /> | ||
</Card> | ||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
'name': 'Estate', | ||
'depends': [ | ||
'base_setup', | ||
'mail' | ||
], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/ninja_turtles_estate_views.xml', | ||
'views/ninja_turtles_estate_property_offer_views.xml', | ||
'views/ninja_turtles_estate_property_type_views.xml', | ||
'views/ninja_turtles_estate_property_tag_views.xml', | ||
'views/ninja_turtles_estate_property_kanban.xml', | ||
'views/ninja_turtles_estate_menus.xml', | ||
'views/res_users_views.xml', | ||
], | ||
'license': 'LGPL-3', | ||
'application': True | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import ninja_turtles_estate | ||
from . import ninja_turtles_estate_property_offer | ||
from . import ninja_turtles_estate_property_tag | ||
from . import ninja_turtles_estate_property_type | ||
from . import res_users |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
from datetime import date, timedelta | ||
|
||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tools import float_compare, float_is_zero | ||
|
||
|
||
class NinjaTurtlesEstate(models.Model): | ||
_name = "ninja.turtles.estate" | ||
_description = "For the fastest progress ever!" | ||
_order = "id desc" | ||
_inherit = ['mail.thread'] | ||
|
||
name = fields.Char(string="Name", required=True) | ||
description = fields.Text(string="Description") | ||
postcode = fields.Char(string="Postcode") | ||
date_availability = fields.Date( | ||
string="Available From", | ||
copy=False, | ||
default=lambda self: date.today() + timedelta(days=90), | ||
) | ||
expected_price = fields.Float(string="Expected Price", required=True) | ||
selling_price = fields.Float( | ||
string="Selling Price", | ||
readonly=True, | ||
copy=False, | ||
) | ||
bedrooms = fields.Integer( | ||
string="Bedrooms", | ||
default=2, | ||
) | ||
living_area = fields.Integer(string="Living Area (sqm)") | ||
facades = fields.Integer(string="Facades") | ||
garage = fields.Boolean(string="Garage") | ||
garden = fields.Boolean(string="Garden") | ||
garden_area = fields.Integer(string="Garden Area (sqm)") | ||
garden_orientation = fields.Selection( | ||
string="Garden Orientation", | ||
selection=[ | ||
('north', 'North'), | ||
('south', 'South'), | ||
('east', 'East'), | ||
('west', 'West'), | ||
], | ||
help="Garden Orientation is for choosing your specified area for your garden.", | ||
) | ||
status = fields.Selection( | ||
string="Status", | ||
selection=[ | ||
('new', 'New'), | ||
('offer received', 'Offer Received'), | ||
('offer accepted', 'Offer Accepted'), | ||
('sold', "Sold"), | ||
('cancelled', "Cancelled"), | ||
], | ||
required=True, | ||
default="new", | ||
copy=False, | ||
tracking=True, | ||
) | ||
active = fields.Boolean( | ||
string="Active", | ||
default=True, | ||
) | ||
total_area = fields.Integer( | ||
string="Total Area", | ||
compute="_compute_total_area", | ||
) | ||
best_price = fields.Float( | ||
string="Best Offer", | ||
compute="_compute_best_price", | ||
) | ||
property_type_id = fields.Many2one( | ||
"ninja.turtles.estate.property.type", | ||
string="Property Type", | ||
) | ||
buyer_id = fields.Many2one( | ||
"res.partner", | ||
string="Buyer", | ||
copy=False, | ||
) | ||
salesperson_id = fields.Many2one( | ||
"res.users", | ||
string="Salesperson", | ||
default=lambda self: self.env.user, | ||
) | ||
tag_ids = fields.Many2many( | ||
"ninja.turtles.estate.property.tag", | ||
string="Tags", | ||
) | ||
offer_ids = fields.One2many( | ||
"ninja.turtles.estate.property.offer", | ||
"property_id", | ||
string="Offers", | ||
tracking=True, | ||
) | ||
|
||
_sql_constraints = [ | ||
('check_expected_price_positive', 'CHECK(expected_price > 0)', 'Expected price must be strictly positive.'), | ||
('check_selling_price_positive', 'CHECK(selling_price >= 0)', '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): | ||
self.best_price = 0 | ||
for record in self.filtered(lambda r: r.offer_ids and any(r.offer_ids.mapped('price'))): | ||
record.best_price = max(record.offer_ids.mapped('price')) | ||
|
||
@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 = False | ||
|
||
def action_mark_sold(self): | ||
for record in self: | ||
if record.status in ('cancelled', 'new'): | ||
raise UserError("Cancelled or new properties cannot be sold.") | ||
elif record.status == 'offer received': | ||
raise UserError("You cannot sell a property with a non-accepted offer.") | ||
else: | ||
record.status = 'sold' | ||
|
||
def action_cancel(self): | ||
for record in self: | ||
if record.status == 'sold': | ||
raise UserError("Sold properties cannot be cancelled.") | ||
record.status = 'cancelled' | ||
|
||
@api.constrains('selling_price', 'expected_price') | ||
def _check_selling_price_margin(self): | ||
for record in self.filtered(lambda p: not float_is_zero(p.selling_price, precision_digits=2)): | ||
min_price = 0.9 * record.expected_price | ||
if float_compare(record.selling_price, min_price, precision_digits=2) < 0: | ||
raise ValidationError( | ||
"Selling price cannot be lower than 90% of the expected price.\n" | ||
f"Expected: {record.expected_price}, Minimum Allowed: {min_price}, Given: {record.selling_price}" | ||
) | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def _check_property_deletion(self): | ||
if any(self.filtered(lambda p: p.status not in ['new', 'cancelled'])): | ||
raise UserError("You can only delete properties in 'New' or 'Cancelled' status.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.