-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[IMP] estate: add offer count stat button and default fillter for available property #1102
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
javek-odoo
wants to merge
17
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-javek
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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
abcede9
[ADD] estate - new module added
javek-odoo a09d9e2
[ADD] estate - new module added
javek-odoo 2f7c73f
[ADD] estate - new module added
javek-odoo 2811bab
[ADD] estate - new module added
javek-odoo 8c4ca8f
[ADD] estate - new module added
javek-odoo b90bee4
[IMP] estate: created views, menuitem
javek-odoo 60d0594
[IMP] estate: Added basic views for property
javek-odoo f7fbdb6
[IMP] estate: model relations
javek-odoo 43dbcf0
[FIX] estate: removed whitespace
javek-odoo b0c2cf3
[IMP] estate: Added Computed Fields And Onchanges
javek-odoo 6385d9b
[IMP] estate: Added action button and sql constraint
javek-odoo e774e32
[FIX] estate: removed whitespace
javek-odoo bb42153
[FIX] estate: Implemented PR suggestions
javek-odoo 19f1bc6
[IMP] estate: Add Inline view, widgets, list orders
javek-odoo 36be2c0
[IMP] estate: added attribute options, list orders
javek-odoo 1386900
[IMP] estate: add stat button, default filter for available
javek-odoo 37beac2
[FIX] estate: corrected files order in manifest file
javek-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,19 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'version': '1.0', | ||
| 'depends': ['crm'], | ||
| 'author': 'jaldip vekariya (javek)', | ||
| 'description': """ | ||
| An Real Estate App to buy, sell, and rent properties. | ||
| """, | ||
| 'application': True, | ||
| 'license': 'LGPL-3', | ||
| 'data': [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/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,4 @@ | ||
| from . import real_estate_property_offer | ||
| from . import real_estate_property_tag | ||
| from . import real_estate_property_type | ||
| from . import real_estate |
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,104 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError, UserError | ||
| from odoo.tools import float_compare | ||
|
|
||
|
|
||
| class RealEstate(models.Model): | ||
| _name = "real_estate" | ||
| _description = "Real Estate" | ||
| _order = "id desc" | ||
|
|
||
| name = fields.Char(required=True) | ||
| description = fields.Text() | ||
| postcode = fields.Char() | ||
| date_availability = fields.Date( | ||
| copy=False, | ||
| default=lambda self: fields.Date.context_today(self) + relativedelta(months=3), | ||
| ) | ||
| expected_price = fields.Float(required=True) | ||
| selling_price = fields.Float() | ||
| bedrooms = fields.Integer(default=2) | ||
| living_area = fields.Integer() | ||
| facades = fields.Integer() | ||
| garage = fields.Boolean() | ||
| garden = fields.Boolean() | ||
| garden_area = fields.Integer() | ||
| garden_orientation = fields.Selection([ | ||
| ("north", "North"), | ||
| ("south", "South"), | ||
| ("east", "East"), | ||
| ("west", "West"), | ||
| ]) | ||
| state = fields.Selection( | ||
| selection=[ | ||
| ("new", "New"), | ||
| ("offer_received", "Offer Received"), | ||
| ("offer_accepted", "Offer Accepted"), | ||
| ("sold", "Sold"), | ||
| ("cancelled", "Cancelled"), | ||
| ], | ||
| string="Status", | ||
| default="new", | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
| property_type_id = fields.Many2one("estate.property.type", string="Property Type", required=True) | ||
| buyer_id = fields.Many2one("res.partner", string="Buyer") | ||
| sales_id = fields.Many2one("res.users", string="Salesperson") | ||
| tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
| offer_ids = fields.One2many("estate.property.offer", "property_id") | ||
| total_area = fields.Integer(compute="_compute_total_area") | ||
| best_price = fields.Integer(compute="_compute_best_price") | ||
|
|
||
| _expected_price_positive = models.Constraint( | ||
| 'CHECK(expected_price > 0.0)', | ||
| 'The expected price must be strictly positive.' | ||
| ) | ||
| _selling_price_positive = models.Constraint( | ||
| 'CHECK(selling_price >= 0.0 or selling_price IS NULL)', | ||
| '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.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 _garden_changes(self): | ||
| if self.garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = "north" | ||
| else: | ||
| self.garden_area = 0 | ||
| self.garden_orientation = None | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state != "cancelled": | ||
| record.state = "sold" | ||
| else: | ||
| raise UserError("Cancelled Property can not be sold") | ||
javek-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state != "sold": | ||
| record.state = "cancelled" | ||
| else: | ||
| raise UserError("Sold Property can not be cancelled") | ||
javek-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return True | ||
|
|
||
| @api.constrains("expected_price", "selling_price") | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if record.selling_price == 0: | ||
| return False | ||
| if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) < 0: | ||
| raise ValidationError("The selling price cannot be lower than 90 of the expected price.") | ||
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,63 @@ | ||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from odoo import api, fields, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class PropertyOffer(models.Model): | ||
| _name = "estate.property.offer" | ||
| _description = "Property Offers" | ||
| _order = "price desc" | ||
|
|
||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| selection=[ | ||
| ("accepted", "Accepted"), | ||
| ("refused", "Refused") | ||
| ] | ||
| ) | ||
| partner_id = fields.Many2one("res.partner", string="Partner", required=True) | ||
| property_id = fields.Many2one("real_estate", string="Property", required=True) | ||
| validity = fields.Integer(string="Validity(days)", default=7) | ||
| deadline = fields.Date( | ||
| compute="_compute_deadline", | ||
| inverse="_inverse_validity" | ||
| ) | ||
| property_type_id = fields.Many2one(related="property_id.property_type_id", store=True) | ||
|
|
||
| _price_positive = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The offer price must be positive.' | ||
| ) | ||
|
|
||
| @api.depends("validity", "create_date") | ||
| def _compute_deadline(self): | ||
| for record in self: | ||
| date = record.create_date.date() if record.create_date else fields.Date.today() | ||
| record.deadline = date + relativedelta(days=record.validity) | ||
|
|
||
| def _inverse_validity(self): | ||
| for record in self: | ||
| record.validity = ((record.deadline) - record.create_date.date()).days | ||
|
|
||
| def accept_offer(self): | ||
javek-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for record in self: | ||
| if record.property_id.buyer_id: | ||
| raise UserError("Only One Offer can be accepted") | ||
| else: | ||
| for ids in record.property_id.offer_ids: | ||
| if (record.id != ids.id): | ||
| ids.status = "refused" | ||
| record.property_id.buyer_id = record.partner_id | ||
| record.property_id.selling_price = record.price | ||
| record.status = "accepted" | ||
| record.property_id.state = "offer_accepted" | ||
| return True | ||
|
|
||
| def reject_offer(self): | ||
| for record in self: | ||
| if record.property_id.buyer_id and record.status == "accepted": | ||
| raise UserError("Accepted Offer can not be rejected") | ||
| else: | ||
| 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,22 @@ | ||
| from random import randint | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class PropertyTag(models.Model): | ||
| _name = "estate.property.tag" | ||
| _description = "Property Tags" | ||
| _order = "name" | ||
|
|
||
| name = fields.Char(string="Name") | ||
| color = fields.Integer( | ||
| string='Color Index', default=lambda self: self._default_color() | ||
| ) | ||
|
|
||
| _name_unique = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'The name must be unique' | ||
| ) | ||
|
|
||
| def _default_color(self): | ||
javek-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return randint(1, 11) | ||
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 PropertyType(models.Model): | ||
| _name = "estate.property.type" | ||
| _description = "Property Types" | ||
| _order = "sequence, name" | ||
|
|
||
| name = fields.Char(string="Name") | ||
javek-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| property_ids = fields.One2many("real_estate", "property_type_id", required=True) | ||
| sequence = fields.Integer("Sequence") | ||
| offer_id = fields.One2many("estate.property.offer", "property_type_id") | ||
| offer_count = fields.Integer(compute="_compute_offer_count") | ||
|
|
||
| _name_unique = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'The name must be unique' | ||
| ) | ||
|
|
||
| @api.depends("offer_id") | ||
| def _compute_offer_count(self): | ||
| for record in self: | ||
| record.offer_count = len(record.offer_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,5 @@ | ||
| id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
| estate.access_real_estate,access_real_estate,model_real_estate,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| estate.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,9 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <odoo> | ||
| <menuitem id="estate" name="Estate"/> | ||
| <menuitem id="estate_advertisement" name="Advertisement" parent="estate"/> | ||
| <menuitem id="estate_advertisement_properties" name="Properties" parent="estate_advertisement" action="real_estate"/> | ||
| <menuitem id="estate_settings" name="Settings" parent="estate"/> | ||
| <menuitem id="estate_settings_property_type" name="Property Type" parent="estate_settings" action="estate_property_type"/> | ||
| <menuitem id="estate_settings_property_tag" name="Property Tags" parent="estate_settings" action="estate_property_tag"/> | ||
| </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,43 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_offer" model="ir.actions.act_window"> | ||
| <field name="name">PropertyOffers</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> | ||
|
|
||
|
|
||
| <record id="estate_property_offer_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="Offers" editable="bottom" decoration-danger="status == 'refused'" decoration-success="status == 'accepted'"> | ||
| <field name="price" /> | ||
| <field name="partner_id" string="Partner" /> | ||
| <field name="validity" string="Validity(days)"/> | ||
| <field name="deadline"/> | ||
| <button name="accept_offer" string="Accept" type="object" icon="fa-check" invisible="status == 'accepted' or status == 'refused'"/> | ||
| <button name="reject_offer" string="Reject" type="object" icon="fa-close" invisible="status == 'accepted' or status == 'refused'"/> | ||
| <field name="status"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="estate_property_offer_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="Offer"> | ||
| <group> | ||
| <field name="price" /> | ||
| <field name="partner_id" string="Partner" /> | ||
| <field name="validity"/> | ||
| <field name="deadline" readonly="0"/> | ||
| <field name="status"/> | ||
| </group> | ||
| </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,37 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_tag" model="ir.actions.act_window"> | ||
| <field name="name">Tag Name</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
|
|
||
| <record id="estate_property_tag_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="Types"> | ||
| <field name="name" string="Type"/> | ||
| <field name="color" widget="color_picker" options="{'color_field': 'color'}"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <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 string="Tags"> | ||
| <sheet> | ||
| <group> | ||
| <field name="name" /> | ||
| <field name="color" widget="color_picker"/> | ||
| </group> | ||
| </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,57 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_type" model="ir.actions.act_window"> | ||
| <field name="name">Property Type</field> | ||
| <field name="res_model">estate.property.type</field> | ||
| <field name="view_mode">list,form</field> | ||
| </record> | ||
|
|
||
|
|
||
| <record id="estate_property_type_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 name="sequence" widget="handle"/> | ||
| <field name="name" string="Type"/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
|
|
||
| <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 string="Properties"> | ||
| <sheet> | ||
| <div class="oe_button_box" name="button_box"> | ||
| <button type="action" name="%(estate_property_offer)d" icon="fa-dollar"> | ||
| <div class="o_form_field o_stat_info"> | ||
| <span class="o_stat_value"> | ||
| <field name="offer_count" string="Offers" widget="statinfo"/> | ||
| </span> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| <h1> | ||
| <field name="name" placeholder="Name"/> | ||
| </h1> | ||
| <notebook> | ||
| <page string="Properties"> | ||
| <field name="property_ids"> | ||
| <list> | ||
| <field name="name" string="Title" /> | ||
| <field name="expected_price" /> | ||
| <field name="state" string="Status" readonly="1"/> | ||
| </list> | ||
| </field> | ||
| </page> | ||
| </notebook> | ||
| </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.
Uh oh!
There was an error while loading. Please reload this page.