odoo filter one2many list - odoo

I have a long one2many list and want to show only a subset of this to the user, based on filters that the user may set.
My current approach is to have the original one2many field with all records, and another filtered one2many field.
I compute the filtered list by selecting the subset that is not filtered from the original list.
Further I apply the changes from the filtered list to the original list. So I search for new records in the list and create those as well in the original list. I search for deleted records and delete them from the original list.
This approach works actually, but it requires a bunch of code and only mimics what I would expect from either some native Odoo features or a filterable one2many widget.
Sadly all other approaches I tried did not work:
Searching in one2many lists does not work (e.g. setting search_default_ values in the context). I think it is not supported.
Using a domain to filter the second one2many list does not work (neither in xml nor python code). I think Odoo only allows this for many2many.
I would like to create a filterable one2many widget by extending the normal one. However I don't understand where in the js code the list is populated.
So question is: Is there an easier solution than my current approach to filter a one2many field with native Odoo features?
Or can you help me with the js code of a custom one2many widget to only show a subset of items? For instance, which method is called when the list is populated and in which field are the ids of the items?
Example
I want in my model something as the following:
# This is the original list, with all entries
schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', 'schedule_id', string="Entries")
# This is the filtered list, to be used in the view
# Note: Sadly using the domain here does not work. It always shows all entries. But I hope you get the idea what I want to accomplish.
filtered_schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', string="Filtered Entries", related='schedule_entry_ids', domain='[("phase_id", "=", filter_phase_id)]')
# This is the field that defines the filter
filter_phase_id =
fields.Many2one('mymodule.phase', string="Phase Filter")
Sadly using the domain filter does not work, so my approach at the moment is to create the filtered field as a computed field 'by hand':
filtered_schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', string="Filtered Entries", compute='_compute_filter', inverse='_inverse_filter')
#api.onchange('filter_phase_id', 'schedule_entry_ids')
def _compute_filter(self):
# Populate the filtered list with the elements from the original list, for which the filter condition holds
def _inverse_filter(self):
# Remove elements from the original list if they should be present in the filtered list but aren't anymore (elements have been deleted from the filtered list).
# For all new elements in the filtered list, create a new element in the original list (elements have been created)

I tried all the tricks you mentioned with the same result...
The only workarounds (wich works!) I found is explained below:
1- You can use compute in ..._ids field definition
and put all the 'filtering stuff' in the def
but all lines on 'many' side will be read-only
(it's a problem for me because I need to edit these lines
2- You can define a new computed boolean field on the table wich is
on the "many" side (in your case 'mymodule.schedule_entry') and put
the 'filtering stuff' in the def. It works perfectly and the lines are editable !

Related

How delete Item from ArrayList in Firestore using Koltin

I want to delete one item from the animeId. For example, if I need to remove the animeId[5] or I want to remove the item that the value is equal 5114, how can I do that? I alredy learned how I remove item like the entire animeIdbut not just one item.
Here's an print how the database is organized:
For updating some fields of a document, use the update() method.
If you want to remove a specific item from an Arraylist, you can use a call to:
.update("arrayfield", FieldValue.arrayRemove("itemtoremove"))
For example if you have an arraylist that contains three items as “abc”, “efg”, “xyz”.
And if you want to remove specific item called “efg” from an arraylist you should use a call to:
.update("arrayfield", FieldValue.arrayRemove("efg"))
Please also take a look at this Stackoverflow Link which explains clearly on
how to remove specific items from the array list in the firestore using kotlin.

Modifying Domain of Many2One using Many2Many

Just to preface, I'm using Odoo 10 Enterprise.
I have a custom module with the following (these are just the relevant fields) on its form:
orange_tag_id = This is a Many2Many field with the _Checkboxes widget defined that's connected to a Tags module (we'll just call it orange.tags). This field displays six or seven tags I've created and then applied to various products within the 'product.product/template' module.
orange_child_ids = This is just a One2Many within a child module of the parent module. This lists a product_tmpl_id Many2One and then a read-only copy of orange_tag_id from the parent that just copies whatever is selected in orange_tag_id in the parent form (this was created just in case defining parent.orange_tag_id in the domain didn't work).
When a tag is selected from the orange_tag_id checkbox, it should sort of modify the domain of product_tmpl_id in orange_child_ids and then only display the products in the drop-down display that have been tagged with the selected active tag. I've managed to get this sort of working by just adding the following to the form XML view within orange_child_ids:
<field name="product_tmpl_id" domain="[('orange_tag_id.id','in',parent.orange_tag_id[0])]"/>
This will display only the products that have been tagged with the selected tag with one exception: Tag6's products (just calling it this because its ID was 6) will always display in the drop-down regardless of whether it's selected or not. If Tag2 is selected, then Tag2 and Tag6's products will display. I tried removing Tag6 from any products that had it defined, then deleting the Tag6 record, re-creating the tag, and re-applying it to the relevant products, but the issue persists. I also can only select one tag in the checkbox -- if more than one is selected, I get the following error from product_tmpl_id:
TypeError: not all arguments converted during string formatting
This isn't as big of a deal as not having the correct records displaying, but I'd also like to resolve this, but I'm not entirely sure how.
I've searched for hours and am aware of methods where this can be done in self-hosted installations, however, we're using Odoo 10 Enterprise (I've omitted the required x_ in my aforementioned custom fields just for easier readability), and I have no access to the file system and consequently can't make modifications where that's required. I've been trying to figure this out using just the Developer Tools and my administrative access to the database's settings.
I've messed around a lot with the domain, looked through many questions and forum threads, and what I have was the only thing that worked. Is there any way to get this working correctly within the limitations of Enterprise?
Much obliged.
It appears that adding [2] after the [0] makes everything work and resolves the two issues I was having, so:
<field name="product_tmpl_id" domain="[('orange_tag_id.id','in',parent.orange_tag_id[0][2])]"/>
This will filter the results of the Many2One based on the records selected in the Many2Many field.
While [('orange_tag_id.id','in',parent.orange_tag_id[0][2])] will work, it is extremely obscure.
I advise you to go with [('orange_tag_id.id','in',parent.orange_tag_id.ids)]

Creating a feature class in ArcGIS 10

I am trying to create a feature class from another feature class via below:
arcpy.CreateFeatureclass_management(path, name, "POLYGON")
In ArcGIS, it is creating the fields Shape, Shape_Length, and Shape_Area. I added additional fields to the newly feature class.
cursor = arcpy.da.SearchCursor("old featureclass", ["Shape#", "*"]
insert = arcpy.da.InsertCursor("new featureclass", ["*"]
for i in cursor:
insert.insertRow(i)
I am getting an error:
Sequence size must match size of the row
This is because the newly feature class has added additional fields as I mentioned above. Then I tried
for i in cursor:
append newly array with (ShapeLength, and ShapeArea)
insert.insertRow(newlyarray)
It worked fine but the Shape_Area and Shape_Length is returning zero. I've also tried to calculate field area and it didn't work as well.
Can someone please help me with this issue? The geometry shape is a polygon but the shape area and shape length won't populate based of the pre-existing shape.
I think what you want to do is:
Get the fields list from the old shapefile,
Add the desired fields to the new file,
then iterate over each field (or just the ones you want to copy) of each row from the old file and copy the value into its corresponding field in the new file.
Then you can add your brand new new fields whenever you like and this copying function won't be affected if it refers to fields by name.
Another method would be to literally copy the old shapefile using the copy tool, then edit the copied file.

yadcf externally triggered filters 'shut off' the actual filtering

I am trying to set my yadcf filters up so they can be triggered from a call (link) from another page. I have an angular single page application that has three tabs on it. If a user clicks a link on lets say the first tab, they will go to another tab (separate table) that contains detailed information relevant to the link they click. (e.g. They are on a row in a table that deals with Apple Mac Pro computers. They see that there are 20 skus currently in the system. They click the number 20 and they go to a lower tab (different table) that contains all the information for those skus). There is no server call in the middle. All the data is loaded in all the tables when the application loads up. So, they are simply clicking a link that applies a filter to the detail table.
yadcf can do this through externally_triggered filters. However, when I set 'externally_triggered': true, it stops the actual filters from working on the details table. (In other words, I can no longer go to that table and manually adjust the filters.)
Does anyone know a way around this issue?
It appears the externally_triggered: true switch does not need to be turned on to use yadcf.exFilterColumn() method. I do not understand when it does need to be turned on, but I am able to call the exFilterColumn method and pass it the options needed to 'prefilter' the table while still retaining the ability to filter the table manually.
externally_triggered and yadcf.exFilterColumn are not related in any way, indeed when yadcf.exFilterColumn is used filters behave a bit differently - they are not filtering on change/keyup/etc , but rather only when the uadcf.exFilterExternallyTriggered function is called (its on purpose and all is explained in the docs)
Here is the relevant text from the docs of the externally_triggered, here it is:
* externally_triggered
Required: false
Type: boolean
Default value: false
Description: Filters will filter only when yadcf.exFilterExternallyTriggered(table_arg) is called
Special notes: Useful when you want to build some form with filters and you want to trigger the filter when that form
"submit" button is clicked (instead of filtering per filter input change)
Here is the showcase page

How to display custom fields in rally?

I have a ruby script that is trying to pull up some custom fields from Rally, the filter works just fine ( the filter contains one of the custom fields i want to pull up) but when I try to display it, it doesn't show up in the list (the value returned for all custom fields is blank, while appropriate values are returned for FormattedID, Name, Description).
Here's the link [link]http://pastebin.ubuntu.com/6124958/
Please see this post.
Do you fetch the fields?
What version of WS API are you using? If it is v2.0 is c_ prepended to the name of the field in the code?
How is the field spelled in your code and how that spelling compares to Name and Display Name of the field in UI?
There is another reason why custom fields might not appear (other than the versioning and 'c_' issues nickm mentioned). I just found this out after a ton of head banging. The Rally SDK's ui stuff will filter out all fields that are hidden (such as _ref, or other 'hidden' custom fields) so you cannot view them in your apps in grids, charts, etc. For example, when constructing a Rally.ui.grid.Grid, a class called Rally.ui.grid.ColumnBuilder is constructed and it executes a command on the columns of the chart that look like this:
_removeHiddenColumns: function (columns) {
return _.filter(columns, function (column) {
return !column.modelField || !column.modelField.hidden;
});
},
As you can see, if you try to display any fields that are hidden (like _ref for example) in a grid, the column gets removed. So, although you may be fetching the custom fields, they will not show up unless those fields are not 'hidden'.