Different tree views for different groups

Several employees are in different groups and are not ‘allowed’ to see some information from the model. I defined this on field-level in the model and added the invisible state to it. In the form view the fields are removed, but in tree / list view the columns are still there. Also summation is also still there.

Can I define a new tree / list view or what extra steps do I need to take to hide / remove those fields based on the group?

Instead of adding the invisible attribute, you should add a field access rule (on ir.model.field model) to restrict the read acess to this fields.

Tryton will take care of automatically removing from the views the fields that the user is not able to see.

This is because the invisible attribute is intened to be evaluated dinamically. On tree views as it depends on the record the colum will be always there but will be empty for invisible records.

Thanks, that’s working. This also removes the possibility to write to the field which is normal. But in my case it would be nice if it was possible. Because the employee in the group shouldn’t be bothered with product prices, but when they add a product, the price should be added as well in the background. Other employees can deal with the prices but there a several options to achieve this.

So maybe duplicating your tree views with the needed fields and then adding a model “ir.action-res.group”?
See here: modules/stock: 5b7f8347c044 product.xml

1 Like

Then you should set a default value for the field. This value will be set by the server when creating new records.

1 Like

Oh, my … even more possibilities :smile: Now I have to decide which one to pick …

Just curious, how would I do that? The price in the field is based on the listprice of the product. So when a product is added, the price is updated. But now it stays with the default. Can I use a new Transaction() to update the price?

I guess you can override the create method to compute the price from product when the client did not set any value.

Have to try that.

But another question came up … (yeah I’m challenging you all :wink: ). The tree view is also ‘tabbed’ based on the state. This is done with the ir.action.act_window.domain in the XML. I have two groups. The first one is allowed to only see 2 states. The other group can see all the states.

I’ve now duplicated the whole menu / tree / domain and added the menu entry to the different groups. But I was curious if there is another way to achieve this? It basically boils down to allow a list of groups to see a domain tab or not.

In this case I will just add a record rule to restrict the access to the named records and keep all the tabs there.

If the user does not have acess to the other states they will just see them as empty (while the records are already there for other users).

That’s how it is now, but I was thinking to clean up the interface a bit.

Some users are always getting an empty page when they open the tree view because they are not allowed to see orders in state ‘draft’. The tabs are representing the ‘flow’ of the order which is starting with ‘draft’, so I don’t want to change the order of the tabs.

But it works how I wanted it to be, but it’s a lot of duplicate XML. So I thought maybe there is another way.