-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Master technical onboarding faavc #1071
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
Faruk372742
wants to merge
13
commits into
odoo:master
Choose a base branch
from
odoo-dev:master-technical_onboarding-faavc
base: master
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
13 commits
Select commit
Hold shift + click to select a range
c21c5ba
[ADD] estate: initialize the estate app - Chapter 2
Faruk372742 dd58b67
[ADD] estate: adding estate property table - Chapter 3
Faruk372742 b4bd38a
[ADD] estate: adding security for estate_property table - Chapter 4
Faruk372742 923489a
[ADD] estate: adding menus and changing fields - Chapter 5
Faruk372742 7365fae
[IMP] estate: adding list,form, search views (filters + group by) - C…
Faruk372742 40660a8
[IMP] estate: adding relations between models - Chapter 7
Faruk372742 2c59655
[IMP] estate: add computed fields and onchanges - Chapter 8
Faruk372742 79ff504
[IMP] estate: adding actions to estate property and estate_property_o…
Faruk372742 5f480f5
[IMP] estate: add SQL and Python constraints - Chapter 10
Faruk372742 339b8eb
[REF] estate: resolving onboarder's comments
Faruk372742 a1670fa
[IMP] estate: adding sprinkles to the views - Chapter 11
Faruk372742 0fec157
[IMP] estate: res.user inheritance for properties - Chapter 12
Faruk372742 b7c50ca
[REF] estate: removing comments and endlining xmls
Faruk372742 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,22 @@ | ||
| { | ||
| "name": "estate", | ||
| "website": "", | ||
| "category": "Tutorials", | ||
| "version": "0.1", | ||
| "application": True, | ||
| "installable": True, | ||
| "depends": ["base"], | ||
| "data": [ | ||
| "security/security.xml", | ||
| "security/ir.model.access.csv", | ||
| "views/estate_property_views.xml", | ||
| "views/estate_property_tag_views.xml", | ||
| "views/estate_property_offer_views.xml", | ||
| "views/estate_property_type_views.xml", | ||
| "views/res_users_views.xml", | ||
| "views/estate_menus.xml", | ||
| ], | ||
| "assets": {}, | ||
| "author": "Odoo S.A.", | ||
| "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,5 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer | ||
| 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,128 @@ | ||
| from odoo import api, fields, models | ||
| from dateutil.relativedelta import relativedelta | ||
| from datetime import datetime | ||
| from odoo.exceptions import UserError, ValidationError | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = "estate.property" | ||
| _description = "Estate Property" | ||
| name = fields.Char("Title", required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| copy=False, default=lambda self: datetime.now() + 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("Living Area (sqm)") | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection( | ||
| string="Orientation", | ||
| selection=[ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ], | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| state = fields.Selection( | ||
| readonly=True, | ||
| string="State", | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| default="new", | ||
| required=True, | ||
| copy=False, | ||
| store=True, | ||
| ) | ||
| type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
| salesperson_id = fields.Many2one( | ||
| "res.users", string="Salesperson", 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", string="Offers") | ||
| total_area = fields.Integer("Total Area (sqm)", compute="_compute_total_area") | ||
| best_price = fields.Float("Best Price", compute="_compute_best_price") | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| "CHECK(expected_price > 0)", "The expected price must be positive" | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| "CHECK(selling_price > 0)", "The selling price must be positive" | ||
| ) | ||
|
|
||
| _order = "id desc" | ||
|
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. let's keep all the meta data at first before any field declaration |
||
|
|
||
| @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") or [0]) | ||
|
|
||
| @api.onchange("garden") | ||
| def _onchange_garden(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = "north" | ||
| else: | ||
| self.garden_area = False | ||
| self.garden_orientation = False | ||
|
|
||
| def action_cancel_property(self): | ||
| if self.state == "sold": | ||
| raise UserError("Sold property cannot be cancelled!") | ||
|
|
||
| for record in self: | ||
| record.state = "cancelled" | ||
|
|
||
| return True | ||
|
|
||
| def action_sell_property(self): | ||
| if self.state == "cancelled": | ||
| raise UserError("Cancelled property cannot be sold!") | ||
|
|
||
| for record in self: | ||
| record.state = "sold" | ||
|
|
||
| return True | ||
|
|
||
| @api.constrains("expected_price", "selling_price") | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if len(record.offer_ids) > 0 and ( | ||
| float_compare(record.selling_price, record.expected_price * 0.9, 5) | ||
| == -1 | ||
| ): | ||
| raise ValidationError( | ||
| "The selling price cannot be lower than the 90% of the expected price" | ||
| ) | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_except_few_states(self): | ||
| if any( | ||
| (record.state != "new" and record.state != "cancelled") for record in self | ||
| ): | ||
| raise UserError( | ||
| "You cannot remove the property except when the state is new or cancelled!" | ||
| ) | ||
|
|
||
| def offer_received(self): | ||
| if self.state == "new": | ||
| self.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,103 @@ | ||
| from odoo import api, fields, models | ||
| from datetime import timedelta | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Estate Property Offer" | ||
| 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("Validity", default=7) | ||
| date_deadline = fields.Date("Deadline", compute="_compute_date_deadline") | ||
| hide_offer_buttons = fields.Boolean(compute="_compute_hide_offer_buttons") | ||
| property_type_id = fields.Many2one(related="property_id.type_id", store=True) | ||
| _check_price = models.Constraint( | ||
| "CHECK(price > 0)", "Offer's price must be positive" | ||
| ) | ||
| _order = "price desc" | ||
|
|
||
| @api.model | ||
| def create(self, vals_list): | ||
| an_estate_property = self.env["estate.property"].browse( | ||
| vals_list[0]["property_id"] | ||
| ) | ||
| if any( | ||
| vals_list[0]["price"] < offer_id.price | ||
| for offer_id in an_estate_property.offer_ids | ||
| ): | ||
| raise UserError("Offer cannot be lower than any of previous offers!") | ||
|
|
||
| an_estate_property.offer_received() | ||
|
|
||
| return super().create(vals_list) | ||
|
|
||
| @api.depends("validity", "create_date") | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| record.date_deadline = ( | ||
| record.create_date or fields.Datetime.now() | ||
| ) + timedelta(days=record.validity) | ||
|
|
||
| @api.depends("property_id.state") | ||
| def _compute_hide_offer_buttons(self): | ||
| for record in self: | ||
| a_state = record.property_id.state | ||
| if ( | ||
| a_state == "offer_accepted" | ||
| or a_state == "cancelled" | ||
| or a_state == "sold" | ||
| or record.status | ||
| ): | ||
| record.hide_offer_buttons = True | ||
| else: | ||
| record.hide_offer_buttons = False | ||
|
|
||
| def action_accept_offer(self): | ||
| if self.status: | ||
| raise UserError("You cannot change the status!") | ||
| if self.property_id.state == "offer_accepted": | ||
| raise UserError("One offer has been already accepted, sorry!") | ||
| if self.property_id.state == "cancelled": | ||
| raise UserError("This property is cancelled") | ||
| if self.property_id.state == "sold": | ||
| raise UserError("This property is sold") | ||
|
|
||
| for record in self: | ||
| record.status = "accepted" | ||
| record.property_id.selling_price = record.price | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.state = "offer_accepted" | ||
| return True | ||
|
|
||
| def action_refuse_offer(self): | ||
| if self.status: | ||
| raise UserError("You cannot change the status!") | ||
| for record in self: | ||
| record.status = "refused" | ||
| return True | ||
|
|
||
| def is_still_open_to_offers(self): | ||
| if ( | ||
| self.partner_id.state == "offer_accepted" | ||
| or self.partner_id.state == "sold" | ||
| or self.partner_id.state == "cancelled" | ||
| ): | ||
| print("HELLO!!") | ||
| return True | ||
|
|
||
| print("FALSE case!!") | ||
| return False | ||
|
|
||
| # @api.depends("create_date", "date_deadline") Not working right now!!! | ||
| # def _inverse_date_deadline(self): | ||
| # print("Hello!") | ||
| # for record in self: | ||
| # record.validity = ( | ||
| # (record.date_deadline or fields.Datetime.now()) | ||
| # - (record.create_date or fields.Datetime.now()) | ||
| # ).days |
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,10 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Estate Property Tag" | ||
| name = fields.Char("Name", required=True) | ||
| color = fields.Integer("Color") | ||
| _name_unique = models.Constraint("unique(name)", "Tag name must be unique") | ||
| _order = "name" |
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 fields, models, api | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Estate Property Type" | ||
| name = fields.Char(required=True) | ||
| _name_unique = models.Constraint("unique(name)", "Type must be unique") | ||
| property_ids = fields.One2many("estate.property", "type_id", string="Properties") | ||
| _order = "sequence, name" | ||
| sequence = fields.Integer( | ||
| "Sequence", default=1, help="Used to order property types" | ||
| ) | ||
| offer_ids = fields.One2many( | ||
| "estate.property.offer", "property_type_id", string="Offers" | ||
| ) | ||
| offer_count = fields.Integer("Offer Count", compute="_compute_offer_count") | ||
|
|
||
| @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,11 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
| property_ids = fields.One2many( | ||
| "estate.property", | ||
| "salesperson_id", | ||
| string="User Properties", | ||
| domain=["|", ("state", "=", "new"), ("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,6 @@ | ||
| 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_readonly,access_estate_property_readonly,model_estate_property,group_readonly_user,1,0,0,0 | ||
| 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,10 @@ | ||
| <odoo> | ||
| <data> | ||
| <record id="group_all_rights_user" model="res.groups"> | ||
| <field name="name">Complete User</field> | ||
| </record> | ||
| <record id="group_readonly_user" model="res.groups"> | ||
| <field name="name">Readonly User</field> | ||
| </record> | ||
| </data> | ||
| </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,12 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_menu_root" name="Estate Property"> | ||
| <menuitem id="estate_first_level_menu" name="Advertisements"> | ||
| <menuitem id="estate_second_level_menu" action="estate_property_action" /> | ||
| </menuitem> | ||
| <menuitem id="estate_settings_menu" name="Settings"> | ||
| <menuitem id="estate_property_type_menu" action="estate_property_type_action" /> | ||
| <menuitem id="estate_property_tag_menu" action="estate_property_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,45 @@ | ||
| <odoo> | ||
| <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 editable="bottom" decoration-success="status == 'accepted'" | ||
| decoration-danger="status == 'refused'"> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| <field name="property_type_id" /> | ||
| <button name="action_accept_offer" type="object" string="" icon="fa-check" | ||
| title="accept" invisible="hide_offer_buttons" /> | ||
| <button name="action_refuse_offer" type="object" string="" icon="fa-times" | ||
| title="refuse" invisible="hide_offer_buttons" /> | ||
| </list> | ||
| </field> | ||
| </record> | ||
| <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> | ||
| <sheet> | ||
| <group> | ||
| <group> | ||
| <field name="price" /> | ||
| <field name="partner_id" /> | ||
| <field name="status" /> | ||
| <field name="validity" /> | ||
| <field name="date_deadline" /> | ||
| </group> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
| <record id="estate_property_offer_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,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,7 @@ | ||
| <odoo> | ||
| <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> | ||
| </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.
we do not need this as this is not computed anymore 👀