Skip to Content
Menu
This question has been flagged
1 Reply
716 Views

Hello,


I'm currently working on Odoo v16 SaaS Studio reports (tested on Runbot). My goal is to make certain fields visible using the "Visible if" function of the Studio module.


My condition for invisibility is based on tags/labels, such as tag IDs of sales orders.


The error occurs only if multiple tags are selected and you try to apply an invisibility condition on one of them.


Here's the modification you should have in your XML view after applying the condition in Studio:


>xpath expr="/t[1]/div[1]/table[1]/thead[1]/tr[1]/th[3]" position="attributes">

   name_field_tag == 8

>/xpath>


Here's a typical example of the error you might encounter:


ValueError: Expected singleton: crm.tag(1, 8)

Template: studio_customization.studio_report_docume_ac48d7d3-a5b4-4b14-95e2-970f66b1f11e_document

Path: /t/div/table/thead/tr/th[3]

Node:

doc.x_studio_etiquette_sales.id == 2"/>


I haven't found any solutions other than "Resorting to development, which is not possible because we are on SaaS and intend to stay that way..."


Thank you.


Avatar
Discard
Best Answer

Hi,

The error you are encountering is because the Studio report is trying to evaluate a condition that involves multiple records. The name_field_tag == 8 condition is attempting to check if a single tag ID is equal to 8, but the expression is being evaluated for multiple tag records.

In Odoo Studio, when you apply a "Visible if" condition on a field based on a Many2many or One2many relationship, the condition is evaluated for each record in that relationship. If there are multiple records, the condition needs to be modified to handle that case.

Here's a potential solution:

  1. Instead of using the == operator, use the in operator to check if the tag ID is present in the set of related records.
  2. Use the mapped function to get a list of tag IDs from the related records.

The modified condition in the XML view should look like this:

{'invisible': [('name_field_tag', 'not in', [8])]}



This condition checks if the tag ID 8 is present in the list of tag IDs related to the record. If the tag ID 8 is not present, the field will be visible; otherwise, it will be invisible.

If you want to make the field invisible when any of the selected tags match a specific set of tag IDs, you can modify the condition as follows:

{'invisible': [('name_field_tag.ids', '&', [1, 8])]}

This condition checks if the set of tag IDs related to the record contains both 1 and 8. If both tag IDs are present, the field will be invisible; otherwise, it will be visible.

Or if you can done this using studio option try it in this way:



Hope it helps

Avatar
Discard
Author

Hello,

Indeed, you need to use the "mapped" function in the view.

So, I have something like this:

>xpath expr="/t[1]/t[1]/div[1]/div[5]/div[1]/span[2]" position="attributes">
>attribute name="t-if">not 8 in doc.tag_ids.mapped('id')</attribute<
>/xpath>

This bypasses the singleton error!

Have a great day :)

Best regards