View source | Discuss this page | Page history | Printable version   

How to Extend Models


This document explains an example how to extend a model used in Web POS. The list of models that can be extended and the details needed to extend it are described in This document

The typical case a developer will require to extend an existing Web POS model is when in a new Openbravo module are added one or more columns to a table that is used in Web POS (for example Products, Business Partner, ...) and these new columns needs to be used also in the Web POS terminal.

This example shows how extend the products model adding two existing columns.

Extending server side

To extend the server side you must create a new java class that extends the class ModelExtension.

The class must be annotated with the java qualifier used to extend the products model and the columns added must belong to one of the tables retrieved by the server side model.

Each of the columns added is an instance of HQLProperty. This instance has two values hqlProperty that is an HQL expression based on the tables used by the model and jsonName the name used in the JSON object sent to the browser.

import java.util.Arrays;
import java.util.List;
import org.openbravo.client.kernel.ComponentProvider.Qualifier;
import org.openbravo.retail.posterminal.master.Product;
public class NewProductProperties extends ModelExtension {
  public List<HQLProperty> getHQLProperties(Object params) {
    return Arrays.asList(
            new HQLProperty("product.weight", "weight"), 
            new HQLProperty("", "taxcategoryname"));

Extending the client side

To extend the client side of the model you must add the new columns added in the server side.

In each of the columns added the property name must match with the jsonName value of the HQLProperty added in the server side. The rest of values describes the properties of each column in the client model:

    name: 'weight',
    column: 'weight',
    primaryKey: false,
    filter: false,
    type: 'NUMERIC'
  }, {
    name: 'taxcategoryname',
    column: 'taxcategoryname',
    primaryKey: false,
    filter: false,
    type: 'TEXT'

If needed you can also add client side indexes based on the new columns added. Indexes are usually necessary if you want to execute queries that filter based on the new columns added.

This is an example of a new index for the Products model based on the new added column taxcategoryname.

    name: 'inx_taxcategoryname',
    columns: [{
      name: 'taxcategoryname',
      sort: 'asc'

Retrieved from ""

This page has been accessed 9,717 times. This page was last modified on 27 March 2015, at 11:44. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.