-
Notifications
You must be signed in to change notification settings - Fork 3.3k
19.0 tutorial delje #1415
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
Delvaux-Jean-Baptiste
wants to merge
15
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorial-delje
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
19.0 tutorial delje #1415
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
63c3ad3
[ADD] Add the basic setup for the estate module
Delvaux-Jean-Baptiste 92218f6
[IMP] estate: Added models
Delvaux-Jean-Baptiste 2e76d0b
[FIX] Made field mandatory
Delvaux-Jean-Baptiste a2ee7f4
[FIX] Styling issues
Delvaux-Jean-Baptiste 2b37ba8
[FIX] formatting issues
Delvaux-Jean-Baptiste 52aac90
[ADD] estate: Added menus in app
Delvaux-Jean-Baptiste 861aa17
[ADD] estate: Added garden area field
Delvaux-Jean-Baptiste 6d3ba96
[IMP] estate: Added buyers, salespersons, tags and offers
Delvaux-Jean-Baptiste fc7c422
[FIX] corrections of a couple of wrong names
Delvaux-Jean-Baptiste dce0b63
[FIX] Added missing keys in manifest
Delvaux-Jean-Baptiste 0a6d7d5
[FIX] Removed unnecessary tracking in salesperson_id
Delvaux-Jean-Baptiste 679e80d
[IMP] estate: added computed fields on total_area and best price
Delvaux-Jean-Baptiste 85e2b75
[IMP] estate: Added Cancel and Sold buttons to estate
Delvaux-Jean-Baptiste a5cbecd
[IMP] estate: Added SQL constrains on selling price
Delvaux-Jean-Baptiste 70a196a
[FIX] Correction of Self inside loop
Delvaux-Jean-Baptiste 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 |
|---|---|---|
|
|
@@ -127,3 +127,4 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
| .vscode/settings.json | ||
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,16 @@ | ||
| { | ||
| 'name': "Estate", | ||
| 'author': "delje", | ||
| 'license': "LGPL-3", | ||
| 'depends': ["base"], | ||
| 'application': True, | ||
| 'installable': True, | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_menus_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,4 @@ | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| from . import estate_property |
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,103 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
|
||
|
|
||
|
msho-odoo marked this conversation as resolved.
|
||
| class EstatePropertyModel(models.Model): | ||
| _name = "estate_property" | ||
| _description = "The details of a property" | ||
|
|
||
| name = fields.Char('Estate Name', required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date(copy=False, default=fields.Date.today() + relativedelta(months=3)) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float(readonly=True) | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer(default=0) | ||
| facades = fields.Integer() | ||
| has_garage = fields.Boolean() | ||
| has_garden = fields.Boolean() | ||
| garden_area = fields.Integer(default=0) | ||
| garden_orientation = fields.Selection( | ||
| string='Garden Orientation', | ||
| selection=[ | ||
| ('east', 'East'), | ||
| ('west', 'West'), | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('', ''), | ||
| ], | ||
| ) | ||
| state = fields.Selection( | ||
| string='State', | ||
| selection=[ | ||
| ('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled'), | ||
| ], | ||
| default='new', | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| property_type_id = fields.Many2one("estate_property_type", string="Type") | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer") | ||
| salesperson_id = fields.Many2one('res.users', string='Salesperson', index=True, default=lambda self: self.env.user) | ||
| property_tags_ids = fields.Many2many("estate_property_tag", string="Tags") | ||
| offers_ids = fields.One2many("estate_property_offer", "property_id", string="Offers") | ||
| total_area = fields.Integer(compute="_compute_total_area", readonly=True) | ||
| best_price = fields.Float(compute="_compute_best_price", string="Best Offer", readonly=True) | ||
|
|
||
| @api.depends("living_area", "garden_area") | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.depends("offers_ids") | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| if record.offers_ids: | ||
| record.best_price = max(record.offers_ids.mapped('price')) | ||
| else: | ||
| record.best_price = 0 | ||
|
|
||
| @api.onchange("has_garden") | ||
| def _onchange_has_garden(self): | ||
| self.garden_area = 10 if self.has_garden else 0 | ||
| self.garden_orientation = 'south' if self.has_garden else '' | ||
|
|
||
| def action_sell_property(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| UserError("Cannot sell a cancelled property") | ||
| return False | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel_property(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| UserError("Cannot cancel a sold property") | ||
| return False | ||
| record.state = 'cancelled' | ||
| return True | ||
|
|
||
| _check_expected_price_constraint = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The price of a property must be strictly positive', | ||
| ) | ||
|
|
||
| _check_selling_price_constraint = models.Constraint( | ||
| 'CHECK(selling_price >= 0)', | ||
| 'The selling price must be positive', | ||
| ) | ||
|
|
||
| @api.constrains('selling_price', 'expected_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if (not float_is_zero(record.selling_price, 2)) and float_compare(record.selling_price, record.expected_price * 0.9, 2) < 0: | ||
| error_message = "The selling price is less than 90 percent of the asked price" | ||
| raise ValidationError(error_message) | ||
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,54 @@ | ||
| from datetime import datetime | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyOfferModel(models.Model): | ||
| _name = "estate_property_offer" | ||
| _description = "An offer for an estate" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection(string='State', | ||
| selection=[ | ||
| ('refused', 'Refused'), | ||
| ('accepted', 'Offer Accepted'), | ||
| ], | ||
| copy=False, | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Buyer") | ||
| property_id = fields.Many2one("estate_property", string="Property") | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline") | ||
|
|
||
| @api.depends("validity") | ||
| def _compute_deadline(self): | ||
| for record in self: | ||
| if record.create: | ||
| record.date_deadline = datetime.now() + relativedelta(days=record.validity) | ||
| else: | ||
| record.date_deadline = record.create_date.date() + relativedelta(days=record.validity) | ||
|
|
||
| def _inverse_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| @api.depends("property_id") | ||
| def action_accept_offer(self): | ||
| for record in self: | ||
| if record.status == "accepted" or record.property_id.state in ['cancelled', 'sold', 'offer_accepted']: | ||
| return False | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.state = 'offer_accepted' | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.status = 'accepted' | ||
| return True | ||
|
|
||
| @api.depends("property_id") | ||
| def action_refuse_offer(self): | ||
| for record in self: | ||
| if record.property_id.state in ['cancelled', 'sold']: | ||
| return False | ||
| record.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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTagModel(models.Model): | ||
| _name = "estate_property_tag" | ||
| _description = "The tag of an estate" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'A property tag 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,13 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTypeModel(models.Model): | ||
| _name = "estate_property_type" | ||
| _description = "The type of an estate" | ||
|
|
||
| name = fields.Char(required=True) | ||
|
|
||
| _unique_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'A property tag 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,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_estate_type_model,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_tag_model,access_estate_tag_model,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_offer_model,access_estate_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,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_advertisements_menu" name="Ads"> | ||
| <menuitem id="estate_property_menu" action="estate_property_action"/> | ||
| </menuitem> | ||
|
|
||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_types_menu" action="estate_property_type_action"/> <!-- Property Types --> | ||
| <menuitem id="estate_property_tag_menu" action="estate_property_tag_action"/> <!-- Property Tags --> | ||
| </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,19 @@ | ||
|
|
||
| <odoo> | ||
| <!-- List View --> | ||
| <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="Tags"> | ||
| <field string="Buyer" name="partner_id"/> | ||
| <field string="Price" name="price"/> | ||
| <field string="Status" name="status"/> | ||
| <button name="action_accept_offer" string="Accept" type="object" icon="fa-check" invisible="status in ('accepted','refused')"/> | ||
| <button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times" invisible="status in ('accepted','refused')"/> | ||
| </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,33 @@ | ||
|
|
||
| <odoo> | ||
| <!-- Action Handler --> | ||
| <record id="estate_property_tag_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> | ||
|
|
||
| <!-- 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"> | ||
| <field string="Tags" name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!-- Form View --> | ||
| <record id="estate_property_tag_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> | ||
| <sheet> | ||
| <h1><field name="name"></field></h1> | ||
| </sheet> | ||
| </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,33 @@ | ||
|
|
||
| <odoo> | ||
| <!-- Action Handler --> | ||
| <record id="estate_property_type_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> | ||
|
|
||
| <!-- List View --> | ||
| <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="Types"> | ||
| <field string="Types" name="name"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <!-- Form View --> | ||
| <record id="estate_property_type_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> | ||
| <sheet> | ||
| <h1><field name="name"></field></h1> | ||
| </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.
ops, I shouldn't see this file here :)
environmental files like this one (or .vscode) for example shouldn't be pushed with your commit