Idempiere extend product model

129 Views Asked by At

I want to create a class that extends the idempiere product model to create a code from other fields but I don't know which class I should import or what method I should override.

org.compiere.model.MProduct:

public MProduct (X_I_Product impP)
{
    this (impP.getCtx(), 0, impP.get_TrxName());
    setClientOrg(impP);
    setUpdatedBy(impP.getUpdatedBy());

    // Value field:
    setValue(impP.getValue());
    setName(impP.getName());
    setDescription(impP.getDescription());
    setDocumentNote(impP.getDocumentNote());
    setHelp(impP.getHelp());
    setUPC(impP.getUPC());
    setSKU(impP.getSKU());
    setC_UOM_ID(impP.getC_UOM_ID());
    setM_Product_Category_ID(impP.getM_Product_Category_ID());
    setProductType(impP.getProductType());
    setImageURL(impP.getImageURL());
    setDescriptionURL(impP.getDescriptionURL());
    setVolume(impP.getVolume());
    setWeight(impP.getWeight());
}   //  MProduct
1

There are 1 best solutions below

0
Kaan On

In one of the comments, you clarified that your intent is to "extend the MProduct class and override the method that saves the "VALUE" column".

To answer that, first let's define a simple version of MProduct class, with a few edits:

  • it has only the setValue() method, since that's the only part relevant to your question (the other methods on MProduct are not relevant)
  • the input parameter for setValue() was changed to int vs. the original type is in your example (whatever the return type is from impP.getValue())

Here's a simple version of MProduct:

class MProduct {
    void setValue(int value) {
        System.out.println("setValue() on MProduct");
    }
}

Here's a simple class which extends MProduct by overriding the setValue() method:

class CustomProduct extends MProduct {
    @Override
    void setValue(int value) {
        System.out.println("setValue() on CustomProduct");
        // custom code goes here
    }
}

Finally, here's a simple example showing usage of both of the above classes (both MProduct and CustomProduct):

public static void main(String[] args) {
    new CustomProduct().setValue(123);
    new MProduct().setValue(123);
}

And here's the output from running that example:

setValue() on CustomProduct
setValue() on MProduct