-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ADD] : Creation of the new module #1412
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
macai-odoo
wants to merge
15
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-training-tutorial-macai
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b41bda0
[ADD] : Creation of the new module
macai-odoo a6b3d75
[IMP] : Creation of new model property
macai-odoo feee2db
[IMP] : Added right for group_user
macai-odoo e637945
[IMP] : Added views into the app
macai-odoo c6c24d0
[FIX] estate: feedback implementation for git
macai-odoo 84e3360
[IMP] estate: add title to list view
macai-odoo e5f83fc
[IMP] estate: add search view
macai-odoo de60fce
[IMP] estate: added tag,offer,property type
macai-odoo ada43a3
[FIX] estate: fix style and remarks
macai-odoo d833304
[IMP] estate: Add computation field for offer
macai-odoo c1ed077
[IMP] estate: Add changing has_garden computation
macai-odoo b297326
[FIX] estate: fix the styling
macai-odoo 98ae518
[FIX] estate: fix the comment styling
macai-odoo 170e216
[IMP] estate: Add buttons to update property
macai-odoo 5cf1031
[IMP] estate: Add constraints for property and offer
macai-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
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,17 @@ | ||
| { | ||
| 'name': 'Real Estate', | ||
| 'version': '1.0', | ||
| '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_menu.xml', | ||
| ], | ||
| 'author': 'macai', | ||
| '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,4 @@ | ||
| from . import estate_property | ||
| from . import estate_property_type | ||
| from . import estate_property_tag | ||
| from . import estate_property_offer |
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,134 @@ | ||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError | ||
| from odoo.tools import float_is_zero | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
|
|
||
| class EstateProperty(models.Model): | ||
| _name = 'estate.property' | ||
| _description = 'Real Estate property model' | ||
|
|
||
| # Property information | ||
| name = fields.Char('Name', required=True) | ||
| description = fields.Text('Description') | ||
| postcode = fields.Char('Postcode', required=True) | ||
| date_availability = fields.Date('Availability', copy=False, default=lambda self: fields.Date.add(fields.Date.today(), months=3)) | ||
| expected_price = fields.Float('Expected Price', required=True) | ||
| selling_price = fields.Float('Selling Price', readonly=True, copy=False) | ||
| bedrooms = fields.Integer('Bedrooms', default=2) | ||
| living_area = fields.Integer('Living Area') | ||
| facades = fields.Integer('Facades') | ||
| has_garage = fields.Boolean('Garage') | ||
| has_garden = fields.Boolean('Garden') | ||
| garden_area = fields.Integer('Garden Area') | ||
| garden_orientation = fields.Selection( | ||
| string='Garden Orientation', | ||
| selection=[('north', 'North'), | ||
| ('south', 'South'), | ||
| ('east', 'East'), | ||
| ('west', 'West'), | ||
| ] | ||
| ) | ||
| total_area = fields.Integer(compute='_compute_total_area', string='Total Area') | ||
| active = fields.Boolean('Active', default=True) | ||
| state = fields.Selection( | ||
| string='State', | ||
| selection=[('new', 'New'), | ||
| ('offer_received', 'Offer Received'), | ||
| ('offer_accepted', 'Offer accepted'), | ||
| ('sold', 'Sold'), | ||
| ('cancelled', 'Cancelled'), | ||
| ], | ||
| required=True, | ||
| copy=False, | ||
| default='new' | ||
| ) | ||
| property_type_id = fields.Many2one("estate.property.type", string='Property Type') | ||
|
|
||
| # Other Information | ||
| salesman_id = fields.Many2one('res.users', string='Salesman', default=lambda self: self.env.user) | ||
| buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False) | ||
|
|
||
| # Tags | ||
| tag_ids = fields.Many2many('estate.property.tag', string='Tags') | ||
|
|
||
| # Offers | ||
| offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offer') | ||
| best_price = fields.Float(compute='_compute_best_price', string='Best Offer') | ||
|
|
||
| # Constraints: | ||
| # SQL: | ||
| _check_expected_price = models.Constraint( | ||
| 'CHECK(expected_price > 0)', | ||
| 'The expected price should be stricly positive.' | ||
| ) | ||
| _check_selling_price = models.Constraint( | ||
| 'CHECK(selling_price > 0)', | ||
| 'The proporty selling price should be stricly positive.' | ||
| ) | ||
|
|
||
| # Python: | ||
| @api.constrains('selling_price') | ||
| def _check_selling_price(self): | ||
| for record in self: | ||
| if not float_is_zero(record.selling_price, 2): | ||
| if float_compare(record.selling_price, record.expected_price, 2) == -1: | ||
| raise UserError('The Selling Price must be at least 90% of the Expected Price,' | ||
| ' you must change the expected price to accepted this offer') | ||
|
|
||
| # Computation Fields: | ||
|
|
||
| @api.depends('living_area', 'garden_area') | ||
| def _compute_total_area(self): | ||
| for record in self: # QUESTION is the for each loop here necessary ? or can I just use self ? | ||
| record.total_area = record.living_area + record.garden_area | ||
|
|
||
| @api.depends('offer_ids.price') | ||
| def _compute_best_price(self): | ||
| for record in self: | ||
| if len(record.offer_ids) > 0: | ||
| record.best_price = max(record.offer_ids.mapped('price')) | ||
| else: | ||
| record.best_price = 0. | ||
|
|
||
| @api.onchange('has_garden') | ||
| def _onchange_has_garden(self): | ||
| if self.has_garden: | ||
| self.garden_area = 10 | ||
| self.garden_orientation = 'north' | ||
| else: | ||
| self.garden_area = None | ||
| self.garden_orientation = None | ||
|
|
||
| # Actions buttons | ||
| def action_cancel_property_state(self): | ||
| for record in self: | ||
| if record.state == 'cancelled': | ||
| raise UserError('Cancelled properties cannot be cancelled again !') | ||
| elif record.state == 'sold': | ||
| raise UserError('Sold Properties cannot be cancelled !') | ||
| record.state = 'cancelled' | ||
| return True | ||
| return True | ||
|
|
||
| def action_sell_property_state(self): | ||
| for record in self: | ||
| if record.state == 'sold': | ||
| raise UserError('Sold Properties cannot be sold again !') | ||
| elif record.state == 'cancelled': | ||
| raise UserError('Cancelled properties cannot be sold !') | ||
| record.state = 'sold' | ||
| return True | ||
| return True | ||
|
|
||
| # Actions : | ||
| def action_set_selling_offer(self, buyer, price): | ||
| for record in self: | ||
| if record.buyer_id: | ||
| raise UserError('An offer is already accepted for this house') | ||
| record.buyer_id = buyer | ||
| record.selling_price = price | ||
| return True | ||
| 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,53 @@ | ||
| from odoo import models, fields, api | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class EstatePropertyOffer(models.Model): | ||
| _name = 'estate.property.offer' | ||
| _description = 'Estate Property Offer' | ||
|
|
||
| price = fields.Float(string='Price') | ||
| status = fields.Selection([ | ||
| ('accepted', 'Accepted'), | ||
| ('refused', 'Refused') | ||
| ], copy=False, string='Status') | ||
| validity = fields.Integer(string='Validity (Days)', default=7) | ||
| date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', string='Deadline') | ||
| partner_id = fields.Many2one('res.partner', required=True, string='Partner') | ||
| property_id = fields.Many2one('estate.property', required=True) | ||
|
|
||
| # Constraints: | ||
| _check_price = models.Constraint( | ||
| 'CHECK(price > 0)', | ||
| 'The offer price should be stricty positive' | ||
| ) | ||
|
|
||
| # computed fields | ||
|
|
||
| @api.depends('validity', 'create_date') | ||
| def _compute_date_deadline(self): | ||
| for record in self: | ||
| base_date = record.create_date or fields.Date.today() # Fallback when create_date is not set yet: | ||
| record.date_deadline = fields.Date.add(base_date, days=record.validity) | ||
|
|
||
| def _inverse_date_deadline(self): | ||
| for record in self: | ||
| record.validity = (record.date_deadline - record.create_date.date()).days | ||
|
|
||
| # Action buttons | ||
|
|
||
| def action_accept_property_offer(self): | ||
| for record in self: | ||
| for properties in record.property_id: | ||
| properties.action_set_selling_offer(record.partner_id, record.price) | ||
| record.status = 'accepted' | ||
| return True | ||
| return True | ||
|
|
||
| def action_refuse_property_offer(self): | ||
| for record in self: | ||
| if record.status == 'accepted': | ||
| raise UserError('Accepted offer cannot be refused !') | ||
| record.status = 'refused' | ||
| return True | ||
| 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 models, fields | ||
|
|
||
|
|
||
| class EstatePropertyTag(models.Model): | ||
| _name = 'estate.property.tag' | ||
| _description = 'Estate Property Tag' | ||
|
|
||
| name = fields.Char(string='Name', required=True) | ||
| # Constraints: | ||
| _check_unique = models.Constraint( | ||
| 'UNIQUE (name)', | ||
| 'The 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,8 @@ | ||
| from odoo import models, fields | ||
|
|
||
|
|
||
| class EstatePropertyType(models.Model): | ||
| _name = 'estate.property.type' | ||
| _description = 'Define the Real Estate Property Type' | ||
|
|
||
| name = fields.Char(string='Name', required=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,5 @@ | ||
| id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_estate_property_user,access.estate.property,model_estate_property,base.group_user,1,1,1,1 | ||
| access_estate_property_type_user,access.estate.property.type,model_estate_property_type,base.group_user,1,1,1,1 | ||
| access_estate_property_tag_user,access.estate.property.tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
| access_estate_property_offer_user,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,12 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
| <menuitem id="estate_application_menu_root" name="Real Estate"> | ||
| <menuitem id="estate_advertisement_menu" name="Advertisements" sequence="1"> | ||
| <menuitem id="estate_menu_action" action="estate_property_action"/> | ||
| </menuitem> | ||
| <menuitem id="setting_menu" name="Settings" sequence="2"> | ||
| <menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/> | ||
| <menuitem id="estate_property_tag_menu_action" 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,36 @@ | ||
| <?xml version="1.0"?> | ||
| <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> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <button name="action_accept_property_offer" string="Confirm" type="object" icon="fa-check"/> | ||
| <button name="action_refuse_property_offer" string="Refuse" type="object" icon="fa-level-down"/> | ||
| <field name="status"/> | ||
| </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> | ||
| <group> | ||
| <field name="price"/> | ||
| <field name="partner_id"/> | ||
| <field name="validity"/> | ||
| <field name="date_deadline"/> | ||
| <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,10 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
|
|
||
| <record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
| <field name="name">Tags</field> | ||
| <field name="res_model">estate.property.tag</field> | ||
| <field name="view_mode">list,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,10 @@ | ||
| <?xml version="1.0"?> | ||
| <odoo> | ||
|
|
||
| <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> | ||
|
|
||
| </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.
The one line on the selection field is okay but when you have many values, it's better to have it like this.
Also, it's preferable to have the key as all small letters, so no confusion happens when they are used inside the code in
ifstatements for example.nitpick: some teams might stick to single quotes being only on technical strings (the ones that the user don't see) and double quotes are for the strings that the user can see)
so for example the selection can be ('east', "East") instead of ('east', 'East') but some teams don't do this, they just stick to their own convention which is all single quotes (if possible) or all double quotes
But I see you have all single quotes so good for me but thought to mention it so you know.