Page 1 of 1

Is it possible to enable re-activate option based on conditi

PostPosted: Sat Oct 20, 2012 3:07 pm
by vivekjustthink
Hi all,

Is it possible in adempiere to enable re-activate option to a specific role based on some conditions. For example the re-activate option must be enabled in Purchase Order only till the GRN is made for that purchase order. Please suggest me some way out to do this in adempiere. Thank You.

regards
vivek

Re: Is it possible to enable re-activate option based on con

PostPosted: Sat Oct 20, 2012 10:58 pm
by globalqss
Hi Vivek - I would implement that using a ModelValidator - BEFORE_REACTIVATE event to check the conditions.

Regards,

Carlos Ruiz

Re: Is it possible to enable re-activate option based on con

PostPosted: Wed Oct 24, 2012 2:55 pm
by vivekjustthink
Hi carlos, thank you for your most useful keyword "Model Validator". i was not aware of it. model validator is not working for me. i did the following

* created a custom model validator as below

Code: Select all
public class MyOwnValidator implements ModelValidator {

   /** Client          */
   private int m_AD_Client_ID = -1;
   /** User   */
   private int      m_AD_User_ID = -1;
   /** Role   */
   private int      m_AD_Role_ID = -1;
   /** Logger          */
   private static CLogger log = CLogger.getCLogger(MyOwnValidator.class);
   
   public MyOwnValidator() {
      super();
   }
   @Override
   public void initialize(ModelValidationEngine engine, MClient client) {
      //Client = null for global validator
      if (client != null) {   
         m_AD_Client_ID = client.getAD_Client_ID();
         log.info(client.toString());
      }else{
         log.info("Initializing global validator : " + this.toString());
      }
      engine.addDocValidate(MOrder.Table_Name, this);
   }

   @Override
   public int getAD_Client_ID() {
      return m_AD_Client_ID;
   }

   @Override
   public String login(int AD_Org_ID, int AD_Role_ID, int AD_User_ID) {
      return null;
   }

   @Override
   public String modelChange(PO po, int type) throws Exception {
         if (po.get_TableName().equals("C_Order") && type == TIMING_BEFORE_REACTIVATE)
         {
            MOrder order = (MOrder)po;
            System.out.println("Printer 1");
//            return Msg.getMsg("EN-US", "validator is called");
         }
      return null;
   }

   @Override
   public String docValidate(PO po, int timing) {
      if (po.get_TableName().equals("C_Order") && timing == TIMING_BEFORE_REACTIVATE){
            System.out.println("Printer 2");
//            return Msg.getMsg("EN-US", "validator is called");
      }
      return null;
   }
}


* and registered in client window -> model validation classes field -> as this "org.compiere.model.MyOwnValidator"
but nothing happens when re-activating purchase order. i even checked whether model validator is working by implementing this class "MyValidatorThailand" by looking at the sample here. i am not able to guess wt i missed. Help me out if possible. Thank you so much!! :D

regards
vivek

Re: Is it possible to enable re-activate option based on con

PostPosted: Wed Oct 24, 2012 9:20 pm
by globalqss
Hi Vivek, code looks right, maybe a class deployment problem?

Regards,

Carlos Ruiz

Re: Is it possible to enable re-activate option based on con

PostPosted: Wed Oct 24, 2012 10:52 pm
by vivekjustthink
Hi Carlos,

Am sorry. Am running from the source code and restarted the server several times. Will there be deployment problem still?

Re: Is it possible to enable re-activate option based on con

PostPosted: Sat Nov 03, 2012 9:51 am
by red1
Hi Vivek,
Have you done this also? - http://www.adempiere.com/File:MyValidatorSetup.gif where you put the path to your ModelValidator in the Client window > Model Validation Classes field

Re: Is it possible to enable re-activate option based on con

PostPosted: Sat Nov 03, 2012 12:36 pm
by vivekjustthink
Hi red1,

Thanks for your reply. yes i did it, and mentioned what i've did in the 3rd post of this topic. Please refer it and tell me if i made mistake anywhere. Thank You!! :D

Re: Is it possible to enable re-activate option based on con

PostPosted: Sun Nov 18, 2012 7:14 pm
by red1
(Dude, please do not ask anyone to refer to what you already written.) You can place a break point in debug mode and test your validator within IDE like Eclipse to see what actually is happening. For those who don't know how, it is putting your validator project as dependent on the ADempiere361 project and Debug that validator project. Usually debugging the break point onwards from say where your code is to see if your validator was called in the first place. If not, place the break further back at <ACTION><EVENT> line.