-
Notifications
You must be signed in to change notification settings - Fork 2.8k
19.0 tutorials mekav #1095
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
mekav-odoo
wants to merge
12
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-mekav
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 mekav #1095
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3f42781
[ADD] estate: create module real-estate. chapter 1,2
mekav-odoo a2afb92
[IMP] estate: configure database and add security
mekav-odoo 363b4bf
[IMP] estate: complete ch-5 and start ch-6
mekav-odoo 9821fb8
[IMP] estate: complete ch-10 up to Attributes and options
mekav-odoo 5f64341
[IMP] estate: complete ch-11 up to Attributes and options
mekav-odoo 1e40a8a
[IMP] estate: complete ch-11
mekav-odoo 9881d31
[IMP] estate: complete ch-11
mekav-odoo 69ca8c9
[IMP] estate: complete practice task (maintenance)
mekav-odoo ba96830
[IMP] estate: complete practice task (maintenance)
mekav-odoo 8657fde
[IMP] estate: start with ch-12 inheritance
mekav-odoo 2bfaa51
[IMP] estate: complete ch-12 Inheritance
mekav-odoo 8950231
[FIX] estate: fix all merge issues
mekav-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,23 @@ | ||
| { | ||
| 'name': "estate", | ||
| 'description': "A real-estate application", | ||
| 'author': "meet kavathiya", | ||
| 'website': "https://www.odoo.com/", | ||
| 'category': "Real-estate", | ||
| 'version': "0.1", | ||
| 'application': True, | ||
| 'installable': True, | ||
| 'depends': ['base'], | ||
| '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_maintenance_request_views.xml", | ||
| "views/estate_property_views.xml", | ||
| "views/res_users_view.xml", | ||
| "views/estate_menus.xml", | ||
| ], | ||
| 'assets': {}, | ||
| 'license': "LGPL-3", | ||
| } |
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_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_maintenance_request | ||
| 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,23 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| class EstatePropertyMaintenanceRequest(models.Model): | ||
| _name = 'estate.property.maintenance.request' | ||
| _description = "estate property maintenance" | ||
|
|
||
| cost = fields.Float() | ||
| tital = fields.Char() | ||
| status = fields.Selection( | ||
| [('new', "New"), ('approved', "Approved"), ('done', "Done")], copy=False | ||
| ) | ||
| property_id = fields.Many2one('estate.property', required=True) | ||
| _chek_cost = models.Constraint( | ||
| "CHECK(cost >= 0)", "cost of property should be positive" | ||
| ) | ||
|
|
||
| @api.constrains('cost', 'status') | ||
| def _check_cost(self): | ||
| for record in self: | ||
| if record.status == 'approved' and not record.cost > 0: | ||
| raise ValidationError("cost should be grater than 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,137 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| 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( | ||
| copy=False, default=fields.Date.add(fields.Date.today(), months=3) | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(copy=False, readonly=True) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer() | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| [ | ||
| ('new', "New"), | ||
| ('offer_received', "Offer Received"), | ||
| ('offer_accepted', "Offer Accepted"), | ||
| ('sold', "Sold"), | ||
| ('cancelled', "Cancelled"), | ||
| ], | ||
| required=True, | ||
| default='new', | ||
| copy=False, | ||
| ) | ||
| garden_orientation = fields.Selection( | ||
| selection=[ | ||
| ('north', "North"), | ||
| ('south', "South"), | ||
| ('east', "East"), | ||
| ('west', "West"), | ||
| ], | ||
| ) | ||
| property_type = fields.Many2one('estate.property.type', string="property type") | ||
| salesman_id = fields.Many2one( | ||
| 'res.users', string="Salesman", default=lambda self: self.env.user | ||
| ) | ||
| buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False) | ||
| tag_ids = fields.Many2many('estate.property.tag') | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id') | ||
| maintenance_request_ids = fields.One2many( | ||
| 'estate.property.maintenance.request', 'property_id' | ||
| ) | ||
| total_area = fields.Float(compute='_compute_total_area', store=True) | ||
| best_price = fields.Float(compute='_compute_best_price') | ||
| total_maintenance_cost = fields.Float(compute='_compute_total_maintenance_cost') | ||
| _chek_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", "Expected price of property should be positive" | ||
| ) | ||
| _chek_selling_price = models.Constraint( | ||
| "CHECK(selling_price >= 0)", "selling price of property should 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: | ||
| record.best_price = max(record.offer_ids.mapped('price'), default=0.0) | ||
|
|
||
| @api.onchange('garden') | ||
| def _onchnage_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = 'north' | ||
| else: | ||
| self.garden_area = 0 | ||
| self.garden_orientation = False | ||
|
|
||
| def action_property_sold(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise UserError("cancelled property cannot be sold") | ||
|
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. Explain the events where should I use UserError and ValidationError? |
||
| else: | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| def action_property_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError("sold property cannot be cancelled") | ||
| else: | ||
| record.state = 'cancelled' | ||
| return True | ||
|
|
||
| @api.constrains('selling_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if ( | ||
| record.selling_price | ||
| and float_compare( | ||
| record.selling_price, | ||
| record.expected_price * 0.9, | ||
| precision_digits=2, | ||
| ) | ||
| == -1 | ||
| ): | ||
| raise ValidationError( | ||
| "Selling price should not be less than 90% of expected price" | ||
| ) | ||
|
|
||
| @api.depends('maintenance_request_ids.cost') | ||
| def _compute_total_maintenance_cost(self): | ||
| for record in self: | ||
| record.total_maintenance_cost = sum( | ||
| record.maintenance_request_ids.mapped('cost') | ||
| ) | ||
|
|
||
| @api.constrains('state') | ||
| def _check_state(self): | ||
| for record in self: | ||
| if record.state == 'sold' and record.maintenance_request_ids.filtered( | ||
| lambda r: r.status != 'done' | ||
| ): | ||
| raise ValidationError( | ||
| "All maintenance request should be done before property marked as sold" | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_cancelled(self): | ||
| if any(record.state not in ['new','cancelled'] for record in self): | ||
| 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,62 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = "estate property offers" | ||
| _order = 'price desc' | ||
|
|
||
| price = fields.Float() | ||
| status = fields.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) | ||
| property_type_id = fields.Many2one( | ||
| 'estate.property.type', related='property_id.property_type', store=True | ||
| ) | ||
| date_deadline = fields.Date( | ||
| compute='_compute_date_deadline', inverse='_inverse_date_deadline' | ||
| ) | ||
| _chek_offer_price = models.Constraint( | ||
| "CHECK(price > 0)", "offer price of property should be positive" | ||
| ) | ||
|
|
||
| @api.depends('validity') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = fields.Date.add( | ||
| record.create_date or fields.Date.today(), days=record.validity | ||
| ) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| def action_accept(self): | ||
| for record in self: | ||
| if record.property_id.selling_price: | ||
| raise UserError("One offer is already Accepted") | ||
| else: | ||
| record.status = 'accepted' | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = 'offer_accepted' | ||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| for record in self: | ||
| if record.status == 'accepted': | ||
| record.property_id.selling_price = False | ||
| record.status = 'refused' | ||
| return True | ||
|
|
||
| @api.model | ||
| def create(self, vals): | ||
| for val in vals: | ||
| if self.env['estate.property'].browse(val['property_id']).offer_ids.filtered(lambda x: x.price > val['price']): | ||
| raise UserError("offer amount should be grater than current offer amount.") | ||
| self.env['estate.property'].browse(val['property_id']).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,14 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = "estate property tges" | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
| _uniq_tag_name = models.Constraint( | ||
| "unique(name)", | ||
mekav-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "A tag already exist, tag should 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,22 @@ | ||||||
| from odoo import api, fields, models | ||||||
|
|
||||||
|
|
||||||
| class EstatePropertyType(models.Model): | ||||||
| _name = 'estate.property.type' | ||||||
| _description = "estate property types" | ||||||
| _order = 'name' | ||||||
|
|
||||||
| name = fields.Char(required=True) | ||||||
| property_ids = fields.One2many('estate.property', 'property_type') | ||||||
| sequence = fields.Integer() | ||||||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||||||
| offer_count = fields.Integer(compute='_compute_offer') | ||||||
|
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.
Suggested change
|
||||||
| _uniq_tag_name = models.Constraint( | ||||||
| "unique(name)", | ||||||
| "A Property Type already exist, Propert type should be unique.", | ||||||
| ) | ||||||
|
|
||||||
| @api.depends('offer_ids') | ||||||
| def _compute_offer(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 InheritedResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many('estate.property','salesman_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,7 @@ | ||
| id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_estate_property,access_estate_property,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_request,access_estate_property_maintenance_request,model_estate_property_maintenance_request,base.group_user,1,1,1,1 | ||
| access_res_users,access_res_users,model_res_users,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,15 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <menuitem id="estate_menu_root" name="Real estate"> | ||
| <menuitem id="estate_menu_advertisements" name="Advertisements"> | ||
| <menuitem id="advertisements_menu_properties" action="estate_property_model_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_menu_settings" name="Settings"> | ||
| <menuitem id="setting_menu_property_types" action="estate_property_type_model_action"/> | ||
| <menuitem id="setting_menu_property_tags" action="estate_property_tag_model_action"/> | ||
| <menuitem id="setting_menu_property_maintenance_request" action="estate_property_maintenance_request_model_action"/> | ||
| </menuitem> | ||
| </menuitem> | ||
|
|
||
| </odoo> |
38 changes: 38 additions & 0 deletions
38
estate/views/estate_property_maintenance_request_views.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,38 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_maintenance_request_model_action" model="ir.actions.act_window"> | ||
| <field name="name">Property maintenance</field> | ||
| <field name="res_model">estate.property.maintenance.request</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_maintenance_request_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.maintenance.request.view.list</field> | ||
| <field name="model">estate.property.maintenance.request</field> | ||
| <field name="arch" type="xml"> | ||
| <list> | ||
| <field name="tital"/> | ||
| <field name="status"/> | ||
| <field name="cost"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.maintenance.request.view.form</field> | ||
| <field name="model">estate.property.maintenance.request</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Offer"> | ||
| <sheet> | ||
| <group> | ||
| <field name="tital" /> | ||
| <field name="status"/> | ||
| <field name="cost"/> | ||
| <field name="property_id"/> | ||
| </group> | ||
| </sheet> | ||
| </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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this lambda function do?