-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19.0 tutorials pkhu #1106
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
Draft
pkhu-odoo
wants to merge
14
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-pkhu
base: 19.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.
+829
−7
Draft
19.0 tutorials pkhu #1106
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e73b458
[ADD] estate: complete Chapters 1–5 of Odoo_Demo tutorial
pkhu-odoo 40526e2
[ADD] estate: completed Chapters 1–5 of Odoo tutorial Demo
pkhu-odoo 65548f0
[ADD] estate: completed Chapter 6 (Basic views setup for custom model)
pkhu-odoo ddda1fd
[ADD] estate: completed Chapter 7 (Relations between models)
pkhu-odoo 2d40394
[ADD] estate: completed Chapter 8 ( Computed Fields And Onchanges )
pkhu-odoo a6cbe6b
[ADD] estate: completed Chapter 9 and 10 ( Action and Constraints )
pkhu-odoo 8546bcb
[FIX] estate: FIX code style issues
pkhu-odoo b0836a2
[ADD] estate: completed Chapter 11 (Add The Sprinkles)
pkhu-odoo d8e37e7
[ADD] estate: Completed task (Property maintenance model)
pkhu-odoo c053845
[ADD] estate: completed Chapter 12 (Inheritance)
pkhu-odoo b386956
[ADD] estate: completed Chapter 13 (Interact With Other Modules)
pkhu-odoo 47c8163
[FIX] estate: apply code style suggestions
pkhu-odoo 96fbb34
[ADD] estate: completed Chapter 14 and 15
pkhu-odoo 3e60be3
[ADD] estate: OWL basics and estate enhancements
pkhu-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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.card"; | ||
| static props = { | ||
| title: String, | ||
| content: String, | ||
| }; | ||
| } |
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,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> |
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,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++; | ||
| } | ||
| } |
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="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> |
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,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>"); | ||
| } |
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,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> |
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,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', | ||
| ], | ||
| } |
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,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 |
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,9 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstateInvestor(models.Model): | ||
| _name = "estate.investor" | ||
| _description = "investor details" | ||
| _rec_name = 'id' | ||
|
|
||
| name = fields.Many2one('res.partner') | ||
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,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) | ||
pkhu-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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') | ||
pkhu-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.")) | ||
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,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.")) |
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,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) | ||
pkhu-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
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,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." | ||
| ) |
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 @@ | ||
| 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) |
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.