View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

POS/2.30/HowTos/How To Add a New Field in Product Panel

Contents

How to add a new field in Product panel

Objective

This how-to describes how to add a new information for products and allows to edit it through the products panel of Openbravo POS.

Process

Step 1

ALTER TABLE PRODUCTS ADD COLUMN FLAG BOOLEAN DEFAULT b'0';

Step 2

Edit ProductsEditor class (com.openbravo.pos.inventory)

jcboFlag.addActionListener(dirty);
jcboFlag.setSelected(false);
jcboFlag.setSelected(false);
jcboFlag.setSelected(((Boolean)myprod[17]).booleanValue());
jcboFlag.setSelected(false);
jcboFlag.setSelected(((Boolean)myprod[17]).booleanValue());
myprod[17] = Boolean.valueOf(jcboFlag.isSelected());

Step 3

Edit DataLogicSales class (com.openbravo.pos.forms).

new Field("FLAG", Datas.BOOLEAN, Formats.BOOLEAN)
public final ProductInfoExt getProductInfo(String id) throws BasicException {
       return (ProductInfoExt) new PreparedSentence(s
           , "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE ID = ?"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).find(id);
   }
   public final ProductInfoExt getProductInfoByCode(String sCode) throws BasicException {
       return (ProductInfoExt) new PreparedSentence(s
           , "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE CODE = ?"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).find(sCode);
   }
 public final ProductInfoExt getProductInfoByReference(String sReference) throws BasicException {
       return (ProductInfoExt) new PreparedSentence(s
           , "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE REFERENCE = ?"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).find(sReference);
   }
public List<ProductInfoExt> getProductCatalog(String category) throws BasicException  {
       return new PreparedSentence(s
           , "SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.TAXCAT, P.CATEGORY, P.ATTRIBUTESET_ID, P.IMAGE, P.ATTRIBUTES, P.FLAG " +
             "FROM PRODUCTS P, PRODUCTS_CAT O WHERE P.ID = O.PRODUCT AND P.CATEGORY = ? " +
             "ORDER BY O.CATORDER, P.NAME"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).list(category);
   }
   public List<ProductInfoExt> getProductComments(String id) throws BasicException {
       return new PreparedSentence(s
           , "SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.TAXCAT, P.CATEGORY, P.ATTRIBUTESET_ID, P.IMAGE, P.ATTRIBUTES, P.FLAG " +
             "FROM PRODUCTS P, PRODUCTS_CAT O, PRODUCTS_COM M WHERE P.ID = O.PRODUCT AND P.ID = M.PRODUCT2 AND M.PRODUCT = ? " +
             "AND P.ISCOM = " + s.DB.TRUE() + " " +
             "ORDER BY O.CATORDER, P.NAME"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).list(id);
   }
public final SentenceList getProductList() {
       return new StaticSentence(s
           , new QBFBuilder(
             "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE ?(QBF_FILTER) ORDER BY REFERENCE", new String[] {"NAME", "PRICEBUY", "PRICESELL", "CATEGORY", "CODE"})
           , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING})
           , ProductInfoExt.getSerializerRead());
   }
   
   // Products list
   public SentenceList getProductListNormal() {
       return new StaticSentence(s
           , new QBFBuilder(
             "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE ISCOM = " + s.DB.FALSE() + " AND ?(QBF_FILTER) ORDER BY REFERENCE", new String[] {"NAME", "PRICEBUY", "PRICESELL", "CATEGORY", "CODE"})
           , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING})
           , ProductInfoExt.getSerializerRead());
   }
   
   //Auxiliar list for a filter
   public SentenceList getProductListAuxiliar() {
        return new StaticSentence(s
           , new QBFBuilder(
             "SELECT ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, TAXCAT, CATEGORY, ATTRIBUTESET_ID, IMAGE, ATTRIBUTES, FLAG " +
             "FROM PRODUCTS WHERE ISCOM = " + s.DB.TRUE() + " AND ?(QBF_FILTER) ORDER BY REFERENCE", new String[] {"NAME", "PRICEBUY", "PRICESELL", "CATEGORY", "CODE"})
           , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING})
           , ProductInfoExt.getSerializerRead());
   }
public final SentenceList getProductCatQBF() {
       return new StaticSentence(s
           , new QBFBuilder(
               "SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.CATEGORY, P.TAXCAT, P.ATTRIBUTESET_ID, P.IMAGE, P.STOCKCOST, P.STOCKVOLUME, CASE WHEN C.PRODUCT IS NULL THEN " + s.DB.FALSE() + " ELSE " + s.DB.TRUE() + " END, C.CATORDER, P.ATTRIBUTES, P.FLAG " +
               "FROM PRODUCTS P LEFT OUTER JOIN PRODUCTS_CAT C ON P.ID = C.PRODUCT " +
               "WHERE ?(QBF_FILTER) " +
               "ORDER BY P.REFERENCE", new String[] {"P.NAME", "P.PRICEBUY", "P.PRICESELL", "P.CATEGORY", "P.CODE"})
           , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING})
           , productsRow.getSerializerRead());
   }
public final SentenceExec getProductCatInsert() {
       return new SentenceExecTransaction(s) {
           public int execInTransaction(Object params) throws BasicException {
               Object[] values = (Object[]) params;
               int i = new PreparedSentence(s
                   , "INSERT INTO PRODUCTS (ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, ATTRIBUTESET_ID, IMAGE, STOCKCOST, STOCKVOLUME, ATTRIBUTES,FLAG) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)"
                   , new SerializerWriteBasicExt(productsRow.getDatas(), new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,17})).exec(params);
               if (i > 0 && ((Boolean)values[14]).booleanValue()) {
                   return new PreparedSentence(s
                       , "INSERT INTO PRODUCTS_CAT (PRODUCT, CATORDER) VALUES (?, ?)"
                       , new SerializerWriteBasicExt(productsRow.getDatas(), new int[] {0, 15})).exec(params);
               } else {
                   return i;
               }
           }
       };
   }


public final SentenceExec getProductCatUpdate() {
       return new SentenceExecTransaction(s) {
           public int execInTransaction(Object params) throws BasicException {
               Object[] values = (Object[]) params;
               int i = new PreparedSentence(s
                   , "UPDATE PRODUCTS SET ID = ?, REFERENCE = ?, CODE = ?, NAME = ?, ISCOM = ?, ISSCALE = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, ATTRIBUTESET_ID = ?, IMAGE = ?, STOCKCOST = ?, STOCKVOLUME = ?, ATTRIBUTES = ?,FLAG=? WHERE ID = ?"
                   , new SerializerWriteBasicExt(productsRow.getDatas(), new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,17, 0})).exec(params);
               if (i > 0) {
                   if (((Boolean)values[14]).booleanValue()) {
                       if (new PreparedSentence(s
                               , "UPDATE PRODUCTS_CAT SET CATORDER = ? WHERE PRODUCT = ?"
                               , new SerializerWriteBasicExt(productsRow.getDatas(), new int[] {15, 0})).exec(params) == 0) {
                           new PreparedSentence(s
                               , "INSERT INTO PRODUCTS_CAT (PRODUCT, CATORDER) VALUES (?, ?)"
                               , new SerializerWriteBasicExt(productsRow.getDatas(), new int[] {0, 15})).exec(params);
                       }
                   } else {
                       new PreparedSentence(s
                           , "DELETE FROM PRODUCTS_CAT WHERE PRODUCT = ?"
                           , new SerializerWriteBasicExt(productsRow.getDatas(), new int[] {0})).exec(params);
                   }
               }
               return i;
           }
       };
   }

Step 4

Edit ProductsInfoExt class (com.openbravo.pos.ticket)

protected boolean flag;
flag = false;
 product.flag = dr.getBoolean(14).booleanValue();

Step 5

Result

New field in product panel

Retrieved from "http://wiki.openbravo.com/wiki/POS/2.30/HowTos/How_To_Add_a_New_Field_in_Product_Panel"

This page has been accessed 13,728 times. This page was last modified on 30 March 2010, at 08:00. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.