0

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
Kaan
  • 5,434
  • 3
  • 19
  • 41
  • I didn't get your point, did you created new columns in M_Product table and you want to make some vaildation on them, or you just want to extend the MProduct class and override some methods? – Younes LAB Dec 06 '21 at 09:26
  • 1
    @YounesLAB I just want to extend the **MProduct** class and override the method that saves the "VALUE" column. – alejandrohtadinom Dec 06 '21 at 20:23
  • You can create new model class that inherited from MProduct class, then override the method you want to update, and If you want to link the Product window with your new class I think you need to add it in your model factory. – Younes LAB Dec 07 '21 at 13:29

1 Answers1

0

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
Kaan
  • 5,434
  • 3
  • 19
  • 41