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

Adding a new field in the products creation

1- Add a new coloumn in the products table ( a type string in my case named Test).

2- Add the textfield and the label in the products interface usng the Netbeans drag & drop. For this the concerned class is: ProductsEditor.java ( com.openbravo.pos.inventory ) I named my textfield m_jTest and label Test In method public ProductsEditor(DataLogicSales dlSales, DirtyManager dirty) add your textfield as:

m_jTest.getDocument().addDocumentListener(dirty);


In method public void writeValueEOF()

m_jTest.setText(null); m_jTest.setEnabled(false);



In method public void writeValueInsert()


m_jTest.setText(null); m_jTest.setEnabled(false);


In method public void writeValueDelete(Object value)

 m_jTest.setText(Formats.STRING.formatValue(myprod[16]));//number of the item being added you shld chek the prevs number


m_jTest.setEnabled(false);



In method public void writeValueEdit(Object value)

m_jTest.setText(Formats.STRING.formatValue(myprod[16]));//number of the item being added you shld chek the prevs number


m_jTest.setEnabled(true);

In method public Object createValue() throws BasicException

Increase the object array to one plus to accomodate your field

myprod[17] = m_jName.getText();



3- In the Datalogicsales.java class ( com.openbravo.pos.forms )


Add your field in the productsRow new Field("TEST", Datas.STRING, Formats.STRING));



In method 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, TEST " +
             "FROM PRODUCTS WHERE ID = ?"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).find(id);
   }



In method 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, TEST " +
             "FROM PRODUCTS WHERE CODE = ?"
           , SerializerWriteString.INSTANCE
           , ProductInfoExt.getSerializerRead()).find(sCode);
   }


In method   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, TEST " +
             "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.TEST " +
             "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.TEST " +
             "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);
   }




   // Products list
   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, TEST " +
             "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, TEST " +
             "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, TEST " +
             "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.TEST " +
               "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,TEST) 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 = ?,TEST=? 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;
           }
       };
   }


3- Now in ProduuctInfoext.java class (com.opnbravo.pos.tickets)


\\add a String varable

protected String test;


Initialize it in public ProductInfoExt()

test=null;


\\also add

public final String getTest() {
       return test;
   }
   public final void setTest(String value) {
       test = value;
   }




Please check this link for more info and an example:

http://forge.openbravo.com/plugins/espforum/view.php?group_id=101&forumid=434922&topicid=6995059

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

This page has been accessed 1,738 times. This page was last modified on 2 October 2009, at 13:58. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.