Skip to content
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

Draft
wants to merge 5 commits into
base: 18.0
Choose a base branch
from

Conversation

padi-odoo
Copy link

…file, created views, actions

& menuitems, created custom list view.

…file, created views, actions

& menuitems, created custom list view.
@robodoo
Copy link

robodoo commented Feb 5, 2025

Pull request status dashboard

Copy link

@mobe-odoo mobe-odoo left a 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.

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.

Copy link
Author

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

@@ -0,0 +1,32 @@
from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta

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.

Copy link
Author

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

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)?

Copy link
Author

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

_name = "estate.property"
_description = "Estate Property Model"

name = fields.Char(string="Your name", required=True, default="Unknown")

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?

Copy link
Author

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

_description = "Estate Property Model"

name = fields.Char(string="Your name", required=True, default="Unknown")
active = fields.Boolean(default=False)

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?

Copy link
Author

@padi-odoo padi-odoo Feb 6, 2025

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


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")

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?

Copy link
Author

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

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)

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?

Copy link
Author

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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Remove this extra line.

Copy link
Author

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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Remove this extra line

Copy link
Author

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.
Copy link

@mobe-odoo mobe-odoo left a 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

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.

Copy link
Author

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

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.

Copy link
Author

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

@@ -0,0 +1,44 @@
from datetime import timedelta

from odoo import models, fields

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

('west', 'West')
], string="Garden Orientation", help="Orientation of the garden"
)
property_type = fields.Many2one(comodel_name="estate.property.type", string="Property Type")

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.

Suggested change
property_type = fields.Many2one(comodel_name="estate.property.type", string="Property Type")
property_type = fields.Many2one("estate.property.type", string="Property Type")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes are implemented

Comment on lines 43 to 44
offer_ids = fields.One2many(comodel_name="estate.property.offer", inverse_name="property_id", string="Offers"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes are done

Comment on lines 8 to 12
status = fields.Selection([
('accepted', 'Accepted'),
('refused', 'Refused')
], string="Status" ,copy=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Author

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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Remove extra lines

Copy link
Author

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%" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name="name" width="20%" />
<field name="name" width="20%"/>

check other occurrences as well.

Copy link
Author

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
Copy link

@mobe-odoo mobe-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @padi-odoo ,

Please see the review comments.

Thanks!

@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()

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??

Copy link
Author

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.

Comment on lines +32 to +34
existing_accepted_offer = self.search([
('property_id', '=', record.property_id.id),
('status', '=', 'accepted')

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.

Copy link
Author

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

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The buyer_id field of the property should be updated with the buyer (partner_id) from the accepted offer.
  2. The selling_price should be set to the price of the accepted offer if constraints are satisfied.
  3. 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):

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??

Copy link
Author

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.

else:
record.state = 'cancelled'

@api.constrains('selling_price')

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

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??

Copy link
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants