-
Notifications
You must be signed in to change notification settings - Fork 2.8k
auber - Technical Training #1058
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
aurb9
wants to merge
19
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-auber
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.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c95998a
[ADD] Chapter 2 - Add app
aurb9 1fd3b26
[REV] Fix build
aurb9 48f899f
[FIX] Fix build
aurb9 fee6b56
[ADD] Chapter 3
aurb9 057d77f
[ADD] Chapter 4 - Add security
aurb9 0e1ffa3
[IMP] Chapter 5 - Add UI
aurb9 80c6911
[IMP] Chapter 6 - Add custom views
aurb9 c551f66
[FIX] Fix parsing error in group by view
aurb9 793b0cc
[FIX] Fix parsing error in group by view
aurb9 f578c54
[MERGE] Merge remote-tracking branch 'dev/19.0-tutorials-auber' into …
aurb9 fbf913f
[IMP] estate: remember last sold price for statistics
barracudapps 8da414a
[FIX] estate: unfreeze field date
barracudapps 1de0fde
[IMP] Chapter 7 - Add relational models
aurb9 8115ce2
[IMP] estate: add compute, inverse and onchange methods
aurb9 648390f
[IMP] estate: add action buttons on property and property_offer
aurb9 e98208e
[IMP] estate: add SQL and Python constraints to the models
aurb9 c0bed00
[IMP] estate: add SQL and Python constraints to the models
aurb9 724803e
[MERGE] Merge remote-tracking branch 'dev/19.0-tutorials-auber' into …
aurb9 d8ce950
[IMP] estate: allow buttons to disappear conditionally and add offer …
aurb9 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,17 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'depends': ['base'], | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
|
|
||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_menus.xml', | ||
| ], | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'author': "Odoo", | ||
| 'license': 'AGPL-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 @@ | ||
| from . import property, property_offer, property_tag, property_type |
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,109 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools import float_compare, float_is_zero | ||
|
|
||
|
|
||
| class Property(models.Model): | ||
| _name = 'estate.property' | ||
| _description = "Estate property" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(string="Title", required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| string="Available From", | ||
| default=lambda self: fields.Date.today() + relativedelta(months=3), | ||
| copy=False, | ||
| ) | ||
| 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'), ('south', 'South'), ('east', 'East'), ('west', 'West')] | ||
| ) | ||
| state = fields.Selection( | ||
| default="new", | ||
| string="Status", | ||
| selection=[ | ||
| ('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled'), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| property_type_id = fields.Many2one('estate.property.type', string="Property Type") | ||
| partner_id = fields.Many2one('res.partner', string="Buyer", readonly=True) | ||
| user_id = fields.Many2one('res.users', string="Salesman", default=lambda self: self.env.user) | ||
| tag_ids = fields.Many2many('estate.property.tag', string="Property Tags") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers") | ||
| total_area = fields.Integer(string="Total Area (sqm)", compute='_compute_total_area') | ||
| best_offer = fields.Float(default=0.0, compute="_compute_best_offer") | ||
|
|
||
| _expected_price_strictly_pos = models.Constraint( | ||
| "CHECK(expected_price > 0)", "The expected price must be strictly positive." | ||
| ) | ||
| _selling_price_pos = models.Constraint( | ||
| "CHECK(selling_price >= 0)", "The 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') | ||
| def _compute_best_offer(self): | ||
| for record in self: | ||
| record.best_offer = max(record.offer_ids.mapped('price')) if record.offer_ids else 0.0 | ||
|
|
||
| @api.onchange('garden') | ||
| def _onchange_garden(self): | ||
| self.garden_area = 10 if self.garden else 0 | ||
| self.garden_orientation = 'north' if self.garden else '' | ||
|
|
||
| @api.onchange("offer_ids") | ||
| def _onchange_state(self): | ||
| if not self.offer_ids: | ||
| return | ||
|
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. I think you might need to update |
||
|
|
||
| self.state = 'offer_received' | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if ( | ||
| not float_is_zero(record.selling_price, precision_digits=2) and | ||
| float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1 | ||
| ): | ||
| raise ValidationError( | ||
| self.env._( | ||
| "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." | ||
| ) | ||
| ) | ||
|
|
||
| def action_set_sold(self): | ||
| if self.state == 'cancelled': | ||
| raise UserError(self.env._("Cancelled properties cannot be sold.")) | ||
|
|
||
| self.state = 'sold' | ||
| return True | ||
|
|
||
| def action_set_cancelled(self): | ||
| if self.state == 'sold': | ||
| raise UserError(self.env._("Sold properties cannot be cancelled.")) | ||
|
|
||
| self.state = 'cancelled' | ||
| return 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,48 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class PropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = "Property Offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False) | ||
| partner_id = fields.Many2one('res.partner', required=True) | ||
| property_id = fields.Many2one('estate.property', required=True) | ||
| property_type_id = fields.Many2one(related='property_id.property_type_id', store=True) | ||
| validity = fields.Integer(default=7, string="Validity (days)") | ||
| deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline') | ||
|
|
||
| _price_pos = models.Constraint( | ||
| "CHECK(price > 0)", "The offer price must be strictly positive." | ||
| ) | ||
|
|
||
| @api.depends('validity') | ||
| def _compute_deadline(self): | ||
| for record in self: | ||
| create_date = record.create_date or fields.Date.today() | ||
| record.deadline = create_date + relativedelta(days=record.validity) | ||
|
|
||
| def _inverse_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.deadline - fields.Date.to_date(record.create_date)).days | ||
|
|
||
| def action_confirm(self): | ||
| self.status = 'accepted' | ||
| for offer in self.property_id.offer_ids: | ||
| if offer.id == self.id: | ||
| continue | ||
|
|
||
| offer.status = 'refused' | ||
|
|
||
| self.property_id.state = 'offer_accepted' | ||
| self.property_id.partner_id = self.partner_id | ||
| self.property_id.selling_price = self.price | ||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| self.status = 'refused' | ||
| return 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,12 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class PropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = "Property Tag" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() | ||
|
|
||
| _name_uniq = models.Constraint("UNIQUE(name)", "The name 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,20 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class PropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = "Property Type" | ||
| _order = "sequence desc, name" | ||
|
|
||
| name = fields.Char(required=True) | ||
| property_ids = fields.One2many('estate.property', 'property_type_id') | ||
| sequence = fields.Integer(help="Used to order property types. Higher is better.") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
| offer_count = fields.Integer(compute='_compute_offer_count') | ||
|
|
||
| _name_uniq = models.Constraint("UNIQUE(name)", "The name 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,5 @@ | ||
| 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 |
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,12 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_property_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_property_advertisements_menu" name="Advertisements"> | ||
| <menuitem id="estate_property_model_menu_action" action="estate_property_model_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_property_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_model_menu_action" action="estate_property_type_model_action"/> | ||
| <menuitem id="estate_property_tag_model_menu_action" action="estate_property_tag_model_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,44 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_offer_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.form</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Offer"> | ||
| <sheet> | ||
| <group> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="deadline"/> | ||
| </group> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.offer.list</field> | ||
| <field name="model">estate.property.offer</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Offer" editable="bottom" decoration-success="status == 'accepted'" | ||
| decoration-danger="status == 'refused'"> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="deadline"/> | ||
| <button name="action_confirm" type="object" title="Accept" icon="fa-check" invisible="status"/> | ||
| <button name="action_refuse" type="object" title="Refuse" icon="fa-times" invisible="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_model_action" model="ir.actions.act_window"> | ||
| <field name="name">Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list,form</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</field> | ||
| </record> | ||
| </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,32 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_tag_model_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.form</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Tag"> | ||
| <sheet> | ||
| <group> | ||
| <field name="name"/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.tag.list</field> | ||
| <field name="model">estate.property.tag</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Tag" editable="bottom"> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_tag_model_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
| </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,57 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_type_view_form" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.form</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <form string="Property Type"> | ||
| <sheet> | ||
| <div name="button_box"> | ||
| <button name="%(estate.estate_property_offer_model_action)d" type="action" | ||
| class="oe_stat_button" icon="fa-id-card-o"> | ||
| <div class="o_field_widget o_stat_info"> | ||
| <span class="o_stat_value"> | ||
| <field name="offer_count"/> | ||
| </span> | ||
| <span class="o_stat_text">Offers</span> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| <div class="oe_title"> | ||
| <h1 class="mb32"> | ||
| <field name="name" class="mb16"/> | ||
| </h1> | ||
| </div> | ||
| <notebook> | ||
| <page name="Properties"> | ||
| <field name="property_ids" readonly="True"> | ||
| <list string="Properties" delete="False"> | ||
| <field name="name"/> | ||
| <field name="expected_price"/> | ||
| <field name="state"/> | ||
| </list> | ||
| </field> | ||
| </page> | ||
| </notebook> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_view_list" model="ir.ui.view"> | ||
| <field name="name">estate.property.type.list</field> | ||
| <field name="model">estate.property.type</field> | ||
| <field name="arch" type="xml"> | ||
| <list string="Property Type"> | ||
| <field name="sequence" widget="handle"/> | ||
| <field name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_type_model_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Types</field> | ||
| <field name="res_model">estate.property.type</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.
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.
This is a technical string 😉