-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[ADD] estate: created a new module, model defination, added security … #323
base: 18.0
Are you sure you want to change the base?
Conversation
…file, created views, actions & menuitems, created custom list view.
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.
Hello @padi-odoo ,
I've added some suggestions. Please have a look at them.
Some general instructions:
- Please make sure to add a new line at the end of every file.
- Please ensure the entire module follows coding guidelines.
estate/__manifest__.py
Outdated
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.
Why there is no version in manifest file?
Check the proper sequencing for fields in manifest file.
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.
Included version and proper sequencing is done
estate/models/estate_property.py
Outdated
@@ -0,0 +1,32 @@ | |||
from datetime import datetime, timedelta, date | |||
from dateutil.relativedelta import relativedelta |
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.
Why you have imported this if not used?
Please make sure to import only the required libraries.
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.
Removed extra imports from the file
estate/views/custom_listview.xml
Outdated
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.
Why there is need of new file for adding views?
Can't we add the views in its appropriate file (estate_property_views.xml)?
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.
Separated files for menuitems and views, actions as suggested
estate/models/estate_property.py
Outdated
_name = "estate.property" | ||
_description = "Estate Property Model" | ||
|
||
name = fields.Char(string="Your name", required=True, default="Unknown") |
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 string for the fields should be appropriate. Also what's the need of adding "default" parameter here?
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.
Modified the string and suggested changes are done
estate/models/estate_property.py
Outdated
_description = "Estate Property Model" | ||
|
||
name = fields.Char(string="Your name", required=True, default="Unknown") | ||
active = fields.Boolean(default=False) |
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.
What is the purpose of active field? and why you have passed 'False' in default?
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.
Active field is used for filtering purpose between currently active and inactive records, default = False sets by default record as inactive
estate/models/estate_property.py
Outdated
|
||
name = fields.Char(string="Your name", required=True, default="Unknown") | ||
active = fields.Boolean(default=False) | ||
state = fields.Selection(selection = [('New', 'New'), ('Offer Received', 'Offer Received'), ('Offer Accepted', 'Offer Accepted'), ('Sold', 'Sold'), ('Cancelled', 'Cancelled')], default="New") |
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.
Why there is no string for this field?
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.
Added string with appropriate value
estate/models/estate_property.py
Outdated
postcode = fields.Char() | ||
date_availability = fields.Date(copy=False, default=fields.Date.today() + timedelta(days=+90)) | ||
expected_price = fields.Float(required=True) | ||
selling_price = fields.Float(readonly=True, copy=False) |
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.
Could you explain the purpose of "copy", "required", "readonly" parameters?
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.
Copy decides the whether field's value is duplicated or not when the record is duplicated.
Required decides whether a field must have a value before saving the record.
Readonly prevents the alteration by giving access to read the data only
<menuitem id="test_model_menu_action" action="estate_property_action" /> | ||
</menuitem> | ||
</menuitem> | ||
|
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.
Remove this extra line.
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.
Suggested Changes are done.
from odoo import models, fields | ||
|
||
class EstateProperty(models.Model): | ||
|
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.
Remove this extra line
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.
Suggested changes are done
…ed custome form view & search view, seperated files for menuitems and views, actions.
2f8890a
to
4f0b885
Compare
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.
Hello @padi-odoo ,
Great work for now!
I've added some comments and suggestions, please go through it and if you have any query feel free to reach me out.
Thanks
estate/__manifest__.py
Outdated
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.
Make a habit to add description so others will know what is the purpose of this module.
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.
Added description in manifest.py file
estate/models/__init__.py
Outdated
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.
Import should be in alphabetical order.
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.
Rearranged imports in alphabetical order
estate/models/estate_property.py
Outdated
@@ -0,0 +1,44 @@ | |||
from datetime import timedelta | |||
|
|||
from odoo import models, fields |
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 import should follow alphabetical order.
Refer doc: https://www.odoo.com/documentation/18.0/contributing/development/coding_guidelines.html#imports
estate/models/estate_property.py
Outdated
('west', 'West') | ||
], string="Garden Orientation", help="Orientation of the garden" | ||
) | ||
property_type = fields.Many2one(comodel_name="estate.property.type", string="Property Type") |
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.
No need of writing 'comodel_name', check other occurrences as well.
property_type = fields.Many2one(comodel_name="estate.property.type", string="Property Type") | |
property_type = fields.Many2one("estate.property.type", string="Property Type") |
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.
Suggested changes are implemented
estate/models/estate_property.py
Outdated
offer_ids = fields.One2many(comodel_name="estate.property.offer", inverse_name="property_id", string="Offers" | ||
) |
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.
offer_ids = fields.One2many(comodel_name="estate.property.offer", inverse_name="property_id", string="Offers" | |
) | |
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") |
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.
Suggested changes are done
status = fields.Selection([ | ||
('accepted', 'Accepted'), | ||
('refused', 'Refused') | ||
], string="Status" ,copy=False | ||
) |
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.
status = fields.Selection([ | |
('accepted', 'Accepted'), | |
('refused', 'Refused') | |
], string="Status" ,copy=False | |
) | |
status = fields.Selection([ | |
('accepted', 'Accepted'), | |
('refused', 'Refused') | |
], string="Status", copy=False) |
Refer codebase to see proper syntax for fields. Also check other occurences as well.
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.
Corrected the syntax according to codebase
@@ -0,0 +1,10 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<odoo> | |||
|
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.
Remove extra lines
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.
Suggested changes are done
<field name="model">estate.property</field> | ||
<field name="arch" type="xml"> | ||
<list string="Properties"> | ||
<field name="name" width="20%" /> |
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.
<field name="name" width="20%" /> | |
<field name="name" width="20%"/> |
check other occurrences as well.
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.
Suggested changes are done
… methods and constraints using SQL and Python
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.
@api.depends('create_date', 'validity') | ||
def _compute_date_deadline(self): | ||
for record in self: | ||
create_date = record.create_date.date() if record.create_date else fields.Date.today() |
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.
Do we really need this variable for create date??
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.
Optimized code by removing unnecessary variable creation(create_date) as suggested.
existing_accepted_offer = self.search([ | ||
('property_id', '=', record.property_id.id), | ||
('status', '=', 'accepted') |
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 just need to check if there is an existing offer 'accepted' so can't we just add limit to it? Refer codebase for it.
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.
Added limit attribute to self.search method to stop searching after we get 1 record instead of running complete for loop.
|
||
record.status = 'accepted' | ||
record.property_id.buyer_id = record.partner_id.id | ||
record.property_id.selling_price = record.price |
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.
What impact should be there in property on accepting any offer?
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 buyer_id field of the property should be updated with the buyer (partner_id) from the accepted offer.
- The selling_price should be set to the price of the accepted offer if constraints are satisfied.
- Offer's status should be set to 'accepted'.
record.property_id.buyer_id = record.partner_id.id | ||
record.property_id.selling_price = record.price | ||
|
||
def action_refuse(self): |
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.
What if the property is already sold or cancelled, will there be any use for this button then??
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.
If the property is already sold or cancelled, it would be logical to invisible the "Accept" and "Refuse" buttons, since the property status is final and no further offers can be accepted or refused.
estate/models/estate_property.py
Outdated
else: | ||
record.state = 'cancelled' | ||
|
||
@api.constrains('selling_price') |
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.
Could you please verify the place of constrains method? Please follow coding guidelines
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.
What is the difference between SQL and python constrains??
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.
SQL constraints are applied directly at the database level and ensuring data correctness before the data is stored in the database.
Python constraints are defined within the Odoo models and applied by the logic we write in python functions, not directly by the database.
Corrected the place of constraint method.
…widget for state representaion,model & manual ordering and conditional buttons visibility
…file, created views, actions
& menuitems, created custom list view.