-
Notifications
You must be signed in to change notification settings - Fork 2.9k
19.0 tutorial dhvag #1110
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
dhvag-odoo
wants to merge
11
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorial-dhvag
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 tutorial dhvag #1110
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
32a250b
[ADD] estate module: initial model structure (Chapters 1–3)
dhvag-odoo ca94372
[ADD] estate module: Setup and Checkpoint Validation (Chapters 4-6)
dhvag-odoo f8ae7c6
[ADD] estate module: Implement relations between estate models (Chapt…
dhvag-odoo 41b6a55
[FIX] estate module: fixed the import issue
dhvag-odoo 48db2c6
[FIX] estate module: Fixed review comments
dhvag-odoo def4d3d
[ADD] estate module: Computed Fields and Onchange (Chapter 8)
dhvag-odoo fa2ac6b
[ADD] estate module: Completed (Chapter 9 and 10)
dhvag-odoo 0c7c7f7
[ADD] estate module: Completed (Chapter 11)
dhvag-odoo 332bd11
[ADD] estate module: Completed Task: Property Maintenance Requests
dhvag-odoo 6ec0905
[ADD] estate module: Completed (Chapter 12 & 13)
dhvag-odoo d71b031
[ADD] estate module: Completed (Chapter 14 & 15)
dhvag-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
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,23 @@ | ||
| { | ||
| 'name': "Estate", | ||
| 'version': '1.0', | ||
| 'depends': ['base'], | ||
| 'author': 'Dhrudeep', | ||
| 'description': """ | ||
| This module provides functionality to manage real estate properties. | ||
| """, | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_maintenance_requests_view.xml', | ||
| 'views/estate_investor_profile_view.xml', | ||
| 'views/estate_res_users_view.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| 'category': 'Tutorial', | ||
| '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,7 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_property_maintenance_requests | ||
| from . import res_users | ||
| from . import estate_investor_profile |
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 EstatePropertyInvestor(models.Model): | ||
| _name = 'estate.property.investor' | ||
| _description = 'Estate Property investor' | ||
|
|
||
| name = fields.Many2one('res.partner', string="investor") | ||
| property_ids = fields.One2many('estate.property', 'buyer_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,137 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Estate Property Planning' | ||
| _order = 'id desc' # defaultvalue = asc | ||
|
|
||
| name = fields.Char(required=True, default="Unknown") | ||
| description = fields.Text() | ||
| postcode = fields.Float() | ||
| date_availability = fields.Date( | ||
| "Available From", copy=False, default=lambda self: fields.Date.today() + relativedelta(months=3) | ||
| ) | ||
| 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"), | ||
| ('west', "West"), | ||
| ('east', "East"), | ||
| ('south', "South"), | ||
| ], | ||
| help="Direction for the garden" | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ('new', "New"), | ||
| ('offer_received', "Offer Received"), | ||
| ('offer_accepted', "Offer Accepted"), | ||
| ('sold', "Sold"), | ||
| ('cancelled', "Cancelled"), | ||
| ], | ||
| string="Status", | ||
| default='new', | ||
| ) | ||
| property_type_id = fields.Many2one( | ||
| 'estate.property.type', string="Property Type") | ||
| seller_id = fields.Many2one( | ||
| 'res.users', string="Salesman", default=lambda self: self.env.user | ||
| ) | ||
| buyer_ids = fields.Many2one( | ||
| 'res.partner', string="Partner/Buyer", copy=False) | ||
| tags_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( | ||
| "Best offer", compute='_compute_best_price', store=True) | ||
| property_maintenance_requests = fields.One2many( | ||
| 'estate.property.maintenance.requests', 'property_id') | ||
| total_maintenance_cost = fields.Float( | ||
| compute='_compute_total_maintenance_cost', string="Total Maintenance Cost") | ||
| is_favorite = fields.Boolean(string="Favorite") | ||
|
|
||
| # SQL Constraint | ||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', "The expected price must be strictly positive") | ||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', "The selling price must be positive") | ||
|
|
||
| # Python Constriant | ||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_price(self): | ||
| if self.buyer_ids and self.selling_price < (self.expected_price * 0.9): | ||
| raise ValidationError( | ||
| "The selling price must be at least 90% of the expected price! You must reduce the expected price if you want to accept this offer.") | ||
|
|
||
| # Compute Methods | ||
| # Depends Decorator | ||
| @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): | ||
| result = dict(self.env['estate.property.offer']._read_group( | ||
| [('property_id', 'in', self.ids)], | ||
| ['property_id'], | ||
| ['price:max'] | ||
| )) | ||
| for record in self: | ||
| record.best_price = result.get(record, 0) | ||
|
|
||
| @api.depends('property_maintenance_requests.cost') | ||
| def _compute_total_maintenance_cost(self): | ||
| result = dict(self.env['estate.property.maintenance.requests']._read_group( | ||
| [('property_id', 'in', self.ids)], | ||
| ['property_id'], | ||
| ['cost:sum'] | ||
| )) | ||
| for record in self: | ||
| record.total_maintenance_cost = result.get(record, 0) | ||
|
|
||
| # Onchange Decorator | ||
| @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 | ||
|
|
||
| # Action Methods | ||
| def action_sold(self): | ||
| if 'cancelled' in self.mapped('state'): | ||
| raise UserError("Cancelled properties cannot be sold.") | ||
| else: | ||
| for record in self: | ||
| if record.property_maintenance_requests.status != 'done': | ||
| raise UserError( | ||
| "Property cannot be sold if there is any maintenance request not done.") | ||
| return self.write({'state': 'sold'}) | ||
|
|
||
| def action_cancel(self): | ||
| if 'sold' in self.mapped('state'): | ||
| raise UserError("Sold properties cannot be cancelled.") | ||
| return self.write({'state': 'cancelled'}) | ||
|
|
||
| # Ondelete Decorator | ||
| @api.ondelete(at_uninstall=False) | ||
| def _check_state(self): | ||
| for record in self: | ||
| if record.state in ('offer_received', 'offer_accepted'): | ||
| raise UserError( | ||
| "Only new and canceled properties 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,23 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError | ||
|
|
||
|
|
||
| class EstatePropertyMaintenanceRequests(models.Model): | ||
| _name = 'estate.property.maintenance.requests' | ||
| _description = 'Estate Property Maintenance Requests' | ||
|
|
||
| title = fields.Char() | ||
| cost = fields.Float() | ||
| status = fields.Selection( | ||
| default='new', | ||
| copy=False, | ||
| selection=[('new', "New"), ('approved', "Approved"), ('done', "Done")], | ||
| ) | ||
| property_id = fields.Many2one('estate.property', required=True) | ||
|
|
||
| # Constraint Decorator | ||
| @api.constrains('status', 'cost') | ||
| def _check_cost(self): | ||
| if self.status == 'approved' and self.cost <= 0: | ||
| raise ValidationError( | ||
| "The 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,80 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import api, fields, models | ||
|
|
||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = 'Estate Property offer' | ||
| # _order = 'price desc' | ||
|
|
||
| price = fields.Float("Price") | ||
| status = fields.Selection( | ||
| copy=False, | ||
| selection=[('accepted', "Accepted"), ('refused', "Refused")], | ||
| ) | ||
| partner_id = fields.Many2one( | ||
| 'res.partner', string="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') | ||
| property_type_id = fields.Many2one( | ||
| related='property_id.property_type_id', store=True) | ||
|
|
||
| # SQL Constraint | ||
| _check_offer_price = models.Constraint( | ||
| 'CHECK(price > 0)', "The selling price must be positive") | ||
|
|
||
| # Compute Methods | ||
| # Depends Decorator | ||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| date = offer.create_date.date() if offer.create_date else fields.Date.today() | ||
| offer.date_deadline = date + relativedelta(days=offer.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| start_date = ( | ||
| record.create_date.date() if record.create_date else fields.Date.today() | ||
| ) | ||
| record.validity = (record.date_deadline - start_date).days | ||
|
|
||
| # Model Decorator | ||
| @api.model | ||
| def create(self, vals): | ||
| for vals in vals: | ||
| property_id = vals.get('property_id') | ||
| if property_id: | ||
| result = self.env['estate.property.offer']._read_group( | ||
| [('property_id', '=', property_id)], | ||
| [], | ||
| ['price:max'] | ||
| ) | ||
| max_offer = result[0][0] if result else 0.0 | ||
| if vals.get('price', 0.0) <= max_offer: | ||
| raise UserError( | ||
| "The offer must be higher than existing offers.") | ||
| self.env['estate.property'].browse( | ||
| property_id).state == 'offer_received' | ||
| return super().create(vals) | ||
|
|
||
| # Action Funcitons | ||
| def action_accept(self): | ||
| for record in self: | ||
| if record.property_id.state != 'offer_accepted': | ||
| record.status = 'accepted' | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_ids = self.partner_id | ||
| record.property_id.state = 'offer_accepted' | ||
| else: | ||
| raise UserError('One offer has already been accepted') | ||
dhvag-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| record.status = 'refused' | ||
| record.property_id.state = 'new' | ||
| record.property_id.selling_price = '0' | ||
| record.property_id.buyer_ids = None | ||
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,29 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = 'Estate Property Tag' | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer("Color Index") | ||
|
|
||
| # SQL Constraint | ||
| _check_name = models.Constraint('UNIQUE(name)', "The name must be unique") | ||
|
|
||
| local_datetime = fields.Char( | ||
| compute='_compute_local_datetime', store=True) | ||
|
|
||
| # Copmute Method - Depends Decorator | ||
| @api.depends('create_date') | ||
| def _compute_local_datetime(self): | ||
| for record in self: | ||
| if record.create_date: | ||
| # user_tz = self.env.user.tz or 'Asia/Kolkata' | ||
| local_dt = fields.Datetime.context_timestamp( | ||
| record, record.create_date | ||
| ) | ||
| record.local_datetime = local_dt.strftime("%Y-%m-%d %H:%M:%S") | ||
| else: | ||
| record.local_datetime = False |
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,26 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow this conventions while declaring fields, constraints, methods or CRUD operations. |
||
| _name = 'estate.property.type' | ||
| _description = 'Estate Property Type' | ||
| _order = 'name' | ||
| # _rec_name = 'id' | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer(default=10) | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
| offer_count = fields.Integer(compute='_compute_offer_count') | ||
|
|
||
| # Depends Decorator | ||
| @api.depends('offer_ids') | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) | ||
|
|
||
| # SQL Constarint | ||
| _check_name = models.Constraint('unique(name)', "The name must be unique") | ||
|
|
||
| # For Inline View | ||
| property_ids = fields.One2many( | ||
| "estate.property", "property_type_id", string="Properties") | ||
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 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many('estate.property', 'seller_id') | ||
| name = fields.Char() | ||
|
|
||
| prices = fields.One2many( | ||
| 'estate.property', 'seller_id') | ||
| total_unsold_value = fields.Float( | ||
| compute='_compute_total_unsold_value') | ||
|
|
||
| @api.depends('prices.expected_price', 'prices.state') | ||
| def _compute_total_unsold_value(self): | ||
| for record in self: | ||
| unsold_prices = record.prices.filtered(lambda p: p.state != 'sold') | ||
| record.total_unsold_value = ( | ||
| sum(unsold_prices.mapped('expected_price') | ||
| ) if unsold_prices else 0.0 | ||
| ) |
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 @@ | ||
| id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_estate_model,access_estate_model,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1 | ||
| access_estate_property_maintenance_requests,access_estate_property_maintenance_requests,model_estate_property_maintenance_requests,base.group_user,1,1,1,1 | ||
| access_estate_property_investor,access_estate_property_investor,model_estate_property_investor,base.group_user,1,1,1,1 |
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.