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
[All] Improve naming of elements for safe xpath expressions #14649
Comments
Hello, The idea, if easily doable without big overhead could be to have a name with "_filter_num". |
Hi, I was not able to use: context={'search_default_account':1} |
@mart-e any plans on implementing this? |
Are there any compatibility problems by just adding the name attributes throughout the codebase of odoo search views? Would only be nice to get a naming guideline for filters, like "filter_<plausible_name>" and for group-by-only filters maybe filter_group_by_<field_list>". |
@intero-chz @pedrobaeza lets see if it is doable to generate automatically a name based on the filter definition. If something that is properly documented and implementing it is clean and minimal (to check), it could be nice to have. |
@mart-e did you ever get around to this one? |
No, I said, if somebody makes a pull request to fix it, it should be about having an autogenerated name. But we do not plan to implement it ourself at the moment. |
Okay, I misunderstood! Not sure if I can find the time to do something like this, let us leave it open as is for now. |
Ran into this issue? Inheriting product.product_template_search_view I wished to add a filter to the "Group By" field, however like your example above group is not named. If this is a related issue, it makes inheriting flawed. |
Impacted versions: 9.0, 10.0, 11.0 master.
Steps to reproduce: Create a new module in which you do an xpath to an existing view that has an element without any name. Let us take an example from the
marketing_campaign
module. Inmarketing_campaign_views.xml
there is the following code:If I inherit this view and want to replace / modify the filter for "Manual Mode" I cannot xpath by string since this is removed (thank god it was). If I want to replace or remove this line:
My only resort is to either do an xpath on the whole view and remove a whole block or by using an index. For example:
Both of these options are not ideal. Using the index might break if a filter is removed somewhere along or if another custom developed module adds a new filter. In this case I would either get an error if it is removed or I would be doing the wrong things on the wrong filter. In order to be able to xpath safely every element should have a name on which you can xpath. This is safe and cannot produce errors.
This behaviour can be found through the whole Odoo code and goes further than only filters.
We should create a solution in which we can xpath on every element without using an index or removing a big part of the view with an xpath to re-add it again in the xpath.
This is an example Python script to find all filters in Odoo that do not have a name to xpath on (for showing how big the issue is):
When I run this script there are 567
filter
elements in Odoo that do not have a name defined to safely xpath on. This shows how many elements there are through-out Odoo without a name.Edit: as pointed out by @mart-e this number is probably a bit too high, since some filters use multiple lines and my script will not catch this (https://github.com/odoo/odoo/blob/10.0/addons/crm/views/crm_lead_views.xml#L321). This is just a PoC to point out the amount is quite high though.
Expected behavior:
Every element in Odoo should be accessible with an xpath option that is not breaking if something changes.
This behaviour was already discussed with @mart-e and @odony and this issue will allow us to debate about a good solution.
One suggestion is to have default generated names for elements if a name is not specified. Something along the lines of a default string="My field" but then for elements in views. Another option is to simply add the
name=""
on every element, but this was not something @odony was in favour of.The text was updated successfully, but these errors were encountered: