Creating Virtual Fields Using Property Fields in the Openbravo ERP Platform
In our previous blog post, we looked at how to create virtual columns using Client Class. In this one, we will see how to create virtual columns using property fields. The basic difference between a client class and property field is that client class is more suitable for UX enhancement or styling, whereas property fields are those fields whose values are derived from existing fields in the records. In the below example, we will see a scenario where this might be useful.
Note: The examples provided below are available as a module here.
Use case 1
In the Product window, there is a tab called Price, where the price list version, the unit price and the list price are listed.
But in a multicurrency environment, unless we navigate to the price list version and check the price list parent tab, we cannot know for which currency the prices are listed. To fix this, let’s add the currency property field to the Price tab.
Here the value of the property field is priceListVersion.priceList.currency. The price list version is already available in the window and we are using this information to navigate to its parent tab Price List and fetch the value of the currency field present in it. Once we compile and restart the tomcat server, here’s what the Price tab will look like.
Use case 2
The warehouse admin is cross-verifying the Goods Receipt and the actual goods that have been received and notices a discrepancy. Admin decides to call the supplier to inform them about this. The Goods Receipt window has the Partner name and the Partner Address.
If we click on the Partner Address tab, we can notice the phone number of the Supplier.
Imagine this action has to be performed quite frequently to get any information or even for a simple confirmation. So let’s speed up this process by adding the Supplier Phone number as a property field in the Goods Receipt window.
The definition of the property field is pretty simple as we are just fetching the phone number field corresponding to the partner address. Here is what the output will look like.
In general, property fields are more suitable in scenarios where you are going to display more than one field from a referenced entity. Instead of adding new fields for each required field in the database and setting the value from the other entity, we can just add one field and use it as a reference for the other fields.
Did you find useful this information? Do you have any doubts when creating them? Just let me know in the comments section