-
Notifications
You must be signed in to change notification settings - Fork 2.9k
First try #1130
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
eesteerina
wants to merge
15
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-onboarding-esand
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
First try #1130
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9efdf59
First try
eesteerina b75db3b
[ADD] some elements added
eesteerina a29cdce
[ADD] elements added 2
eesteerina c3295cb
Update awesome_clicker/__manifest__.py
eesteerina 0ef923a
Update estate/models/estate_property.py
eesteerina 34a537f
[ADD] estate: add menus and action for property model
eesteerina e7ec16b
[IMP] estate: add defaults and reserved fields to property model
eesteerina ebfc72c
[IMP] estate: improve property views usability
eesteerina f3d41a7
[ADD] add property types, property tags and offers
eesteerina ed9fb0b
[IMP] corrections
eesteerina a4130ad
[IMP] Improved property with best price calculation, validity, deadline
eesteerina 60d1ea2
[ADD] confirmation buttons and interactions added
eesteerina 1be9f1c
[IMP] variables improved by adding some constraints
eesteerina 27e01b3
[ADD] connections between models
eesteerina 9386f03
[IMP] inheritance in some models
eesteerina 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
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,23 @@ | ||
| { | ||
| "name": "Real Estate", | ||
| "version": "1.0", | ||
| "summary": "Real Estate Property Management", | ||
| "description": """ | ||
| Tutorial module for managing real estate properties. | ||
| """, | ||
| "author": "Your Name", | ||
| "category": "Tutorial", | ||
| "depends": ["base"], | ||
| "data": [ | ||
| 'security/ir.model.access.csv', | ||
| 'views/res_users_views.xml', | ||
| 'views/estate_property_offer_views.xml', | ||
| 'views/estate_property_tag_views.xml', | ||
| 'views/estate_property_type_views.xml', | ||
| 'views/estate_property_views.xml', | ||
| 'views/estate_menus.xml' | ||
| ], | ||
| "installable": True, | ||
| "application": True, | ||
| '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,116 @@ | ||
| from odoo import api, fields, models | ||
| from dateutil.relativedelta import relativedelta | ||
| from odoo.tools.float_utils import float_is_zero | ||
| from odoo.exceptions import UserError, ValidationError | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Real Estate Property' | ||
| _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(readonly=True, copy=False) | ||
| 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( | ||
| selection=[ | ||
| ('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West'), | ||
| ] | ||
| ) | ||
| state = fields.Selection( | ||
| [ | ||
| ('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer Accepted'), | ||
| ('sold', 'Sold'), | ||
| ('canceled', 'Cancelled'), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default='new', | ||
| ) | ||
| active = fields.Boolean(default=True) | ||
|
|
||
| property_type_id = fields.Many2one('estate.property.type', string='Property Type') | ||
|
|
||
| buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False) | ||
|
|
||
| salesperson_id = fields.Many2one('res.users', string='Salesperson', default=lambda self: self.env.user) | ||
|
|
||
| tag_ids = fields.Many2many('estate.property.tag', string='Property Tag') | ||
|
|
||
| offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers') | ||
|
|
||
| total_area = fields.Integer(compute='_compute_total_area') | ||
|
|
||
| best_price = fields.Float(compute='_compute_best_price') | ||
|
|
||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The expected price must be strictly positive.', | ||
| ) | ||
|
|
||
| _check_selling_price = 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 float_is_zero(record.selling_price, precision_digits=2): | ||
| continue | ||
| if record.selling_price < record.expected_price * 0.9: | ||
| raise ValidationError('The selling price cannot be lower than 90% of the expected price.') | ||
|
|
||
| @api.depends('garden_area', 'total_area') | ||
| def _compute_total_area(self): | ||
| for record in self: | ||
| record.total_area = record.garden_area + record.living_area | ||
|
|
||
| @api.depends('offer_ids.price') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| prices = record.offer_ids.mapped('price') | ||
| record.best_price = max(prices, default=0.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 = False | ||
|
|
||
| @api.ondelete(at_uninstall=False) | ||
| def _unlink_if_new_or_cancelled(self): | ||
| for record in self: | ||
| if record.state not in ('new', 'cancelled'): | ||
| raise UserError('You can only delete a property when its state is New or Cancelled.') | ||
|
|
||
| def action_sold(self): | ||
| for record in self: | ||
| if record.state == 'canceled': | ||
| raise UserError('A canceled property cannot be set as sold.') | ||
| record.state = 'sold' | ||
| return True | ||
|
|
||
| def action_cancel(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError('A sold property cannot be canceled.') | ||
| record.state = 'canceled' | ||
| 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,83 @@ | ||
| 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' | ||
| _order = 'price desc' | ||
|
|
||
| partner_id = fields.Many2one('res.partner', string='Partner', required=True) | ||
| property_id = fields.Many2one('estate.property', string='Estate Property', required=True) | ||
| price = fields.Float() | ||
| status = fields.Selection( | ||
| copy=False, | ||
| selection=[ | ||
| ('accepted', 'Accepted'), | ||
| ('refused', 'Refused'), | ||
| ] | ||
| ) | ||
| property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', store=True, readonly=True) | ||
| validity = fields.Integer(default=7) | ||
| date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', store=True) | ||
|
|
||
| _check_offer_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The offer price must be strictly positive.', | ||
| ) | ||
|
|
||
| @api.depends('create_date', 'validity') | ||
| def _compute_date_deadline(self): | ||
| for offer in self: | ||
| create_dt = offer.create_date if offer.create_date else fields.Datetime.now() | ||
| offer.date_deadline = (create_dt + timedelta(days=offer.validity)).date() | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for offer in self: | ||
| if offer.date_deadline: | ||
| create_date = offer.create_date.date() if offer.create_date else fields.Datetime.now() | ||
| offer.validity = (offer.date_deadline - create_date).days | ||
|
|
||
| def action_confirm(self): | ||
| for offer in self: | ||
| if offer.property_id.state in ('offer_accepted', 'sold', 'canceled'): | ||
| raise UserError('A sold property cannot accept new offers.') | ||
|
|
||
| offer.status = 'accepted' | ||
|
|
||
| offer.property_id.write({ | ||
| 'buyer_id': offer.partner_id.id, | ||
| 'selling_price': offer.price, | ||
| 'state': 'offer_accepted', | ||
| }) | ||
|
|
||
| return True | ||
|
|
||
| def action_refuse(self): | ||
| for offer in self: | ||
| if offer.status == 'accepted': | ||
| raise UserError('You cannot refuse an accepted offer.') | ||
|
|
||
| offer.status = 'refused' | ||
|
|
||
| property_record = offer.property_id | ||
|
|
||
| active_offers = property_record.offer_ids.filtered(lambda o: o.status in ('pending', 'accepted')) | ||
|
|
||
| if not active_offers: | ||
| property_record.write({ | ||
| 'buyer_id': False, | ||
| 'selling_price': 0, | ||
| 'state': 'new', | ||
| }) | ||
|
|
||
| return True | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| if vals['property_id'] and vals['price'] is not None: | ||
| if vals['price'] < self.env['estate.property'].browse(vals['property_id']).best_price: | ||
| raise UserError('The offer must be higher than the existing offers.') | ||
| return super().create(vals_list) |
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' | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer(name="Color") |
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,24 @@ | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Estate Property Type' | ||
| _order = 'name' | ||
|
|
||
| name = fields.Char(required=True) | ||
| sequence = fields.Integer('Sequence', default=1) | ||
|
|
||
| _unique_type_name = models.Constraint( | ||
| 'UNIQUE(name)', | ||
| 'The property type name must be unique.', | ||
| ) | ||
|
|
||
| property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties') | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='Offers') | ||
| offer_count = fields.Integer(compute='_compute_offer_count', string='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,6 @@ | ||
| from odoo import fields, models | ||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = 'res.users' | ||
|
|
||
| property_ids = fields.One2many('estate.property', 'salesperson_id', string='Properties', domain=[('state', 'in', ['new', '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,5 @@ | ||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
| estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 | ||
| estate.access_estate_property_offer,access_estate_property_offer,estate.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,27 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
| <!-- Root menu (App switcher) --> | ||
| <menuitem id='estate_menu_root' name='Real Estate'/> | ||
|
|
||
| <!-- First level menu (top bar) --> | ||
| <menuitem id='estate_menu_adv' | ||
| name='Advertisements' | ||
| parent='estate_menu_root'/> | ||
|
|
||
| <menuitem id='estate_menu_settings' | ||
| name='Settings' | ||
| parent='estate_menu_root'/> | ||
|
|
||
| <!-- Action menu (opens the list/form view) --> | ||
| <menuitem id='estate_menu_properties' | ||
| parent='estate_menu_adv' | ||
| action='estate_property_action'/> | ||
|
|
||
| <menuitem id='estate_menu_property_type_properties' | ||
| parent='estate_menu_settings' | ||
| action='estate_property_type_action'/> | ||
|
|
||
| <menuitem id='estate_menu_property_tag_properties' | ||
| parent='estate_menu_settings' | ||
| action='estate_property_tag_action'/> | ||
| </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 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
| <record id='estate_property_offer_view_list' model='ir.ui.view'> | ||
| <field name='name'>estate.property.offer.view.list</field> | ||
| <field name='model'>estate.property.offer</field> | ||
| <field name='arch' type='xml'> | ||
| <list string='Properties' editable='bottom' decoration-success="status in ('accepted')" decoration-danger="status in ('refused')"> | ||
| <field name='price'/> | ||
| <field name='partner_id' string='Partner'/> | ||
| <field name='property_type_id' string='Property Type'/> | ||
| <field name='validity' string='Validity (days)'/> | ||
| <field name='date_deadline' string='Deadline'/> | ||
| <button name='action_confirm' string='Confirm' type='object' icon='fa-check' invisible="status in ('accepted', 'refused')"/> | ||
| <button name='action_refuse' string='Refuse' type='object' icon='fa-times' invisible="status in ('accepted', 'refused')"/> | ||
| <field name='status' column_invisible='1'/> | ||
| </list> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id='estate_property_offer_view_form' model='ir.ui.view'> | ||
| <field name='name'>estate.property.offer.view.form</field> | ||
| <field name='model'>estate.property.offer</field> | ||
| <field name='arch' type='xml'> | ||
| <form string='Property'> | ||
| <sheet> | ||
| <group> | ||
| <field name='price'/> | ||
| <field name='partner_id' string='Partner'/> | ||
| <field name='validity' string='Validity (days)'/> | ||
| <field name='date_deadline' string='Deadline'/> | ||
| <field name='status'/> | ||
| </group> | ||
| </sheet> | ||
| </form> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id='estate_property_offer_action_from_types' model='ir.actions.act_window'> | ||
| <field name='name'>Offers From Types</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> | ||
| <field name='view_id' ref='estate_property_offer_view_list'/> | ||
| </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,18 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <odoo> | ||
| <record id='estate_property_tag_action' model='ir.actions.act_window'> | ||
| <field name='name'>Property Tag</field> | ||
| <field name='res_model'>estate.property.tag</field> | ||
| <field name='view_mode'>list,form</field> | ||
| </record> | ||
|
|
||
| <record id='estate_property_tag_view_list' model='ir.ui.view'> | ||
| <field name='name'>estate.property.tag.view.list</field> | ||
| <field name='model'>estate.property.tag</field> | ||
| <field name='arch' type='xml'> | ||
| <list string='Properties' 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.
Not sure it was necessary to change this, we try not to change code for aestetic reasons once it has been merged, as it makes it harder to get the git blame to see who wrote it and find the commit that introduced the line.