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

How to Extend Receipt Properties

Bulbgraph.png   The contents of this article are available from RMP26

Contents

Overview

This article aims to explain how to add new properties to the Receipt Properties dialog.

It also explains how to make these properties to be saved in the backend, and finally, how to retrieve them for Paid Tickets.

The Model

This example assumes we are working in a module which DB prefix is MYMOD.

We want to add a new properties to make it possible to define a different description for the Sales Order and the Shipment created in the backend.

Finally, in order to make it easier to retrieve this new Shipment description when loading Paid Tickets, we are going to save this description not only in the Shipment but also in the Sales Order that generates it. To do so a new EM_MYMOD_shipmentDescription is created in C_Order table.

Web POS

This is the code that extends default implementation of OB.UI.ModalReceiptPropertiesImpl enyo kind.

 
OB.UI.ModalReceiptPropertiesImpl.extend({
  initComponents: function () {
    var i, customAttributes = [];
 
    // remove standard receipt description
    for (i = 0; i < this.newAttributes.length; i++) {
      if (this.newAttributes[i].name !== 'receiptDescription') {
        customAttributes.push(this.newAttributes[i]);
      }
    }
 
    // add custom receipt properties at the beginning
    customAttributes.unshift({
      kind: 'OB.UI.renderTextMultiLineProperty',
      name: 'receiptDescription',
      modelProperty: 'description',
      i18nLabel: 'MYMOD_TicketDescription'
    }, {
      kind: 'OB.UI.renderTextMultiLineProperty',
      name: 'shipmentDescription',
      modelProperty: 'mymodShipmentDescription',
      extraProperties: ['MaterialMgmtShipmentInOut.description'],
      i18nLabel: 'MYMOD_DeliveryDescription',
    });
 
    this.newAttributes = customAttributes;
    this.inherited(arguments);
  }
});

The newAttributes array keeps all the properties that can be edited. It can be modified in the initComponents method before the kind is rendered.

modelProperty is the name of the property in the local model as well as in the backend, it is used by the OrderLoader to match the property in the entity when loading.

extraProperties allows to define additional properties to be used by the OrderLoader, in this way it is possible to save the same property in different places; in the example in mymodShipmentDescription and in shipment description.

Both modelProperty and extraProperties can specify the backend's entity the property is going to be saved in.

Once saved, it is possible to get paid tickets in the Web POS. This code reads the new property created in this example:

 
@Qualifier(PaidReceipts.paidReceiptsPropertyExtension)
public class PaidReceiptProperties extends ModelExtension {
 
  @Override
  public List<HQLProperty> getHQLProperties(Object params) {
    return new ArrayList<HQLProperty>() {
      private static final long serialVersionUID = 1L;
      {
        add(new HQLProperty("ord.mymodShipmentDescription", "mymodShipmentDescription"));
      }
    };
  }
}

Let's discuss the main aspects in this code:

 
@Qualifier(PaidReceipts.paidReceiptsPropertyExtension)

This Qualifier is defining this class, which needs to extend ModelExtension, to be injected as dependency when generating the query to retrieve Paid Tickets information.

getHQLProperties returns a list of HQLProperty that will be added to the HQL query.

Each of these HQLProperty consists on a first parameter which is the actual HQL property, which will be inserted in the generated query, and a second parameter which is the name this property will take in the local model in Web POS.

Retrieved from "http://wiki.openbravo.com/wiki/How_to_Extend_Receipt_Properties"

This page has been accessed 6,361 times. This page was last modified on 19 July 2013, at 13:54. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.