-
Notifications
You must be signed in to change notification settings - Fork 3.3k
PR Onboarding toher #1367
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
Tom-Hermann
wants to merge
26
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-onboarding-chap2-toher
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
PR Onboarding toher #1367
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2ab5699
[ADD] Chapt 2
Tom-Hermann f658a83
[ADD] Chapter 3 exercices
Tom-Hermann 4337d07
[ADD] cahp4
Tom-Hermann 819ced7
[REM] space in csv
Tom-Hermann 6126617
[ADD] Chapter 5
Tom-Hermann e9dae69
[FIX] ci style errors
Tom-Hermann daef999
[ADD] Chap 6
Tom-Hermann ee0e11c
[FIX] Typo (sate -> state); add name of filer
Tom-Hermann 556a80d
[CLN] Property class and file name
Tom-Hermann e08ecd9
[ADD] Chap 7
Tom-Hermann 64ca61d
[ADD] Chap 8
Tom-Hermann baba364
[ADD] Chap 9
Tom-Hermann e28e0a2
[ADD] Chap 11
Tom-Hermann 81a3c70
[ADD] Chapt 11
Tom-Hermann d7a7202
[ADD] Chapt 11
Tom-Hermann a6c6851
[ADD] Chapt 12
Tom-Hermann c1ba2ab
[ADD] manifest
Tom-Hermann 32bc48a
[ADD] Chapt 14
Tom-Hermann f66b98a
[ADD] Chapt 14
Tom-Hermann f4ece5c
[FIX] Coding style
Tom-Hermann 88107c8
[FIX] manifest loading order
Tom-Hermann dc70b21
[FIX] Error indent
Tom-Hermann 34b4daf
[FIX] Default date define by lambda
Tom-Hermann 42cc613
[FIX] estate: Reviewers comments
Tom-Hermann ca92311
[FIX] estate: res_users file name
Tom-Hermann ea2fa2b
[FIX] estate: ci/style
Tom-Hermann 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,4 @@ | ||
| { | ||
| "xml.symbols.enabled": false, | ||
| "python.languageServer": "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 @@ | ||
| 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', | ||
| 'depends': ['base'], | ||
| 'application': True, | ||
| 'author': 'toher', | ||
| 'license': 'LGPL-3', | ||
|
|
||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'view/estate_property_offer_view.xml', | ||
| 'view/estate_property_views.xml', | ||
| 'view/estate_property_type_view.xml', | ||
| 'view/estate_property_tag_view.xml', | ||
| 'view/res_users.xml', | ||
| 'view/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,5 @@ | ||
| from . import estate_property | ||
| from . import estate_type | ||
| from . import estate_tag | ||
| from . import estate_offer | ||
| from . import res_user |
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,70 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo.exceptions import UserError | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Offer" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| string="Status", | ||
| selection=[ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused"), | ||
| ("new", "New") | ||
| ], | ||
| copy=False, | ||
| default="new" | ||
| ) | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
| partner_id = fields.Many2one("res.partner", string="Buyer", required=True) | ||
| property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
| validity = fields.Integer(string="Validity", default=7) | ||
| date_deadline = fields.Date(string="Deadline", compute="_compute_dead_line", inverse="_inverse_validity") | ||
|
|
||
| _check_positif_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The price must be positive' | ||
| ) | ||
|
|
||
| property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| property = self.env["estate.property"].browse(vals["property_id"]) | ||
| property.set_offer_received() | ||
| all_prices = property.proterty_offer_ids.mapped('price') | ||
| max_price = all_prices[0] if all_prices else 0 | ||
| if max_price and max_price >= vals['price']: | ||
| raise UserError(self.env._("New offer can't be lower than an other offer")) | ||
| return super().create(vals_list) | ||
|
|
||
| @api.depends("validity") | ||
| def _compute_dead_line(self): | ||
| for offer in self: | ||
| offer.date_deadline = fields.Date.today() + timedelta(days=offer.validity) | ||
|
|
||
| def _inverse_validity(self): | ||
| for offer in self: | ||
| difference = (offer.create_date.date() - fields.Date.today()) | ||
| offer.validity = difference.days | ||
|
|
||
| def action_accept_offer(self): | ||
| for offer in self: | ||
| if offer.status == "refused": | ||
| raise UserError(self.env._("Can't accept an refused offer")) | ||
| offer.status = "accepted" | ||
| offer.property_id.accept_offer() | ||
| return True | ||
|
|
||
| def action_refuse_offer(self): | ||
| for offer in self: | ||
| if offer.status == "accepted": | ||
| raise UserError(self.env._("Can't refuse an accepted offer")) | ||
| offer.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,133 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo.tools import float_utils | ||
|
|
||
| from odoo import api, exceptions, fields, models | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Estate Property Module" | ||
| _order = "id desc" | ||
|
|
||
| _check_positif_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The expected price must be strictly positive' | ||
| ) | ||
| _check_positif_selling_price = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| 'The selling price must be positive' | ||
| ) | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
|
|
||
| # Base Fields | ||
| name = fields.Char(string="Title", required=True) | ||
| description = fields.Text(string="Description") | ||
| postcode = fields.Char(string="Postcode") | ||
| expected_price = fields.Float(string="Expected Price", required=True) | ||
| selling_price = fields.Float(string="Selling Price", copy=False, readonly=True) | ||
| best_price = fields.Integer(string="Best Price", compute="_compute_best_price") | ||
| expected_date = fields.Date( | ||
| string="Expected Date", | ||
| required=True, | ||
| copy=False, | ||
| default=lambda _: (fields.Date.today() + timedelta(days=90)), | ||
| ) | ||
| bedroom = fields.Integer(string="Number of Bedroom", default=2) | ||
| living_area = fields.Integer(string="Living area (square metter)") | ||
| facades = fields.Integer(string="Number of facades") | ||
| garage = fields.Boolean(string="Have a garage?") | ||
| garden = fields.Boolean(string="Have a garden?") | ||
| garden_area = fields.Integer(string="Garden area (square metter)") | ||
| garden_orientation = fields.Selection( | ||
| string="Garden's orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", " East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| total_area = fields.Integer(string="Total Area", compute="_compute_total_area") | ||
| state = fields.Selection( | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
| string="Estate's state", | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", " Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| copy=False | ||
| ) | ||
| salesman_id = fields.Many2one( | ||
| "res.users", | ||
| string="Salesman", | ||
| default=lambda self: self.env.user | ||
| ) | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Type") | ||
| property_tag_ids = fields.Many2many("estate.property.tag", string="Tag") | ||
| proterty_offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
| active = fields.Boolean(default=True) | ||
|
|
||
| @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('proterty_offer_ids.price') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| all_prices = record.proterty_offer_ids.mapped('price') | ||
| record.best_price = all_prices[0] if all_prices else 0 | ||
|
|
||
| @api.onchange("garden") | ||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = 'north' | ||
| else: | ||
| self.garden_area = 0 | ||
| self.garden_orientation = '' | ||
|
|
||
| @api.constrains("selling_price", "expected_price") | ||
| def _check_price_expectation(self): | ||
| for record in self: | ||
| if float_utils.float_is_zero(record.selling_price, 2): | ||
| return True | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
| if float_utils.float_compare(record.selling_price, record.expected_price * 0.9, 2) == -1: | ||
| raise exceptions.ValidationError(self.env._("Selling price can't be smaller than 90% of the expected price")) | ||
| return True | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def delete(self): | ||
| for record in self: | ||
| if record.state not in {"new", "cancelled"}: | ||
| raise exceptions.UserError(self.env._(f"Can't delete an advertise in {record.state} state")) | ||
|
|
||
| def action_sold_adv(self): | ||
| for advertisements in self: | ||
| if advertisements.state == "cancelled": | ||
| raise exceptions.UserError(self.env._("Can't sold an canceled advertise")) | ||
| advertisements.state = "sold" | ||
| return True | ||
|
|
||
| def action_cancel_adv(self): | ||
| for advertisements in self: | ||
| if advertisements.state == "sold": | ||
| raise exceptions.UserError(self.env._("Can't cancel an sold advertise")) | ||
| advertisements.state = "cancelled" | ||
| return True | ||
|
|
||
| def accept_offer(self): | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
| for advertise in self: | ||
| accepted_offer = advertise.proterty_offer_ids.filtered(lambda r: r.status == 'accepted') | ||
| advertise.buyer_id = accepted_offer.partner_id | ||
| advertise.selling_price = accepted_offer.price | ||
| advertise.state = 'offer_accepted' | ||
| (advertise.proterty_offer_ids - accepted_offer).action_refuse_offer() | ||
|
|
||
| def set_offer_received(self): | ||
| for advertise in self: | ||
| advertise.state = "offer_received" | ||
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 = "Estate Tag" | ||
| _order = "name" | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| "Another tag already exists with the same name!" | ||
| ) | ||
|
|
||
| name = fields.Char(string="Tag") | ||
| color = fields.Integer() |
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 EstateType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Type" | ||
| _order = "sequence" | ||
|
|
||
| _check_unique_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| "Another type already exists with the same name!" | ||
| ) | ||
|
|
||
| name = fields.Char(string="Type", required=True) | ||
| property_ids = fields.One2many('estate.property', 'property_type_id') | ||
| sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id') | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
Comment on lines
+14
to
+18
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. |
||
|
|
||
| @api.depends('offer_ids') | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_ids) | ||
|
Tom-Hermann marked this conversation as resolved.
|
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", "salesman_id") | ||
|
Tom-Hermann marked this conversation as resolved.
|
||
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_model,access_estate_model,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_type_model,access_state_type_model,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_tag_model,access_state_tag_model,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_offer_model,access_state_offer_model,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,14 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <menuitem id="estate_menu_root" name="Estate Root"> | ||
| <menuitem id="estate_advertisements_menu" name="Advertisements"> | ||
| <menuitem id="estate_model_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_type_menu_action" action="estate_type_action"/> | ||
| <menuitem id="estate_tag_menu_action" action="estate_tag_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,27 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <record id="estate_property_offers_action" model="ir.actions.act_window"> | ||
| <field name="name">Property Offers</field> | ||
| <field name="res_model">estate.property.offer</field> | ||
| <field name="view_mode">list</field> | ||
| <field name="domain">[('property_type_id', '=', active_id)]</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 Offers" | ||
| decoration-danger="status == 'refused'" | ||
| decoration-success="status == 'accepted'" | ||
| create="false"> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <button name="action_accept_offer" string="Confirm" type="object" icon="fa-check" invisible="status != 'new'"/> | ||
| <button name="action_refuse_offer" string="Cancel" type="object" icon="fa-times" invisible="status != 'new'"/> | ||
| </list> | ||
| </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,19 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <record id="estate_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Estate Tag</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
| <!-- List view --> | ||
| <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="Tags" editable="bottom"> | ||
| <field name="name"/> | ||
| </list> | ||
| </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.
Keep in mind that this is usually Odoo, since we work here.