-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
10
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.
Draft
19.0 tutorials pkhu #1106
Changes from all commits
Commits
Show all changes
10 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 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 @@ | ||
| 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,17 @@ | ||
| { | ||
| 'name': "estate", | ||
| 'author': "pkhu", | ||
| 'license': "LGPL-3", | ||
| 'depends': ['base'], | ||
| '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_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,6 @@ | ||
| 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 |
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,128 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class Property(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'estate property details' | ||
| _order = 'id desc' | ||
|
|
||
| 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") | ||
| 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') | ||
|
|
||
| _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): | ||
| self.total_area = self.living_area + self.garden_area | ||
|
|
||
| @api.depends('offer_ids.price') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| if record.offer_ids.mapped('price'): | ||
| record.best_price = max(record.offer_ids.mapped('price')) | ||
| else: | ||
| record.best_price = None | ||
|
|
||
| @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 | ||
| if 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 == 'cancelled': | ||
| raise UserError("Cancelled property cannot be sold.") | ||
| else: | ||
| 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): | ||
| if self.state == 'sold': | ||
| raise UserError("Sold property cannot be Cancelled.") | ||
| else: | ||
| self.state = "cancelled" | ||
|
|
||
| @api.depends('property_maintainance_ids.cost') | ||
| def _compute_total_maintenance_cost(self): | ||
| for record in self: | ||
| if record.property_maintainance_ids: | ||
| record.total_maintenance_cost = sum( | ||
| record.property_maintainance_ids.mapped('cost')) | ||
| else: | ||
| record.total_maintenance_cost = 0.00 | ||
|
|
||
| @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 models, fields, api | ||
| 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,93 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import models, fields, api | ||
| 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: | ||
| if record.create_date: | ||
| record.date_deadline = record.create_date + \ | ||
| timedelta(days=record.validity) | ||
| else: | ||
| record.date_deadline = fields.Date.today() + timedelta(days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| if record.date_deadline: | ||
| record.validity = ( | ||
| record.date_deadline - record.create_date.date() | ||
| ).days | ||
| else: | ||
| record.validity = (record.date_deadline - fields.Date.today()) | ||
|
|
||
| def action_accepted(self): | ||
| accepect_records = self.property_id.offer_ids.filtered( | ||
| lambda o: o.status == 'accepted') | ||
| if accepect_records: | ||
| raise UserError("Only one offer can be accepted.") | ||
| 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( | ||
| f"Price should be greater than {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 models, fields | ||
|
|
||
|
|
||
| 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 models, fields, api | ||
|
|
||
|
|
||
| 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) |
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 odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many('estate.property', 'user_id') |
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,6 @@ | ||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
| model_estate,model_estate,model_estate_property,base.group_user,1,1,1,1 | ||
| model_estate_type,model_estate_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| model_estate_tag,model_estate_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| model_estate_offer,model_estate_offer,model_estate_property_offer,base.group_user,1,1,1,1 | ||
| model_estate_maintenance,model_estate_maintenance,model_estate_property_maintenance,base.group_user,1,1,1,1 |
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,16 @@ | ||
| <odoo> | ||
|
|
||
| <menuitem id="estate_menu" name="estate"> | ||
| <menuitem id="estate_advertisements" name="Advertisements"> | ||
| <menuitem id="estate_advertisements_properties" action="estate_property_action"/> | ||
| <!-- <menuitem id="estate_advertisements_property_offer" action="estate_property_offer_action"/> --> | ||
| </menuitem> | ||
|
|
||
| <menuitem id="estate_settings" name="Settings"> | ||
| <menuitem id="estate_settings_property_type" action="estate_property_type_action"/> | ||
| <menuitem id="estate_settings_property_tag" action="estate_property_tag_action"/> | ||
| <menuitem id="estate_settings_property_maintenance" action="estate_property_maintenance_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
|
|
||
| </odoo> |
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> | ||
|
|
||
| <record id="estate_property_maintenance_view_list" model="ir.ui.view"> | ||
| <field name='name'>estate.property.maintenance.view.list</field> | ||
| <field name='model'>estate.property.maintenance</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Channel"> | ||
| <field name="name"/> | ||
| <field name="property_id"/> | ||
| <field name="cost"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_maintenance_action" model="ir.actions.act_window"> | ||
| <field name='name'>Maintenance Request</field> | ||
| <field name='res_model'>estate.property.maintenance</field> | ||
| <field name='view_mode'>list,form</field> | ||
| </record> | ||
|
|
||
| </odoo> |
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.