-
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: Added estate training module #349
base: 18.0
Are you sure you want to change the base?
Conversation
smra-odoo
commented
Feb 13, 2025
- created a new module, estate.
- added init, manifest files.
- added estate_property model and access rights for the model.
- created a new module, estate. - added init, manifest files. - added estate_property model and access rights for the model.
estate/__manifest__.py
Outdated
'application': True, | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
] |
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.
Please add Licence version
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.
👍
estate/security/ir.model.access.csv
Outdated
@@ -0,0 +1,3 @@ | |||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | |||
|
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.
there is no need to keep the blank line in this 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.
👍
- Added new models, estate_property_/offer/type/tags. - Added menus, estate_menu, Advertisement->Properties, Settings->Property Types, Property Tags - Added their actions and views, estate_actions, estate_property_/views/offer_views/tags_views/types_views. - Added relations between the models using Many2one, Many2many and One2many. - Added compute and onchange fields for getting total area of property, best price and if there is garden, then only show garden related fields. - The new models are for new features like property offers, types, tags. Also added each of their list and form views.
else: | ||
record.best_price = 0 | ||
|
||
@api.onchange("garden") |
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.
In Odoo we prefer not to use 'onchange' generally, what's the reason behind that?
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 main reason for not using 'onchange' method generally because it does not get triggered outside of form view, so when we create any record programmatically it does not automatically gets triggered and creates inconsistency.
property_id = fields.Many2one("estate.property", string="Properties", required=True, ondelete="cascade") | ||
|
||
validity = fields.Integer(default="7") | ||
date_deadline = fields.Date(compute="_compute_date_deadline",inverse="_inverse_date_deadline",store=True) |
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.
whats the purpose of using inverse field here? Also, why are we using store=True, what does that do?
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 inverse function is used to allow bidirectional updates between a computed field (date_deadline) and its dependent field (validity) and without an inverse function, date_deadline would be read-only. The main purpose to use inverse function is to let users to manually set date_deadline, and then automatically update validity accordingly.
The store=True attribute makes sure that the computed field's value is stored in the database,so we can filter and search records by date_deadline.
</field> | ||
</record> | ||
|
||
<record id="estate_property_offer_view_form" model="ir.ui.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.
what is the difference between ir.actions.act_window and ir.ui.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.
The main difference between them is, it.actions.act_window defines an action that opens a specific model in a particular view (form, tree, kanban, etc.), it also links a menu item to view and it.ui.view defines the structure/layout of a view for a 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.
can you give a little bit clarity on this?
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.
- ir.actions.act_window is an action definition, it defines an action that odoo executes when a menu item or button is clicked. It specifies which model to open and in which view type (list, form, kanban, etc.).
- ir.ui.view is an view definition, it defines the structure and layout of a view. It specifies how fields are displayed in list, form, kanban, or other views. It only determines the UI structure.
- Flow - A menu item or button triggers an action (ir.actions.act_window). The action opens a model in a specified view type (list, form, etc.). The view layout is defined by ir.ui.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.
Nice
estate/__manifest__.py
Outdated
@@ -0,0 +1,22 @@ | |||
{ | |||
'name': "estate", | |||
'version': '1.0', |
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.
give proper version for the module, since its a module for Odoo v18 we will give it as 18.0, and then updating it with additional features
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 Sold, Cancel buttons property and accepted, refused buttons for offer. - Added SQL and Python Constraints for all price related fields, selling price cannot be negative and expected price should be strictly greater than 0. - Now new records can be added through (inline) list view of property and offers. - Added widget to view property state in top right corner. - Added list ordering for property and offers in deterministic order. - Added conditions for sold and cancel for property, accepted and refused button for offer so respective state stay consistent. - Added Offer Stat button for easier navigation to offer.
</field> | ||
</record> | ||
|
||
<record id="estate_property_offer_view_form" model="ir.ui.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.
can you give a little bit clarity on this?
name = fields.Char(required=True) | ||
color = fields.Integer(string="Color") | ||
|
||
_sql_constraints = [ |
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 can be the substitute for this constraint? Why that substitute is not used 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.
There are two types of constraints in odoo, python constraints and sql constraints. for this constraint the substitute would be
@api.constrains('name') def _check_unique_name(self): for record in self: existing_tag = self.search([('name', '=', record.name), ('id', '!=', record.id)]) if existing_tag: raise ValidationError("Property Tags should be unique!")
this substitute is not used here as sql constraints prevent duplicates at the database level, which is faster and more efficient. sql constraints guarantee uniqueness at all times whereas python constraints can be bypassed in few cases. Using sql constraints avoids race conditions as it has no concurrency issues whereas python constraints has concurrency issues. Python constraints require a database query (search()) every time a record is saved, which is slower than an indexed sql constraint. So to get uniqueness every time the substitute is not used here.
|
||
@api.depends("validity","create_date") | ||
def _compute_date_deadline(self): | ||
for record in 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.
why 'for record in self', why are we not directly updating self 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.
Here, self can be a recordset containing multiple records, not just a single record so if we tried to update self.date_deadline directly, it would attempt to assign a single value to all records, which is incorrect. Using 'for record in self' we are updating each record individually with its correct date_deadline value as each record may have different create_date and validity.
…rs, kanban view to property and added estate_account module. - Added business logic to the CRUD methods, the state should change to offer received when creating an offer, deletion of property should not be possible unless its new or cancelled. - Added res_users inheritance and its view so that in users form we can see which all property he has. - Added estate_account module to create an invoice for customer directly and it is sent to invoices app using inheritance, added invoice lines like administrative fees and 6% of selling price. - Added kanban view of properties grouped by property type, where more information about property is visible based on the conditions.
- Missed Adding res_users_view and its reference to manifest file so added it now.
- Added security rules so each company has its own data.
Added 2 groups, agent and manager. Restricted access for agents, they can only read types and tags. No group can delete anything for consistency. Added record rules so that each agent can only see his/her properties or not assigned properties. Added check_access for security while creating invoice. Added visiblity security as agents cannot see settings but can access already defined types/tags but cannot create new ones.
Created the basic structure for this module.
warranty/__manifest__.py
Outdated
Extend Warranty. | ||
""", | ||
'data': [ | ||
'views/estate_actions.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.
Why we have this file estate_actions.xml in this?
Its a good practice to push code when a functionality or feature is complete or we can say is workable enough and won't affect other features/functionalities.
- Added Demo data so when the Database is created we get some records already.
- Added a report where each property can build report of its offer. - Added a report for salesman/users where through res.users they can build report for all of their properties. - Added a inherited report as if the property has already been invoiced, it shall show in the property report.
- Updated warranty_configuration model by adding fields. - Added menu in the configurations setting and warranty_configuration's list view. - Added warranty_configuration's form view to let warranties be added. - Added product_template model for adding a new field warranty to know if the product has warranty available or not. - Added its boolean view in the sales page of the product in warranty_views. - Added wizard in sale_order and its button in the warranty_sale_order_views for adding warranty. - Added wizard's both model and view to add warranties to products which have warranty available. - Added sale_order_line to unlink the related warranties to their products.