ADempiere 3.6 Cookbook
上QQ阅读APP看书,第一时间看更新

Creating a read-only tab

Sometimes there may be a need where not the complete window should be made read-only. Rather, a particular tab needs to be made read-only. For example, there is a user who, as per their role, shall capture the payments against an invoice. He/she should not be allowed to create an invoice in the system. To address this need, we can have a window where one tab is to capture the payment detail and another one showing the outstanding invoices, which we will make read-only. This way, on the single window, the user will be able to refer to the outstanding invoices and at the same time receive payments towards them.

In our MOM case study, Let us say we want to add a rule that states only an admin user shall be allowed to edit the discussion items of an MOM. Let us see how we can do this.

How to do it...

  1. Log in as System/System with the System Administrator role.
  2. Go to the Window, Tab, and Field window and look for the Minutes Of Meeting window.
  3. Go to the Discussion Detail tab detail on the Tab.
  4. Specify the following in the Read Only Logic field, as shown in the following screenshot:
    @#AD_Role_Name@='GardenWorld User'
    
    How to do it...
  5. Log out and log in as GardenUser/GardenUser with the GardenWorld User role.
  6. Go to the Minutes Of Meeting window. The system will show you the list and the New Record button will be disabled, because, for this role, we have set the read-only logic. Also notice that the read-only tab label is displayed in italic, as shown in the following screenshot:
    How to do it...
  7. Log out and log in as GardenAdmin/GardenAdmin with the GardenWorld Admin role.
  8. Go to the Minutes Of Meeting window. This user will have the permission to create new discussion items, as shown in the following screenshot:
How to do it...

How it works...

The Read Only Logic, in step 3, is the key here. ADempiere evaluates the expression mentioned in this field at the time of displaying a tab. If the expression evaluates to true, then the tab becomes read-only. Otherwise, it remains editable. You can build the expressions using this context. In this recipe, we used the #AD_Role_Name context variable in the expression to check if the role name of the current logged in user is "GardenWorld user", and then made the tab read-only. To view the context information, click on Tools | Preference on any window and go to the Context tab.

There's more...

In the recipe, we saw how to make a tab read-only based on certain conditions, which get evaluated at runtime. There may be a case where a tab has to be read-only in all the cases.

Making the tab read-only for everyone

Say, irrespective of the user or role or any other condition, you want to make a tab read-only. To do this, on the Tab tab of the Window, Tab, and Field windows for the intended tab, check the Read Only checkbox and save it, as shown in the following screenshot:

Making the tab read-only for everyone